diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/python~3.12/library%2Ftermios.html | |
new repository
Diffstat (limited to 'devdocs/python~3.12/library%2Ftermios.html')
| -rw-r--r-- | devdocs/python~3.12/library%2Ftermios.html | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/devdocs/python~3.12/library%2Ftermios.html b/devdocs/python~3.12/library%2Ftermios.html new file mode 100644 index 00000000..8d4c0fdf --- /dev/null +++ b/devdocs/python~3.12/library%2Ftermios.html @@ -0,0 +1,55 @@ + <span id="termios-posix-style-tty-control"></span><h1>termios — POSIX style tty control</h1> <p>This module provides an interface to the POSIX calls for tty I/O control. For a complete description of these calls, see <em class="manpage"><a class="manpage reference external" href="https://manpages.debian.org/termios(3)">termios(3)</a></em> Unix manual page. It is only available for those Unix versions that support POSIX <em>termios</em> style tty I/O control configured during installation.</p> <div class="availability docutils container"> <p><a class="reference internal" href="https://docs.python.org/3.12/library/intro.html#availability"><span class="std std-ref">Availability</span></a>: Unix.</p> </div> <p>All functions in this module take a file descriptor <em>fd</em> as their first argument. This can be an integer file descriptor, such as returned by <code>sys.stdin.fileno()</code>, or a <a class="reference internal" href="../glossary#term-file-object"><span class="xref std std-term">file object</span></a>, such as <code>sys.stdin</code> itself.</p> <p>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.</p> <p>The module defines the following functions:</p> <dl class="py function"> <dt class="sig sig-object py" id="termios.tcgetattr"> +<code>termios.tcgetattr(fd)</code> </dt> <dd> +<p>Return a list containing the tty attributes for file descriptor <em>fd</em>, as follows: <code>[iflag, oflag, cflag, lflag, ispeed, ospeed, cc]</code> where <em>cc</em> is a list of the tty special characters (each a string of length 1, except the items with indices <code>VMIN</code> and <code>VTIME</code>, which are integers when these fields are defined). The interpretation of the flags and the speeds as well as the indexing in the <em>cc</em> array must be done using the symbolic constants defined in the <a class="reference internal" href="#module-termios" title="termios: POSIX style tty control. (Unix)"><code>termios</code></a> module.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="termios.tcsetattr"> +<code>termios.tcsetattr(fd, when, attributes)</code> </dt> <dd> +<p>Set the tty attributes for file descriptor <em>fd</em> from the <em>attributes</em>, which is a list like the one returned by <a class="reference internal" href="#termios.tcgetattr" title="termios.tcgetattr"><code>tcgetattr()</code></a>. The <em>when</em> argument determines when the attributes are changed:</p> <dl class="py data"> <dt class="sig sig-object py" id="termios.TCSANOW"> +<code>termios.TCSANOW</code> </dt> <dd> +<p>Change attributes immediately.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="termios.TCSADRAIN"> +<code>termios.TCSADRAIN</code> </dt> <dd> +<p>Change attributes after transmitting all queued output.</p> </dd> +</dl> <dl class="py data"> <dt class="sig sig-object py" id="termios.TCSAFLUSH"> +<code>termios.TCSAFLUSH</code> </dt> <dd> +<p>Change attributes after transmitting all queued output and discarding all queued input.</p> </dd> +</dl> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="termios.tcsendbreak"> +<code>termios.tcsendbreak(fd, duration)</code> </dt> <dd> +<p>Send a break on file descriptor <em>fd</em>. A zero <em>duration</em> sends a break for 0.25–0.5 seconds; a nonzero <em>duration</em> has a system dependent meaning.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="termios.tcdrain"> +<code>termios.tcdrain(fd)</code> </dt> <dd> +<p>Wait until all output written to file descriptor <em>fd</em> has been transmitted.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="termios.tcflush"> +<code>termios.tcflush(fd, queue)</code> </dt> <dd> +<p>Discard queued data on file descriptor <em>fd</em>. The <em>queue</em> selector specifies which queue: <code>TCIFLUSH</code> for the input queue, <code>TCOFLUSH</code> for the output queue, or <code>TCIOFLUSH</code> for both queues.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="termios.tcflow"> +<code>termios.tcflow(fd, action)</code> </dt> <dd> +<p>Suspend or resume input or output on file descriptor <em>fd</em>. The <em>action</em> argument can be <code>TCOOFF</code> to suspend output, <code>TCOON</code> to restart output, <code>TCIOFF</code> to suspend input, or <code>TCION</code> to restart input.</p> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="termios.tcgetwinsize"> +<code>termios.tcgetwinsize(fd)</code> </dt> <dd> +<p>Return a tuple <code>(ws_row, ws_col)</code> containing the tty window size for file descriptor <em>fd</em>. Requires <code>termios.TIOCGWINSZ</code> or <code>termios.TIOCGSIZE</code>.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd> +</dl> <dl class="py function"> <dt class="sig sig-object py" id="termios.tcsetwinsize"> +<code>termios.tcsetwinsize(fd, winsize)</code> </dt> <dd> +<p>Set the tty window size for file descriptor <em>fd</em> from <em>winsize</em>, which is a two-item tuple <code>(ws_row, ws_col)</code> like the one returned by <a class="reference internal" href="#termios.tcgetwinsize" title="termios.tcgetwinsize"><code>tcgetwinsize()</code></a>. Requires at least one of the pairs (<code>termios.TIOCGWINSZ</code>, <code>termios.TIOCSWINSZ</code>); (<code>termios.TIOCGSIZE</code>, <code>termios.TIOCSSIZE</code>) to be defined.</p> <div class="versionadded"> <p><span class="versionmodified added">New in version 3.11.</span></p> </div> </dd> +</dl> <div class="admonition seealso"> <p class="admonition-title">See also</p> <dl class="simple"> <dt> +<code>Module</code> <a class="reference internal" href="tty#module-tty" title="tty: Utility functions that perform common terminal control operations. (Unix)"><code>tty</code></a> +</dt> +<dd> +<p>Convenience functions for common terminal control operations.</p> </dd> </dl> </div> <section id="example"> <span id="termios-example"></span><h2>Example</h2> <p>Here’s a function that prompts for a password with echoing turned off. Note the technique using a separate <a class="reference internal" href="#termios.tcgetattr" title="termios.tcgetattr"><code>tcgetattr()</code></a> call and a <a class="reference internal" href="../reference/compound_stmts#try"><code>try</code></a> … <a class="reference internal" href="../reference/compound_stmts#finally"><code>finally</code></a> statement to ensure that the old tty attributes are restored exactly no matter what happens:</p> <pre data-language="python">def getpass(prompt="Password: "): + import termios, sys + fd = sys.stdin.fileno() + old = termios.tcgetattr(fd) + new = termios.tcgetattr(fd) + new[3] = new[3] & ~termios.ECHO # lflags + try: + termios.tcsetattr(fd, termios.TCSADRAIN, new) + passwd = input(prompt) + finally: + termios.tcsetattr(fd, termios.TCSADRAIN, old) + return passwd +</pre> </section> <div class="_attribution"> + <p class="_attribution-p"> + © 2001–2023 Python Software Foundation<br>Licensed under the PSF License.<br> + <a href="https://docs.python.org/3.12/library/termios.html" class="_attribution-link">https://docs.python.org/3.12/library/termios.html</a> + </p> +</div> |
