termios
— POSIX 样式 tty 控制
¶
本模块为 tty I/O 控制,提供 POSIX 调用接口。这些调用的完整描述,见 termios(3) Unix 手册页。它只可用于那些 Unix 版本,支持 POSIX termios 样式 tty I/O 控制 (在安装过程中配置)。
可用性 :Unix。
本模块中的所有函数接受文件描述符
fd
作为其第 1 自变量。这可以是整数文件描述符,譬如返回通过
sys.stdin.fileno()
,或
文件对象
,譬如
sys.stdin
本身。
This module also defines all the constants needed to work with the functions provided here; these have the same name as their counterparts in C. Please refer to your system documentation for more information on using these terminal control interfaces.
模块定义了下列函数:
- termios. tcgetattr ( fd ) ¶
-
Return a list containing the tty attributes for file descriptor fd , as follows:
[iflag, oflag, cflag, lflag, ispeed, ospeed, cc]where cc is a list of the tty special characters (each a string of length 1, except the items with indicesVMINandVTIME, which are integers when these fields are defined). The interpretation of the flags and the speeds as well as the indexing in the cc array must be done using the symbolic constants defined in thetermios模块。
- termios. tcsetattr ( fd , 当 , 属性 ) ¶
-
Set the tty attributes for file descriptor fd 从 属性 , which is a list like the one returned by
tcgetattr()。 当 argument determines when the attributes are changed:- termios. TCSANOW ¶
-
Change attributes immediately.
- termios. TCSADRAIN ¶
-
Change attributes after transmitting all queued output.
- termios. TCSAFLUSH ¶
-
Change attributes after transmitting all queued output and discarding all queued input.
- termios. tcsendbreak ( fd , duration ) ¶
-
Send a break on file descriptor fd . A zero duration sends a break for 0.25–0.5 seconds; a nonzero duration has a system dependent meaning.
- termios. tcdrain ( fd ) ¶
-
Wait until all output written to file descriptor fd has been transmitted.
- termios. tcflush ( fd , queue ) ¶
-
Discard queued data on file descriptor fd 。 queue selector specifies which queue:
TCIFLUSHfor the input queue,TCOFLUSHfor the output queue, orTCIOFLUSHfor both queues.
- termios. tcflow ( fd , action ) ¶
-
挂起 (或再继续) 输入/输出对于文件描述符 fd 。 action 自变量可以是
TCOOFF以挂起输出,TCOON以重启输出,TCIOFF以挂起输入,或TCION以重启输入。
- termios. tcgetwinsize ( fd ) ¶
-
返回元组
(ws_row, ws_col)containing the tty window size for file descriptor fd . Requirestermios.TIOCGWINSZortermios.TIOCGSIZE.Added in version 3.11.
- termios. tcsetwinsize ( fd , winsize ) ¶
-
Set the tty window size for file descriptor fd from winsize , which is a two-item tuple
(ws_row, ws_col)like the one returned bytcgetwinsize(). Requires at least one of the pairs (termios.TIOCGWINSZ,termios.TIOCSWINSZ); (termios.TIOCGSIZE,termios.TIOCSSIZE) to be defined.Added in version 3.11.