Skip to main content

Terminal

Trait Terminal 

Source
pub trait Terminal {
    // Required methods
    fn capabilities(&self) -> Capabilities;
    fn read_line(&mut self) -> AppResult<Option<String>>;
    fn read_key(&mut self) -> AppResult<Key>;
    fn write(&mut self, text: &str) -> AppResult<()>;
    fn write_line(&mut self, text: &str) -> AppResult<()>;
    fn flush(&mut self) -> AppResult<()>;
    fn clear_last_lines(&mut self, count: u16) -> AppResult<()>;
    fn begin_interactive(&mut self) -> AppResult<()>;
    fn end_interactive(&mut self) -> AppResult<()>;
}
Expand description

The interactive medium a prompter reads from and renders to.

Implementations own the I/O device and, for key-driven terminals, the raw-mode lifecycle and cursor movement needed to redraw a live frame. The prompter builds already-styled strings; the terminal only writes them and, between frames, clears the lines it previously drew.

Required Methods§

Source

fn capabilities(&self) -> Capabilities

The interaction model this terminal supports.

Source

fn read_line(&mut self) -> AppResult<Option<String>>

Read one whole line (line-driven terminals).

Returns Ok(None) at end of input so callers surface a typed “input closed” error instead of hanging.

§Errors

Returns an error when the underlying reader fails, or when the terminal is key-driven and does not support line reads.

Source

fn read_key(&mut self) -> AppResult<Key>

Read one decoded keystroke (key-driven terminals).

§Errors

Returns an error when the underlying device fails, at end of input, or when the terminal is line-driven and does not support key reads.

Source

fn write(&mut self, text: &str) -> AppResult<()>

Write text verbatim (no trailing newline).

§Errors

Returns an error when the underlying writer fails.

Source

fn write_line(&mut self, text: &str) -> AppResult<()>

Write text followed by a newline (a carriage return + line feed in raw mode).

§Errors

Returns an error when the underlying writer fails.

Source

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

Flush any buffered output.

§Errors

Returns an error when the underlying writer fails.

Source

fn clear_last_lines(&mut self, count: u16) -> AppResult<()>

Move the cursor up count lines and clear from there down, so the next frame overwrites the previous one. A no-op for line-driven terminals.

§Errors

Returns an error when the underlying device fails.

Source

fn begin_interactive(&mut self) -> AppResult<()>

Enter interactive (raw) mode before a key-driven loop. A no-op for line-driven terminals.

§Errors

Returns an error when raw mode cannot be entered.

Source

fn end_interactive(&mut self) -> AppResult<()>

Leave interactive (raw) mode after a key-driven loop. A no-op for line-driven terminals.

§Errors

Returns an error when raw mode cannot be restored.

Trait Implementations§

Source§

impl Terminal for Box<dyn Terminal>

Source§

fn capabilities(&self) -> Capabilities

The interaction model this terminal supports.
Source§

fn read_line(&mut self) -> AppResult<Option<String>>

Read one whole line (line-driven terminals). Read more
Source§

fn read_key(&mut self) -> AppResult<Key>

Read one decoded keystroke (key-driven terminals). Read more
Source§

fn write(&mut self, text: &str) -> AppResult<()>

Write text verbatim (no trailing newline). Read more
Source§

fn write_line(&mut self, text: &str) -> AppResult<()>

Write text followed by a newline (a carriage return + line feed in raw mode). Read more
Source§

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

Flush any buffered output. Read more
Source§

fn clear_last_lines(&mut self, count: u16) -> AppResult<()>

Move the cursor up count lines and clear from there down, so the next frame overwrites the previous one. A no-op for line-driven terminals. Read more
Source§

fn begin_interactive(&mut self) -> AppResult<()>

Enter interactive (raw) mode before a key-driven loop. A no-op for line-driven terminals. Read more
Source§

fn end_interactive(&mut self) -> AppResult<()>

Leave interactive (raw) mode after a key-driven loop. A no-op for line-driven terminals. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Terminal for Box<dyn Terminal>

Source§

fn capabilities(&self) -> Capabilities

Source§

fn read_line(&mut self) -> AppResult<Option<String>>

Source§

fn read_key(&mut self) -> AppResult<Key>

Source§

fn write(&mut self, text: &str) -> AppResult<()>

Source§

fn write_line(&mut self, text: &str) -> AppResult<()>

Source§

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

Source§

fn clear_last_lines(&mut self, count: u16) -> AppResult<()>

Source§

fn begin_interactive(&mut self) -> AppResult<()>

Source§

fn end_interactive(&mut self) -> AppResult<()>

Implementors§