nxu/term.py

45 lines
999 B
Python
Executable File

#/usr/bin/env python
import fcntl
import os
import pty
import sys
import struct
import termios
def main():
# check usage
args = sys.argv[1:]
if len(args) < 1:
print('usage: %s ROM')
print('')
print(' ROM: the rom file to launch')
sys.exit(1)
# path to rom to run
rom = args[0]
# fork with a new pty
pid, fd = pty.fork()
if pid == 0:
# set TERM to something we can (mostly) handle
env = dict(os.environ)
env['TERM'] = 'ansi'
os.execvpe('bash', ['bash'], env)
else:
# set the terminal size
###cols, rows = 79, 40
cols, rows = 80, 24
size = struct.pack("HHHH", rows, cols, 8, 12)
fcntl.ioctl(fd, termios.TIOCSWINSZ, size)
# use fd for the terminals stdin/stdout
os.dup2(fd, sys.stdin.fileno())
os.dup2(os.dup(fd), sys.stdout.fileno())
os.execvp('uxnemu', ['uxnemu', rom] + args[1:])
if __name__ == "__main__":
main()