#[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
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.