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§
Sourcefn capabilities(&self) -> Capabilities
fn capabilities(&self) -> Capabilities
The interaction model this terminal supports.
Sourcefn read_line(&mut self) -> AppResult<Option<String>>
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.
Sourcefn read_key(&mut self) -> AppResult<Key>
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.
Sourcefn write(&mut self, text: &str) -> AppResult<()>
fn write(&mut self, text: &str) -> AppResult<()>
Write text verbatim (no trailing newline).
§Errors
Returns an error when the underlying writer fails.
Sourcefn write_line(&mut self, text: &str) -> AppResult<()>
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.
Sourcefn clear_last_lines(&mut self, count: u16) -> AppResult<()>
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.
Sourcefn begin_interactive(&mut self) -> AppResult<()>
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.
Sourcefn end_interactive(&mut self) -> AppResult<()>
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>
impl Terminal for Box<dyn Terminal>
Source§fn capabilities(&self) -> Capabilities
fn capabilities(&self) -> Capabilities
Source§fn read_line(&mut self) -> AppResult<Option<String>>
fn read_line(&mut self) -> AppResult<Option<String>>
Source§fn read_key(&mut self) -> AppResult<Key>
fn read_key(&mut self) -> AppResult<Key>
Source§fn write(&mut self, text: &str) -> AppResult<()>
fn write(&mut self, text: &str) -> AppResult<()>
text verbatim (no trailing newline). Read moreSource§fn write_line(&mut self, text: &str) -> AppResult<()>
fn write_line(&mut self, text: &str) -> AppResult<()>
text followed by a newline (a carriage return + line feed in raw
mode). Read moreSource§fn clear_last_lines(&mut self, count: u16) -> AppResult<()>
fn clear_last_lines(&mut self, count: u16) -> AppResult<()>
count lines and clear from there down, so the next
frame overwrites the previous one. A no-op for line-driven terminals. Read moreDyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".