Guido van Rossum | 23cb2a8 | 1994-09-12 10:36:35 +0000 | [diff] [blame] | 1 | # tty.py -- Terminal utilities. |
| 2 | # Author: Steen Lumholt. |
| 3 | |
| 4 | from TERMIOS import * |
| 5 | from termios import * |
| 6 | |
| 7 | # Indexes for termios list. |
| 8 | IFLAG = 0 |
| 9 | OFLAG = 1 |
| 10 | CFLAG = 2 |
| 11 | LFLAG = 3 |
| 12 | ISPEED = 4 |
| 13 | OSPEED = 5 |
| 14 | CC = 6 |
| 15 | |
| 16 | # Put terminal into a raw mode. |
| 17 | def setraw(fd, when=TCSAFLUSH): |
| 18 | mode = tcgetattr(fd) |
| 19 | mode[IFLAG] = mode[IFLAG] & ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON) |
| 20 | mode[OFLAG] = mode[OFLAG] & ~(OPOST) |
| 21 | mode[CFLAG] = mode[CFLAG] & ~(CSIZE | PARENB) |
| 22 | mode[CFLAG] = mode[CFLAG] | CS8 |
| 23 | mode[LFLAG] = mode[LFLAG] & ~(ECHO | ICANON | IEXTEN | ISIG) |
| 24 | mode[CC][VMIN] = 1 |
| 25 | mode[CC][VTIME] = 0 |
| 26 | tcsetattr(fd, when, mode) |
| 27 | |
| 28 | # Put terminal into a cbreak mode. |
| 29 | def setcbreak(fd, when=TCSAFLUSH): |
| 30 | mode = tcgetattr(fd) |
| 31 | mode[LFLAG] = mode[LFLAG] & ~(ECHO | ICANON) |
| 32 | mode[CC][VMIN] = 1 |
| 33 | mode[CC][VTIME] = 0 |
| 34 | tcsetattr(fd, when, mode) |
| 35 | |