Commit e42f595e authored by Fred Drake's avatar Fred Drake

Logical markup.

Made references to constants in other TERMIOS module explicit in termios
description.

Removed superfluous backslash from example.
parent db9693ec
...@@ -4,47 +4,46 @@ ...@@ -4,47 +4,46 @@
\indexii{\POSIX{}}{I/O control} \indexii{\POSIX{}}{I/O control}
\indexii{tty}{I/O control} \indexii{tty}{I/O control}
\setindexsubitem{(in module termios)}
This module provides an interface to the \POSIX{} calls for tty I/O 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 control. For a complete description of these calls, see the \POSIX{} or
\UNIX{} manual pages. It is only available for those \UNIX{} versions \UNIX{} manual pages. It is only available for those \UNIX{} versions
that support \POSIX{} \code{termios} style tty I/O control (and then that support \POSIX{} \emph{termios} style tty I/O control (and then
only if configured at installation time). only if configured at installation time).
All functions in this module take a file descriptor \var{fd} as their All functions in this module take a file descriptor \var{fd} as their
first argument. This must be an integer file descriptor, such as first argument. This must be an integer file descriptor, such as
returned by \code{sys.stdin.fileno()}. returned by \code{sys.stdin.fileno()}.
This module should be used in conjunction with the \code{TERMIOS} This module should be used in conjunction with the
module, which defines the relevant symbolic constants (see the next \module{TERMIOS}\refstmodindex{TERMIOS} module, which defines the
section). relevant symbolic constants (see the next section).
The module defines the following functions: The module defines the following functions:
\begin{funcdesc}{tcgetattr}{fd} \begin{funcdesc}{tcgetattr}{fd}
Return a list containing the tty attributes for file descriptor Return a list containing the tty attributes for file descriptor
\var{fd}, as follows: \code{[\var{iflag}, \var{oflag}, \var{cflag}, \var{fd}, as follows: \code{[}\var{iflag}, \var{oflag}, \var{cflag},
\var{lflag}, \var{ispeed}, \var{ospeed}, \var{cc}]} where \var{cc} is \var{lflag}, \var{ispeed}, \var{ospeed}, \var{cc}\code{]} where
a list of the tty special characters (each a string of length 1, \var{cc} is a list of the tty special characters (each a string of
except the items with indices \code{VMIN} and \code{VTIME}, which are length 1, except the items with indices \constant{TERMIOS.VMIN} and
integers when these fields are defined). The interpretation of the \constant{TERMIOS.VTIME}, which are integers when these fields are
flags and the speeds as well as the indexing in the \var{cc} array defined). The interpretation of the flags and the speeds as well as
must be done using the symbolic constants defined in the the indexing in the \var{cc} array must be done using the symbolic
\code{TERMIOS} module. constants defined in the \module{TERMIOS} module.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{tcsetattr}{fd\, when\, attributes} \begin{funcdesc}{tcsetattr}{fd, when, attributes}
Set the tty attributes for file descriptor \var{fd} from the Set the tty attributes for file descriptor \var{fd} from the
\var{attributes}, which is a list like the one returned by \var{attributes}, which is a list like the one returned by
\code{tcgetattr()}. The \var{when} argument determines when the \function{tcgetattr()}. The \var{when} argument determines when the
attributes are changed: \code{TERMIOS.TCSANOW} to change immediately, attributes are changed: \constant{TERMIOS.TCSANOW} to change
\code{TERMIOS.TCSADRAIN} to change after transmitting all queued immediately, \constant{TERMIOS.TCSADRAIN} to change after transmitting
output, or \code{TERMIOS.TCSAFLUSH} to change after transmitting all all queued output, or \constant{TERMIOS.TCSAFLUSH} to change after
queued output and discarding all queued input. transmitting all queued output and discarding all queued input.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{tcsendbreak}{fd\, duration} \begin{funcdesc}{tcsendbreak}{fd, duration}
Send a break on file descriptor \var{fd}. A zero \var{duration} sends 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 a break for 0.25--0.5 seconds; a nonzero \var{duration} has a system
dependent meaning. dependent meaning.
...@@ -55,27 +54,28 @@ Wait until all output written to file descriptor \var{fd} has been ...@@ -55,27 +54,28 @@ Wait until all output written to file descriptor \var{fd} has been
transmitted. transmitted.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{tcflush}{fd\, queue} \begin{funcdesc}{tcflush}{fd, queue}
Discard queued data on file descriptor \var{fd}. The \var{queue} Discard queued data on file descriptor \var{fd}. The \var{queue}
selector specifies which queue: \code{TERMIOS.TCIFLUSH} for the input selector specifies which queue: \constant{TERMIOS.TCIFLUSH} for the
queue, \code{TERMIOS.TCOFLUSH} for the output queue, or input queue, \constant{TERMIOS.TCOFLUSH} for the output queue, or
\code{TERMIOS.TCIOFLUSH} for both queues. \constant{TERMIOS.TCIOFLUSH} for both queues.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{tcflow}{fd\, action} \begin{funcdesc}{tcflow}{fd, action}
Suspend or resume input or output on file descriptor \var{fd}. The Suspend or resume input or output on file descriptor \var{fd}. The
\var{action} argument can be \code{TERMIOS.TCOOFF} to suspend output, \var{action} argument can be \constant{TERMIOS.TCOOFF} to suspend
\code{TERMIOS.TCOON} to restart output, \code{TERMIOS.TCIOFF} to output, \constant{TERMIOS.TCOON} to restart output,
suspend input, or \code{TERMIOS.TCION} to restart input. \constant{TERMIOS.TCIOFF} to suspend input, or
\constant{TERMIOS.TCION} to restart input.
\end{funcdesc} \end{funcdesc}
\subsection{Example} \subsection{Example}
\nodename{termios Example} \nodename{termios Example}
Here's a function that prompts for a password with echoing turned off. Here's a function that prompts for a password with echoing turned
Note the technique using a separate \code{termios.tcgetattr()} call off. Note the technique using a separate \function{tcgetattr()} call
and a \code{try \ldots{} finally} statement to ensure that the old tty and a \keyword{try} ... \keyword{finally} statement to ensure that the
attributes are restored exactly no matter what happens: old tty attributes are restored exactly no matter what happens:
\begin{verbatim} \begin{verbatim}
def getpass(prompt = "Password: "): def getpass(prompt = "Password: "):
...@@ -83,7 +83,7 @@ def getpass(prompt = "Password: "): ...@@ -83,7 +83,7 @@ def getpass(prompt = "Password: "):
fd = sys.stdin.fileno() fd = sys.stdin.fileno()
old = termios.tcgetattr(fd) old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd) new = termios.tcgetattr(fd)
new[3] = new[3] & \~TERMIOS.ECHO # lflags new[3] = new[3] & ~TERMIOS.ECHO # lflags
try: try:
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new) termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new)
passwd = raw_input(prompt) passwd = raw_input(prompt)
...@@ -101,9 +101,9 @@ def getpass(prompt = "Password: "): ...@@ -101,9 +101,9 @@ def getpass(prompt = "Password: "):
\setindexsubitem{(in module TERMIOS)} \setindexsubitem{(in module TERMIOS)}
This module defines the symbolic constants required to use the This module defines the symbolic constants required to use the
\code{termios} module (see the previous section). See the \POSIX{} or \module{termios}\refbimodindex{termios} module (see the previous
\UNIX{} manual pages (or the source) for a list of those constants. section). See the \POSIX{} or \UNIX{} manual pages (or the source)
\refbimodindex{termios} for a list of those constants.
Note: this module resides in a system-dependent subdirectory of the Note: this module resides in a system-dependent subdirectory of the
Python library directory. You may have to generate it for your Python library directory. You may have to generate it for your
......
...@@ -4,47 +4,46 @@ ...@@ -4,47 +4,46 @@
\indexii{\POSIX{}}{I/O control} \indexii{\POSIX{}}{I/O control}
\indexii{tty}{I/O control} \indexii{tty}{I/O control}
\setindexsubitem{(in module termios)}
This module provides an interface to the \POSIX{} calls for tty I/O 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 control. For a complete description of these calls, see the \POSIX{} or
\UNIX{} manual pages. It is only available for those \UNIX{} versions \UNIX{} manual pages. It is only available for those \UNIX{} versions
that support \POSIX{} \code{termios} style tty I/O control (and then that support \POSIX{} \emph{termios} style tty I/O control (and then
only if configured at installation time). only if configured at installation time).
All functions in this module take a file descriptor \var{fd} as their All functions in this module take a file descriptor \var{fd} as their
first argument. This must be an integer file descriptor, such as first argument. This must be an integer file descriptor, such as
returned by \code{sys.stdin.fileno()}. returned by \code{sys.stdin.fileno()}.
This module should be used in conjunction with the \code{TERMIOS} This module should be used in conjunction with the
module, which defines the relevant symbolic constants (see the next \module{TERMIOS}\refstmodindex{TERMIOS} module, which defines the
section). relevant symbolic constants (see the next section).
The module defines the following functions: The module defines the following functions:
\begin{funcdesc}{tcgetattr}{fd} \begin{funcdesc}{tcgetattr}{fd}
Return a list containing the tty attributes for file descriptor Return a list containing the tty attributes for file descriptor
\var{fd}, as follows: \code{[\var{iflag}, \var{oflag}, \var{cflag}, \var{fd}, as follows: \code{[}\var{iflag}, \var{oflag}, \var{cflag},
\var{lflag}, \var{ispeed}, \var{ospeed}, \var{cc}]} where \var{cc} is \var{lflag}, \var{ispeed}, \var{ospeed}, \var{cc}\code{]} where
a list of the tty special characters (each a string of length 1, \var{cc} is a list of the tty special characters (each a string of
except the items with indices \code{VMIN} and \code{VTIME}, which are length 1, except the items with indices \constant{TERMIOS.VMIN} and
integers when these fields are defined). The interpretation of the \constant{TERMIOS.VTIME}, which are integers when these fields are
flags and the speeds as well as the indexing in the \var{cc} array defined). The interpretation of the flags and the speeds as well as
must be done using the symbolic constants defined in the the indexing in the \var{cc} array must be done using the symbolic
\code{TERMIOS} module. constants defined in the \module{TERMIOS} module.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{tcsetattr}{fd\, when\, attributes} \begin{funcdesc}{tcsetattr}{fd, when, attributes}
Set the tty attributes for file descriptor \var{fd} from the Set the tty attributes for file descriptor \var{fd} from the
\var{attributes}, which is a list like the one returned by \var{attributes}, which is a list like the one returned by
\code{tcgetattr()}. The \var{when} argument determines when the \function{tcgetattr()}. The \var{when} argument determines when the
attributes are changed: \code{TERMIOS.TCSANOW} to change immediately, attributes are changed: \constant{TERMIOS.TCSANOW} to change
\code{TERMIOS.TCSADRAIN} to change after transmitting all queued immediately, \constant{TERMIOS.TCSADRAIN} to change after transmitting
output, or \code{TERMIOS.TCSAFLUSH} to change after transmitting all all queued output, or \constant{TERMIOS.TCSAFLUSH} to change after
queued output and discarding all queued input. transmitting all queued output and discarding all queued input.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{tcsendbreak}{fd\, duration} \begin{funcdesc}{tcsendbreak}{fd, duration}
Send a break on file descriptor \var{fd}. A zero \var{duration} sends 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 a break for 0.25--0.5 seconds; a nonzero \var{duration} has a system
dependent meaning. dependent meaning.
...@@ -55,27 +54,28 @@ Wait until all output written to file descriptor \var{fd} has been ...@@ -55,27 +54,28 @@ Wait until all output written to file descriptor \var{fd} has been
transmitted. transmitted.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{tcflush}{fd\, queue} \begin{funcdesc}{tcflush}{fd, queue}
Discard queued data on file descriptor \var{fd}. The \var{queue} Discard queued data on file descriptor \var{fd}. The \var{queue}
selector specifies which queue: \code{TERMIOS.TCIFLUSH} for the input selector specifies which queue: \constant{TERMIOS.TCIFLUSH} for the
queue, \code{TERMIOS.TCOFLUSH} for the output queue, or input queue, \constant{TERMIOS.TCOFLUSH} for the output queue, or
\code{TERMIOS.TCIOFLUSH} for both queues. \constant{TERMIOS.TCIOFLUSH} for both queues.
\end{funcdesc} \end{funcdesc}
\begin{funcdesc}{tcflow}{fd\, action} \begin{funcdesc}{tcflow}{fd, action}
Suspend or resume input or output on file descriptor \var{fd}. The Suspend or resume input or output on file descriptor \var{fd}. The
\var{action} argument can be \code{TERMIOS.TCOOFF} to suspend output, \var{action} argument can be \constant{TERMIOS.TCOOFF} to suspend
\code{TERMIOS.TCOON} to restart output, \code{TERMIOS.TCIOFF} to output, \constant{TERMIOS.TCOON} to restart output,
suspend input, or \code{TERMIOS.TCION} to restart input. \constant{TERMIOS.TCIOFF} to suspend input, or
\constant{TERMIOS.TCION} to restart input.
\end{funcdesc} \end{funcdesc}
\subsection{Example} \subsection{Example}
\nodename{termios Example} \nodename{termios Example}
Here's a function that prompts for a password with echoing turned off. Here's a function that prompts for a password with echoing turned
Note the technique using a separate \code{termios.tcgetattr()} call off. Note the technique using a separate \function{tcgetattr()} call
and a \code{try \ldots{} finally} statement to ensure that the old tty and a \keyword{try} ... \keyword{finally} statement to ensure that the
attributes are restored exactly no matter what happens: old tty attributes are restored exactly no matter what happens:
\begin{verbatim} \begin{verbatim}
def getpass(prompt = "Password: "): def getpass(prompt = "Password: "):
...@@ -83,7 +83,7 @@ def getpass(prompt = "Password: "): ...@@ -83,7 +83,7 @@ def getpass(prompt = "Password: "):
fd = sys.stdin.fileno() fd = sys.stdin.fileno()
old = termios.tcgetattr(fd) old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd) new = termios.tcgetattr(fd)
new[3] = new[3] & \~TERMIOS.ECHO # lflags new[3] = new[3] & ~TERMIOS.ECHO # lflags
try: try:
termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new) termios.tcsetattr(fd, TERMIOS.TCSADRAIN, new)
passwd = raw_input(prompt) passwd = raw_input(prompt)
...@@ -101,9 +101,9 @@ def getpass(prompt = "Password: "): ...@@ -101,9 +101,9 @@ def getpass(prompt = "Password: "):
\setindexsubitem{(in module TERMIOS)} \setindexsubitem{(in module TERMIOS)}
This module defines the symbolic constants required to use the This module defines the symbolic constants required to use the
\code{termios} module (see the previous section). See the \POSIX{} or \module{termios}\refbimodindex{termios} module (see the previous
\UNIX{} manual pages (or the source) for a list of those constants. section). See the \POSIX{} or \UNIX{} manual pages (or the source)
\refbimodindex{termios} for a list of those constants.
Note: this module resides in a system-dependent subdirectory of the Note: this module resides in a system-dependent subdirectory of the
Python library directory. You may have to generate it for your Python library directory. You may have to generate it for your
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment