blob: 20a31c05b3ebd50c6336ec45dad962593ca34a5b [file] [log] [blame]
Guido van Rossume7b146f2000-02-04 15:28:42 +00001"""Terminal utilities."""
2
Guido van Rossum23cb2a81994-09-12 10:36:35 +00003# Author: Steen Lumholt.
4
5from TERMIOS import *
6from termios import *
7
8# Indexes for termios list.
9IFLAG = 0
10OFLAG = 1
11CFLAG = 2
12LFLAG = 3
13ISPEED = 4
14OSPEED = 5
15CC = 6
16
Guido van Rossum23cb2a81994-09-12 10:36:35 +000017def setraw(fd, when=TCSAFLUSH):
Guido van Rossume7b146f2000-02-04 15:28:42 +000018 """Put terminal into a raw mode."""
Guido van Rossum23cb2a81994-09-12 10:36:35 +000019 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 Rossum23cb2a81994-09-12 10:36:35 +000029def setcbreak(fd, when=TCSAFLUSH):
Guido van Rossume7b146f2000-02-04 15:28:42 +000030 """Put terminal into a cbreak mode."""
Guido van Rossum23cb2a81994-09-12 10:36:35 +000031 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