pub trait ConsoleControl: Sealed {
type Saved: Send + Sync + Copy + 'static;
const HANDLER_CONTRACT: HandlerContract;
// Required methods
fn capture(&self) -> Result<Self::Saved>;
fn restore(&self, saved: &Self::Saved) -> Result<()>;
fn write_raw(&self, bytes: &[u8]);
fn trap(&self, on_interrupt: fn()) -> Result<()>;
fn interrupt_exit_code(&self) -> i32;
}Expand description
Save/restore terminal state and trap the interrupt-class events.
Required Associated Constants§
Required Associated Types§
Required Methods§
Sourcefn capture(&self) -> Result<Self::Saved>
fn capture(&self) -> Result<Self::Saved>
Capture the modes as they are now. Call before anything enters raw mode: a later call would save raw modes as the thing to restore to.
Sourcefn restore(&self, saved: &Self::Saved) -> Result<()>
fn restore(&self, saved: &Self::Saved) -> Result<()>
Put the modes back. Must be callable from the interrupt handler, so on
Unix this is tcsetattr and nothing else.
Sourcefn write_raw(&self, bytes: &[u8])
fn write_raw(&self, bytes: &[u8])
Write bytes straight to the terminal, bypassing any buffering — the escape-sequence half of a restore. Async-signal-safe on Unix.
Sourcefn trap(&self, on_interrupt: fn()) -> Result<()>
fn trap(&self, on_interrupt: fn()) -> Result<()>
Run on_interrupt for each interrupt-class event, then exit.
on_interrupt must respect HANDLER_CONTRACT.
A plain fn rather than a closure so there is nothing to allocate or
capture on the Unix path.
Sourcefn interrupt_exit_code(&self) -> i32
fn interrupt_exit_code(&self) -> i32
The process exit code for “killed by an interrupt”.
128 + signal is a POSIX shell convention with no Windows meaning.
Windows returns 130 for Ctrl-C anyway, because scripts and CI check for
it — a deliberate borrowing, flagged here rather than left to look like
an accident.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".