Trait linefeed::terminal::Terminal
[−]
[src]
pub trait Terminal: Sized { type PrepareGuard; fn new() -> Result<Self>; fn eof_char(&self) -> char; fn literal_char(&self) -> char; fn erase_char(&self) -> char; fn word_erase_char(&self) -> char; fn kill_char(&self) -> char; fn delete_seq(&self) -> &str; fn insert_seq(&self) -> &str; fn name(&self) -> Option<&str>; fn size(&self) -> Result<Size>; fn clear_screen(&self) -> Result<()>; fn clear_to_screen_end(&self) -> Result<()>; fn move_up(&self, n: usize) -> Result<()>; fn move_down(&self, n: usize) -> Result<()>; fn move_left(&self, n: usize) -> Result<()>; fn move_right(&self, n: usize) -> Result<()>; fn move_to_first_col(&self) -> Result<()>; fn set_cursor_mode(&self, mode: CursorMode) -> Result<()>; fn wait_for_input(&self, timeout: Option<Duration>) -> Result<bool>; fn prepare(
&self,
catch_signals: bool,
report_signals: SignalSet
) -> Result<Self::PrepareGuard>; fn get_signal(&self) -> Option<Signal>; fn take_signal(&self) -> Option<Signal>; fn read_signals(&self) -> Result<Self::PrepareGuard>; fn read(&self, buf: &mut Vec<u8>) -> Result<usize>; fn write(&self, s: &str) -> Result<()>; }
Defines a low-level interface to the terminal
Associated Types
type PrepareGuard
Returned by prepare
and read_signals
.
When dropped, the prior terminal state will be restored.
Required Methods
fn new() -> Result<Self>
Initialize the terminal interface
fn eof_char(&self) -> char
Returns the character that indicates end-of-file
fn literal_char(&self) -> char
Returns the character that indicates literal quoting sequence
fn erase_char(&self) -> char
Returns the character that indicates backward character erase
fn word_erase_char(&self) -> char
Returns the character that indicates backward word erase
fn kill_char(&self) -> char
Returns the character that indicates backward kill line
fn delete_seq(&self) -> &str
Returns the key sequence that indicates forward delete character
fn insert_seq(&self) -> &str
Returns the key sequence that indicates switching to insert mode
fn name(&self) -> Option<&str>
Returns the name of the terminal, if one has been supplied
fn size(&self) -> Result<Size>
Returns the size of the terminal window
fn clear_screen(&self) -> Result<()>
Presents a clear terminal screen, with cursor at first row, first column.
If the terminal possesses a scrolling window over a buffer, this shall have the effect of moving the visible window down such that it shows an empty view of the buffer, preserving some or all of existing buffer contents, where possible.
fn clear_to_screen_end(&self) -> Result<()>
Clears characters on the line occupied by the cursor, beginning with the cursor and ending at the end of the line. Also clears all characters on all lines after the cursor.
fn move_up(&self, n: usize) -> Result<()>
Moves the cursor up n
cells; n
may be zero.
fn move_down(&self, n: usize) -> Result<()>
Moves the cursor down n
cells; n
may be zero.
fn move_left(&self, n: usize) -> Result<()>
Moves the cursor left n
cells; n
may be zero.
fn move_right(&self, n: usize) -> Result<()>
Moves the cursor right n
cells; n
may be zero.
fn move_to_first_col(&self) -> Result<()>
Moves the cursor to the first column of the current line
fn set_cursor_mode(&self, mode: CursorMode) -> Result<()>
Set the current cursor mode
fn wait_for_input(&self, timeout: Option<Duration>) -> Result<bool>
Waits timeout
for user input. If timeout
is None
, waits indefinitely.
Returns Ok(true)
if input becomes available within the given timeout
or if a signal is received.
Returns Ok(false)
if the timeout expires before input becomes available.
fn prepare(
&self,
catch_signals: bool,
report_signals: SignalSet
) -> Result<Self::PrepareGuard>
&self,
catch_signals: bool,
report_signals: SignalSet
) -> Result<Self::PrepareGuard>
Prepares the terminal for line reading and editing operations.
When the returned value is dropped, the terminal will be restored to its
state prior to calling prepare
.
If catch_signals
is true
, signal handlers will be registered.
These are also restored when the guard value is dropped.
The set of signals caught should include those contained in
report_signals
.
fn get_signal(&self) -> Option<Signal>
If the process received a signal since the last call to take_signal
,
return it. Otherwise, return None
.
fn take_signal(&self) -> Option<Signal>
If the process received a signal since the last call to take_signal
,
consume and return it. Otherwise, return None
.
fn read_signals(&self) -> Result<Self::PrepareGuard>
Configures the terminal to interpret signal-inducing characters as input without raising a signal.
When the returned value is dropped, the terminal will be restored to its
state prior to calling read_signals
.
fn read(&self, buf: &mut Vec<u8>) -> Result<usize>
Reads some input from the terminal and appends it to the given buffer.
Returns the number of bytes read. Ok(0)
may be returned to indicate
that no bytes can be read at this time.
fn write(&self, s: &str) -> Result<()>
Writes output to the terminal and immediately flushes it to the device.
For each newline '\n'
written to the terminal, the cursor should
be moved to the first column of the following line.
The terminal interface shall not automatically move the cursor to the next
line when write
causes a character to be written to the final column.
Implementors
impl Terminal for MemoryTerminal type PrepareGuard = ();