def __init__(self):
global CIO_STARTED
if CIO_STARTED:
raise Exception("cannot init cio twice")
CIO_STARTED = True
self.buf=''
self.fh_ocfg=list()
if os.name == 'posix':
# for posix, need to set to non-canonical input.
self.posix=True
fh = sys.stdin.fileno()
# if the following call fails, we are probably called with a stdin which is not a tty.
ocfg = termios.tcgetattr(fh)
cfg = termios.tcgetattr(fh)
cfg[3] = cfg[3]&~termios.ICANON&~termios.ECHO
#cfg[0] = cfg[0]&~termios.INLCR
#cfg[1] = cfg[0]&~termios.OCRNL
cfg[6][termios.VMIN] = 0
cfg[6][termios.VTIME] = 0
termios.tcsetattr(fh,termios.TCSAFLUSH,cfg)
self.fh_ocfg.extend((fh,ocfg))
atexit.register(stop_canon_input,self.fh_ocfg)
elif os.name == 'nt':
# for windows, don't need to configure the terminal.
self.posix=False
else:
# know only posix and windows...
raise Exception("os variant %s not supported"%repr(os.name))
评论列表
文章目录