prettytty

Struct Connection

Source
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 Commands, executes the first command right away, and defers the second command to just before the terminal connection is closed.

Implementations§

Source§

impl Connection

Source

pub fn open() -> Result<Self>

Open a terminal connection with the default options.

Source

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.

Source

pub fn options(&self) -> &Options

Get the options used when opening this connection.

Source

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.

Source

pub fn input(&self) -> Input<'_>

Get the terminal input.

The returned input object ensures mutually exclusive access to the terminal’s input. Dropping the input object releases access again.

§Panics

If the underlying mutex has been poisoned.

Source

pub fn output(&self) -> Output<'_>

Get the terminal output.

The returned output object ensures mutually exclusive access to the terminal’s output. Dropping the output object releases access again.

§Panics

If the underlying mutex has been poisoned.

Trait Implementations§

Source§

impl Debug for Connection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Connection

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.