1 """Terminal utilities."""
3 # Author: Steen Lumholt.
7 __all__
= ["setraw", "setcbreak"]
9 # Indexes for termios list.
18 def setraw(fd
, when
=TCSAFLUSH
):
19 """Put terminal into a raw mode."""
21 mode
[IFLAG
] = mode
[IFLAG
] & ~
(BRKINT | ICRNL | INPCK | ISTRIP | IXON
)
22 mode
[OFLAG
] = mode
[OFLAG
] & ~
(OPOST
)
23 mode
[CFLAG
] = mode
[CFLAG
] & ~
(CSIZE | PARENB
)
24 mode
[CFLAG
] = mode
[CFLAG
] | CS8
25 mode
[LFLAG
] = mode
[LFLAG
] & ~
(ECHO | ICANON | IEXTEN | ISIG
)
28 tcsetattr(fd
, when
, mode
)
30 def setcbreak(fd
, when
=TCSAFLUSH
):
31 """Put terminal into a cbreak mode."""
33 mode
[LFLAG
] = mode
[LFLAG
] & ~
(ECHO | ICANON
)
36 tcsetattr(fd
, when
, mode
)