ยปCore Development>Code coverage>Lib/tty.py

Python code coverage for Lib/tty.py

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