pub trait Terminal {
    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; }
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

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.

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

Exit the alternate screen.

Queries the current screen size, returning width, height.

Sets the current screen size

Render a series of changes to the terminal output

Flush any buffered output

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.

Implementors