[go: up one dir, main page]

Terminal

Trait Terminal 

Source
pub trait Terminal {
    // Required methods
    fn set_raw_mode(&mut self) -> Result<()>;
    fn set_cooked_mode(&mut self) -> Result<()>;
    fn enter_alternate_screen(&mut self) -> Result<()>;
    fn exit_alternate_screen(&mut self) -> Result<()>;
    fn get_screen_size(&mut self) -> Result<ScreenSize>;
    fn set_screen_size(&mut self, size: ScreenSize) -> Result<()>;
    fn render(&mut self, changes: &[Change]) -> Result<()>;
    fn flush(&mut self) -> Result<()>;
    fn poll_input(
        &mut self,
        wait: Option<Duration>,
    ) -> Result<Option<InputEvent>>;
    fn waker(&self) -> TerminalWaker;

    // Provided method
    fn probe_capabilities(&mut self) -> Option<ProbeCapabilities<'_>> { ... }
}
Expand description

Terminal abstracts over some basic terminal capabilities. If the set_raw_mode or set_cooked_mode functions are used in any combination, the implementation is required to restore the terminal mode that was in effect when it was created.

Required Methods§

Source

fn set_raw_mode(&mut self) -> Result<()>

Raw mode disables input line buffering, allowing data to be read as the user presses keys, disables local echo, so keys pressed by the user do not implicitly render to the terminal output, and disables canonicalization of unix newlines to CRLF.

Source

fn set_cooked_mode(&mut self) -> Result<()>

Source

fn enter_alternate_screen(&mut self) -> Result<()>

Enter the alternate screen. The alternate screen will be left automatically when the Terminal is dropped.

Source

fn exit_alternate_screen(&mut self) -> Result<()>

Exit the alternate screen.

Source

fn get_screen_size(&mut self) -> Result<ScreenSize>

Queries the current screen size, returning width, height.

Source

fn set_screen_size(&mut self, size: ScreenSize) -> Result<()>

Sets the current screen size

Source

fn render(&mut self, changes: &[Change]) -> Result<()>

Render a series of changes to the terminal output

Source

fn flush(&mut self) -> Result<()>

Flush any buffered output

Source

fn poll_input(&mut self, wait: Option<Duration>) -> Result<Option<InputEvent>>

Check for a parsed input event. wait indicates the behavior in the case that no input is immediately available. If wait is None then poll_input will not return until an event is available. If wait is Some(duration) then poll_input will wait up to the given duration for an event before returning with a value of Ok(None). If wait is Some(Duration::ZERO) then the poll is non-blocking.

The possible values returned as InputEvents depend on the mode of the terminal. Most values are not returned unless the terminal is set to raw mode.

Source

fn waker(&self) -> TerminalWaker

Provided Methods§

Source

fn probe_capabilities(&mut self) -> Option<ProbeCapabilities<'_>>

Returns a capability probing helper that will use escape sequences to attempt to probe information from the terminal

Implementors§