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