pub struct Connection { /* private fields */ }
Expand description
A terminal connection providing Input
and Output
.
This object owns the connection to the terminal. It provides independent,
mutually exclusive, and thread-safe access to Input
as well as
Output
. On Unix, the I/O types share the same underlying file
descriptor, whereas on Windows each I/O type uses a distinct handle.
To facilitate reading from the terminal, this type reconfigures the
terminal, at a minimum by disabling the terminal’s line editing mode. Since
its drop handler restores the original configuration, an application
should go out of its way to always execute this type’s drop handler before
exit. Use drop
to manually close a connection before it
goes out of scope.
An application may need to make further changes, such as using the alternate
screen or hiding the cursor, that also need to be undone before exit. In
that case, the application can use Output::exec_defer
. The method takes
two Command
s, executes the first command right away, and defers the
second command to just before the terminal connection is closed.
Implementations§
Source§impl Connection
impl Connection
Sourcepub fn with_options(options: Options) -> Result<Self>
pub fn with_options(options: Options) -> Result<Self>
Open a terminal connection with the given options.
If this method cannot establish a connection to the controlling
terminal, it fails with a ErrorKind::ConnectionRefused
error.
Sourcepub fn io(&self) -> (Input<'_>, Output<'_>)
pub fn io(&self) -> (Input<'_>, Output<'_>)
Get both terminal input and output.
The returned input and output objects ensure mutually exclusive access to the terminal’s input and output, respectively. Dropping them releases access again.