blob: 86530cf46d924236be8259c2b4f22218f85818d3 [file] [log] [blame]
Guido van Rossum23cb2a81994-09-12 10:36:35 +00001# tty.py -- Terminal utilities.
2# Author: Steen Lumholt.
3
4from TERMIOS import *
5from termios import *
6
7# Indexes for termios list.
8IFLAG = 0
9OFLAG = 1
10CFLAG = 2
11LFLAG = 3
12ISPEED = 4
13OSPEED = 5
14CC = 6
15
16# Put terminal into a raw mode.
17def 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.
29def 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