Skip to main content

State

Struct State 

Source
#[non_exhaustive]
pub struct State { pub input: Option<termios>, pub output: Option<termios>, }
Expand description

Snapshot of a terminal’s configuration.

On Unix this stores one libc::termios per half, because the input and output descriptors are not required to refer to the same terminal device. A half whose attributes cannot be read is stored as None and is skipped when the state is applied. On Windows it stores both input and output console-mode bitfields.

A State records each half separately, so it is bound to the pair it was read from. Apply it to that same (input, output) pair; applying it to a different pair writes each half’s attributes to a descriptor they did not come from.

Use values returned by Terminal::get_state or Terminal::make_raw with Terminal::set_state to restore a terminal to a previous configuration.

The fields are readable so a caller can inspect what was saved — a snapshot taken before raw mode is otherwise unrecoverable, since re-reading the descriptor afterwards reports the raw state rather than this one. Both platforms name the halves input and output, but what they hold is inherently platform-specific: a termios and a console mode are not the same concept, so there is no portable shape to offer instead and code that reads them is unix-only or Windows-only by nature. The unix types come from the libc re-export.

The struct is non_exhaustive: a State is only meaningful when it came from the terminal, so it is readable but not constructible from outside the crate.

§Examples

use uncurses::libc;
use uncurses::terminal::Terminal;

let mut term = Terminal::stdio();
let saved = term.make_raw().unwrap();

// Reading the descriptor now would report the raw state, so this snapshot
// is the only way to see what the terminal looked like beforehand.
if let Some(input) = saved.input {
    println!("echo was on: {}", input.c_lflag & libc::ECHO != 0);
}

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§input: Option<termios>

Saved attributes of the input descriptor, or None when they could not be read — typically because it is not a terminal.

§output: Option<termios>

Saved attributes of the output descriptor, or None when they could not be read — typically because it is not a terminal.

Trait Implementations§

Source§

impl Clone for State

Source§

fn clone(&self) -> State

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for State

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for State

§

impl RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl UnsafeUnpin for State

§

impl UnwindSafe for State

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.