0001 """Terminal utilities.""" 0002 0003 # Author: Steen Lumholt. 0004 0005 from termios import * 0006 0007 __all__ = ["setraw", "setcbreak"] 0008 0009 # Indexes for termios list. 0010 IFLAG = 0 0011 OFLAG = 1 0012 CFLAG = 2 0013 LFLAG = 3 0014 ISPEED = 4 0015 OSPEED = 5 0016 CC = 6 0017 0018 def setraw(fd, when=TCSAFLUSH): 0019 """Put terminal into a raw mode.""" 0020 mode = tcgetattr(fd) 0021 mode[IFLAG] = mode[IFLAG] & ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON) 0022 mode[OFLAG] = mode[OFLAG] & ~(OPOST) 0023 mode[CFLAG] = mode[CFLAG] & ~(CSIZE | PARENB) 0024 mode[CFLAG] = mode[CFLAG] | CS8 0025 mode[LFLAG] = mode[LFLAG] & ~(ECHO | ICANON | IEXTEN | ISIG) 0026 mode[CC][VMIN] = 1 0027 mode[CC][VTIME] = 0 0028 tcsetattr(fd, when, mode) 0029 0030 def setcbreak(fd, when=TCSAFLUSH): 0031 """Put terminal into a cbreak mode.""" 0032 mode = tcgetattr(fd) 0033 mode[LFLAG] = mode[LFLAG] & ~(ECHO | ICANON) 0034 mode[CC][VMIN] = 1 0035 mode[CC][VTIME] = 0 0036 tcsetattr(fd, when, mode) 0037
Generated by PyXR 0.9.4