1998-08-10 19:42:37 +00:00
|
|
|
\section{\module{termios} ---
|
1999-03-02 16:37:17 +00:00
|
|
|
\POSIX{} style tty control}
|
1998-07-23 17:59:49 +00:00
|
|
|
|
1999-03-02 16:37:17 +00:00
|
|
|
\declaremodule{builtin}{termios}
|
1999-03-02 17:03:42 +00:00
|
|
|
\platform{Unix}
|
1998-07-23 17:59:49 +00:00
|
|
|
\modulesynopsis{\POSIX{} style tty control.}
|
|
|
|
|
1998-02-09 20:27:12 +00:00
|
|
|
\indexii{\POSIX{}}{I/O control}
|
1995-03-31 12:26:24 +00:00
|
|
|
\indexii{tty}{I/O control}
|
1995-03-28 13:35:14 +00:00
|
|
|
|
1995-03-31 12:26:24 +00:00
|
|
|
|
1998-02-09 20:27:12 +00:00
|
|
|
This module provides an interface to the \POSIX{} calls for tty I/O
|
|
|
|
control. For a complete description of these calls, see the \POSIX{} or
|
1995-03-31 12:26:24 +00:00
|
|
|
\UNIX{} manual pages. It is only available for those \UNIX{} versions
|
1998-03-11 06:00:23 +00:00
|
|
|
that support \POSIX{} \emph{termios} style tty I/O control (and then
|
1995-03-31 12:26:24 +00:00
|
|
|
only if configured at installation time).
|
|
|
|
|
|
|
|
All functions in this module take a file descriptor \var{fd} as their
|
|
|
|
first argument. This must be an integer file descriptor, such as
|
|
|
|
returned by \code{sys.stdin.fileno()}.
|
|
|
|
|
1998-03-11 06:00:23 +00:00
|
|
|
This module should be used in conjunction with the
|
1999-03-02 16:37:17 +00:00
|
|
|
\refmodule[TERMIOSuppercase]{TERMIOS}\refstmodindex{TERMIOS} module,
|
|
|
|
which defines the relevant symbolic constants (see the next section).
|
1995-03-31 12:26:24 +00:00
|
|
|
|
|
|
|
The module defines the following functions:
|
|
|
|
|
|
|
|
\begin{funcdesc}{tcgetattr}{fd}
|
|
|
|
Return a list containing the tty attributes for file descriptor
|
1998-03-11 06:00:23 +00:00
|
|
|
\var{fd}, as follows: \code{[}\var{iflag}, \var{oflag}, \var{cflag},
|
|
|
|
\var{lflag}, \var{ispeed}, \var{ospeed}, \var{cc}\code{]} where
|
|
|
|
\var{cc} is a list of the tty special characters (each a string of
|
|
|
|
length 1, except the items with indices \constant{TERMIOS.VMIN} and
|
|
|
|
\constant{TERMIOS.VTIME}, which are integers when these fields are
|
|
|
|
defined). The interpretation of the flags and the speeds as well as
|
|
|
|
the indexing in the \var{cc} array must be done using the symbolic
|
1999-03-02 16:37:17 +00:00
|
|
|
constants defined in the \refmodule[TERMIOSuppercase]{TERMIOS}
|
|
|
|
module.
|
1995-03-31 12:26:24 +00:00
|
|
|
\end{funcdesc}
|
|
|
|
|
1998-03-11 06:00:23 +00:00
|
|
|
\begin{funcdesc}{tcsetattr}{fd, when, attributes}
|
1995-03-31 12:26:24 +00:00
|
|
|
Set the tty attributes for file descriptor \var{fd} from the
|
|
|
|
\var{attributes}, which is a list like the one returned by
|
1998-03-11 06:00:23 +00:00
|
|
|
\function{tcgetattr()}. The \var{when} argument determines when the
|
|
|
|
attributes are changed: \constant{TERMIOS.TCSANOW} to change
|
|
|
|
immediately, \constant{TERMIOS.TCSADRAIN} to change after transmitting
|
|
|
|
all queued output, or \constant{TERMIOS.TCSAFLUSH} to change after
|
|
|
|
transmitting all queued output and discarding all queued input.
|
1995-03-31 12:26:24 +00:00
|
|
|
\end{funcdesc}
|
|
|
|
|
1998-03-11 06:00:23 +00:00
|
|
|
\begin{funcdesc}{tcsendbreak}{fd, duration}
|
1995-03-31 12:26:24 +00:00
|
|
|
Send a break on file descriptor \var{fd}. A zero \var{duration} sends
|
|
|
|
a break for 0.25--0.5 seconds; a nonzero \var{duration} has a system
|
|
|
|
dependent meaning.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
|
|
|
\begin{funcdesc}{tcdrain}{fd}
|
|
|
|
Wait until all output written to file descriptor \var{fd} has been
|
|
|
|
transmitted.
|
|
|
|
\end{funcdesc}
|
|
|
|
|
1998-03-11 06:00:23 +00:00
|
|
|
\begin{funcdesc}{tcflush}{fd, queue}
|
1995-03-31 12:26:24 +00:00
|
|
|
Discard queued data on file descriptor \var{fd}. The \var{queue}
|
1998-03-11 06:00:23 +00:00
|
|
|
selector specifies which queue: \constant{TERMIOS.TCIFLUSH} for the
|
|
|
|
input queue, \constant{TERMIOS.TCOFLUSH} for the output queue, or
|
|
|
|
\constant{TERMIOS.TCIOFLUSH} for both queues.
|
1995-03-31 12:26:24 +00:00
|
|
|
\end{funcdesc}
|
|
|
|
|
1998-03-11 06:00:23 +00:00
|
|
|
\begin{funcdesc}{tcflow}{fd, action}
|
1995-03-31 12:26:24 +00:00
|
|
|
Suspend or resume input or output on file descriptor \var{fd}. The
|
1998-03-11 06:00:23 +00:00
|
|
|
\var{action} argument can be \constant{TERMIOS.TCOOFF} to suspend
|
|
|
|
output, \constant{TERMIOS.TCOON} to restart output,
|
|
|
|
\constant{TERMIOS.TCIOFF} to suspend input, or
|
|
|
|
\constant{TERMIOS.TCION} to restart input.
|
1995-03-31 12:26:24 +00:00
|
|
|
\end{funcdesc}
|
|
|
|
|
1999-06-23 15:12:09 +00:00
|
|
|
|
|
|
|
\begin{seealso}
|
|
|
|
\seemodule[TERMIOSuppercase]{TERMIOS}{Constants for use with
|
|
|
|
\module{termios}.}
|
|
|
|
\seemodule{tty}{Convenience functions for common terminal control
|
|
|
|
operations.}
|
|
|
|
\end{seealso}
|
|
|
|
|
|
|
|
|
1995-03-31 12:26:24 +00:00
|
|
|
\subsection{Example}
|
|
|
|
\nodename{termios Example}
|
|
|
|
|
1998-03-11 06:00:23 +00:00
|
|
|
Here's a function that prompts for a password with echoing turned
|
|
|
|
off. Note the technique using a separate \function{tcgetattr()} call
|
|
|
|
and a \keyword{try} ... \keyword{finally} statement to ensure that the
|
|
|
|
old tty attributes are restored exactly no matter what happens:
|
1995-03-31 12:26:24 +00:00
|
|
|
|
1998-02-13 06:58:54 +00:00
|
|
|
\begin{verbatim}
|
1995-03-31 12:26:24 +00:00
|
|
|
def getpass(prompt = "Password: "):
|
|
|
|
import termios, TERMIOS, sys
|
|
|
|
fd = sys.stdin.fileno()
|
|
|
|
old = termios.tcgetattr(fd)
|
|
|
|
new = termios.tcgetattr(fd)
|
1998-03-11 06:00:23 +00:00
|
|
|
new[3] = new[3] & ~TERMIOS.ECHO # lflags
|
1995-03-31 12:26:24 +00:00
|
|
|
try:
|
|
|
|
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new)
|
|
|
|
passwd = raw_input(prompt)
|
|
|
|
finally:
|
|
|
|
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, old)
|
|
|
|
return passwd
|
1998-02-13 06:58:54 +00:00
|
|
|
\end{verbatim}
|
1998-02-19 20:07:39 +00:00
|
|
|
|
1999-02-20 00:14:17 +00:00
|
|
|
|
1998-08-10 19:42:37 +00:00
|
|
|
\section{\module{TERMIOS} ---
|
1999-03-02 16:37:17 +00:00
|
|
|
Constants used with the \module{termios} module}
|
1998-07-23 17:59:49 +00:00
|
|
|
|
1999-02-20 00:14:17 +00:00
|
|
|
\declaremodule[TERMIOSuppercase]{standard}{TERMIOS}
|
1999-03-02 17:03:42 +00:00
|
|
|
\platform{Unix}
|
1998-08-10 19:42:37 +00:00
|
|
|
\modulesynopsis{Symbolic constants required to use the
|
1999-03-02 16:37:17 +00:00
|
|
|
\module{termios} module.}
|
1998-07-23 17:59:49 +00:00
|
|
|
|
1999-02-20 00:14:17 +00:00
|
|
|
|
1998-02-09 20:27:12 +00:00
|
|
|
\indexii{\POSIX{}}{I/O control}
|
1995-03-31 12:26:24 +00:00
|
|
|
\indexii{tty}{I/O control}
|
|
|
|
|
|
|
|
This module defines the symbolic constants required to use the
|
1999-03-02 16:37:17 +00:00
|
|
|
\refmodule{termios}\refbimodindex{termios} module (see the previous
|
1998-03-11 06:00:23 +00:00
|
|
|
section). See the \POSIX{} or \UNIX{} manual pages (or the source)
|
|
|
|
for a list of those constants.
|
1995-03-31 12:26:24 +00:00
|
|
|
|
|
|
|
Note: this module resides in a system-dependent subdirectory of the
|
|
|
|
Python library directory. You may have to generate it for your
|
|
|
|
particular system using the script \file{Tools/scripts/h2py.py}.
|