pub trait Terminal: Write {
// Required methods
fn enter_raw_mode(&mut self) -> Result<()>;
fn enter_cooked_mode(&mut self) -> Result<()>;
fn get_dimensions(&self) -> Result<WindowSize>;
fn event_reader(&self) -> EventReader;
fn poll<F: Fn(&Event) -> bool>(
&self,
filter: F,
timeout: Option<Duration>,
) -> Result<bool>;
fn read<F: Fn(&Event) -> bool>(&self, filter: F) -> Result<Event>;
fn set_panic_hook(
&mut self,
f: impl Fn(&mut PlatformHandle) + Send + Sync + 'static,
);
}Required Methods§
Sourcefn enter_raw_mode(&mut self) -> Result<()>
fn enter_raw_mode(&mut self) -> Result<()>
Enters the “raw” terminal mode.
While in “raw” mode a terminal will not attempt to do any helpful interpretation of input
such as waiting for Enter key presses to pass input. This is essentially the opposite of
“cooked” mode. To exit raw mode, use Self::enter_cooked_mode.
Sourcefn enter_cooked_mode(&mut self) -> Result<()>
fn enter_cooked_mode(&mut self) -> Result<()>
Enters the “cooked” terminal mode.
This is considered the normal mode for a terminal device.
While in “cooked” mode a terminal will interpret the incoming data in ways that are useful such as waiting for an Enter key press to pass input to the application.
fn get_dimensions(&self) -> Result<WindowSize>
fn event_reader(&self) -> EventReader
Sourcefn poll<F: Fn(&Event) -> bool>(
&self,
filter: F,
timeout: Option<Duration>,
) -> Result<bool>
fn poll<F: Fn(&Event) -> bool>( &self, filter: F, timeout: Option<Duration>, ) -> Result<bool>
Checks if there is an Event available.
Returns Ok(true) if an Event is available or Ok(false) if one is not available.
If timeout is None then poll will block indefinitely.
Sourcefn read<F: Fn(&Event) -> bool>(&self, filter: F) -> Result<Event>
fn read<F: Fn(&Event) -> bool>(&self, filter: F) -> Result<Event>
Reads a single Event from the terminal.
This function blocks until an Event is available. Use poll first to guarantee that the
read won’t block.
Sourcefn set_panic_hook(
&mut self,
f: impl Fn(&mut PlatformHandle) + Send + Sync + 'static,
)
fn set_panic_hook( &mut self, f: impl Fn(&mut PlatformHandle) + Send + Sync + 'static, )
Sets a hook function to run.
Depending on how your application handles panics you may wish to set a panic hook which
eagerly resets the terminal (such as by disabling bracketed paste and entering the main
screen). The parameter for this hook is a platform handle to std::io::stdout or
equivalent which implements std::io::Write. When the hook function is finished running
the handle’s modes will be reset (same as enter_cooked_mode).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.