NICK_FREQH = 0x314
# global state
-attr = None
+gr_width = 1 # set by command line
+termios_attr = None
fd_in = sys.stdin.fileno()
fd_out = sys.stdout.fileno()
poll_in = select.poll()
)
def init():
- global attr
+ global termios_attr
- if attr is None and os.isatty(fd_in):
- attr = termios.tcgetattr(fd_in)
+ if termios_attr is None and os.isatty(fd_in):
+ termios_attr = termios.tcgetattr(fd_in)
atexit.register(deinit)
tty.setraw(fd_in)
write('\x1b[?25l\x1b[0m') # hide cursor, reset attributes
def deinit():
- global attr
+ global termios_attr
- if attr is not None:
+ if termios_attr is not None:
write('\x1b[?25h\x1b[0m') # show cursor, reset attributes
- termios.tcsetattr(fd_in, termios.TCSADRAIN, attr)
+ termios.tcsetattr(fd_in, termios.TCSADRAIN, termios_attr)
atexit.unregister(deinit)
- attr = None
+ termios_attr = None
def pr_hash(n):
pass
fg = -1
br = -1
for i in range(y0, y1):
- write(f'\x1b[{i + 1:d};{x0 * 2 + 1:d}H')
+ write(f'\x1b[{i + 1:d};{x0 * gr_width + 1:d}H')
for j in range(x0, x1):
new_bg = colors[gr_mem[i * 2][j]]
new_fg = colors[gr_mem[i * 2 + 1][j]]
bg = new_bg
fg = new_fg
br = new_br
- write(ch * 2)
- write('\x1b[u\x1b[0m') # restore cursor and attrs
+ write(ch * gr_width)
+ write('\x1b[u\x1b[0m') # restore cursor and attributes
#time.sleep(.05)
def color(n):
#print('yytext', f'"{lex_yy.yytext:s}"')
#assert False
+if len(sys.argv) >= 2 and sys.argv[1][:11] == '--gr-width=':
+ apple_io.gr_width = int(sys.argv[1][11:])
+ del sys.argv[1]
if len(sys.argv) < 2:
- print(f'usage: {sys.argv[0]:s} program.tok')
+ print(f'usage: {sys.argv[0]:s} [--gr-width=n] program.tok')
sys.exit(EXIT_FAILURE)
program_bas = sys.argv[1]