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