Debian Codegraph @

Doc/library/tty.rst

raw
1 :mod:`!tty` --- Terminal control functions
2 ==========================================
3
4 .. module:: tty
5 :synopsis: Utility functions that perform common terminal control operations.
6
7 .. moduleauthor:: Steen Lumholt
8 .. sectionauthor:: Moshe Zadka <[email protected]>
9
10 **Source code:** :source:`Lib/tty.py`
11
12 --------------
13
14 The :mod:`!tty` module defines functions for putting the tty into cbreak and raw
15 modes.
16
17 .. availability:: Unix.
18
19 Because it requires the :mod:`termios` module, it will work only on Unix.
20
21 The :mod:`!tty` module defines the following functions:
22
23
24 .. function:: cfmakeraw(mode)
25
26 Convert the tty attribute list *mode*, which is a list like the one returned
27 by :func:`termios.tcgetattr`, to that of a tty in raw mode.
28
29 .. versionadded:: 3.12
30
31
32 .. function:: cfmakecbreak(mode)
33
34 Convert the tty attribute list *mode*, which is a list like the one returned
35 by :func:`termios.tcgetattr`, to that of a tty in cbreak mode.
36
37 This clears the ``ECHO`` and ``ICANON`` local mode flags in *mode* as well
38 as setting the minimum input to 1 byte with no delay.
39
40 .. versionadded:: 3.12
41
42 .. versionchanged:: 3.12.2
43 The ``ICRNL`` flag is no longer cleared. This matches Linux and macOS
44 ``stty cbreak`` behavior and what :func:`setcbreak` historically did.
45
46
47 .. function:: setraw(fd, when=termios.TCSAFLUSH)
48
49 Change the mode of the file descriptor *fd* to raw. If *when* is omitted, it
50 defaults to :const:`termios.TCSAFLUSH`, and is passed to
51 :func:`termios.tcsetattr`. The return value of :func:`termios.tcgetattr`
52 is saved before setting *fd* to raw mode; this value is returned.
53
54 .. versionchanged:: 3.12
55 The return value is now the original tty attributes, instead of ``None``.
56
57
58 .. function:: setcbreak(fd, when=termios.TCSAFLUSH)
59
60 Change the mode of file descriptor *fd* to cbreak. If *when* is omitted, it
61 defaults to :const:`termios.TCSAFLUSH`, and is passed to
62 :func:`termios.tcsetattr`. The return value of :func:`termios.tcgetattr`
63 is saved before setting *fd* to cbreak mode; this value is returned.
64
65 This clears the ``ECHO`` and ``ICANON`` local mode flags as well as setting
66 the minimum input to 1 byte with no delay.
67
68 .. versionchanged:: 3.12
69 The return value is now the original tty attributes, instead of ``None``.
70
71 .. versionchanged:: 3.12.2
72 The ``ICRNL`` flag is no longer cleared. This restores the behavior
73 of Python 3.11 and earlier as well as matching what Linux, macOS, & BSDs
74 describe in their ``stty(1)`` man pages regarding cbreak mode.
75
76
77 .. seealso::
78
79 Module :mod:`termios`
80 Low-level terminal control interface.
81