+++ /dev/null
-"""Terminal utilities."""\r
-\r
-# Author: Steen Lumholt.\r
-\r
-from termios import *\r
-\r
-__all__ = ["setraw", "setcbreak"]\r
-\r
-# Indexes for termios list.\r
-IFLAG = 0\r
-OFLAG = 1\r
-CFLAG = 2\r
-LFLAG = 3\r
-ISPEED = 4\r
-OSPEED = 5\r
-CC = 6\r
-\r
-def setraw(fd, when=TCSAFLUSH):\r
- """Put terminal into a raw mode."""\r
- mode = tcgetattr(fd)\r
- mode[IFLAG] = mode[IFLAG] & ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON)\r
- mode[OFLAG] = mode[OFLAG] & ~(OPOST)\r
- mode[CFLAG] = mode[CFLAG] & ~(CSIZE | PARENB)\r
- mode[CFLAG] = mode[CFLAG] | CS8\r
- mode[LFLAG] = mode[LFLAG] & ~(ECHO | ICANON | IEXTEN | ISIG)\r
- mode[CC][VMIN] = 1\r
- mode[CC][VTIME] = 0\r
- tcsetattr(fd, when, mode)\r
-\r
-def setcbreak(fd, when=TCSAFLUSH):\r
- """Put terminal into a cbreak mode."""\r
- mode = tcgetattr(fd)\r
- mode[LFLAG] = mode[LFLAG] & ~(ECHO | ICANON)\r
- mode[CC][VMIN] = 1\r
- mode[CC][VTIME] = 0\r
- tcsetattr(fd, when, mode)\r