"""Terminal utilities."""
__all__ = ["setraw", "setcbreak"]
# Indexes for termios list.
def setraw(fd, when=TCSAFLUSH):
"""Put terminal into a raw mode."""
mode[IFLAG] = mode[IFLAG] & ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON)
mode[OFLAG] = mode[OFLAG] & ~(OPOST)
mode[CFLAG] = mode[CFLAG] & ~(CSIZE | PARENB)
mode[CFLAG] = mode[CFLAG] | CS8
mode[LFLAG] = mode[LFLAG] & ~(ECHO | ICANON | IEXTEN | ISIG)
tcsetattr(fd, when, mode)
def setcbreak(fd, when=TCSAFLUSH):
"""Put terminal into a cbreak mode."""
mode[LFLAG] = mode[LFLAG] & ~(ECHO | ICANON)
tcsetattr(fd, when, mode)