Skip to main content

MemoryTerminal

Struct MemoryTerminal 

Source
pub struct MemoryTerminal { /* private fields */ }
Expand description

Implements an in-memory Terminal interface

The contents of a MemoryTerminal are shared. That is, cloning a MemoryTerminal value will share the contained terminal buffer.

Implementations§

Source§

impl MemoryTerminal

Source

pub fn new() -> MemoryTerminal

Returns a new MemoryTerminal with the default buffer size.

Source

pub fn with_size(size: Size) -> MemoryTerminal

Returns a new MemoryTerminal with the given buffer size.

§Panics

If either of the lines or columns fields are 0.

Source

pub fn clear_all(&self)

Clears the terminal buffer and places the cursor at (0, 0).

Source

pub fn clear_to_end(&self)

Clears all characters beginning at the cursor and ending at buffer end.

Source

pub fn clear_input(&self)

Clears the input buffer.

Source

pub fn has_input(&self) -> bool

Returns whether any input remains to be read.

Source

pub fn lines(&self) -> Lines<'_>

Returns an iterator over lines in the buffer.

§Notes

The returned iterator immutably borrows the contents of the MemoryTerminal. Attempting to perform a mutating operation on the parent MemoryTerminal while the Lines iterator lives will cause a panic.

Source

pub fn move_up(&self, n: usize)

Moves the cursor up n cells.

Source

pub fn move_down(&self, n: usize)

Moves the cursor down n cells.

Source

pub fn move_left(&self, n: usize)

Moves the cursor left n cells.

Source

pub fn move_right(&self, n: usize)

Moves the cursor right n cells.

Source

pub fn move_to_first_column(&self)

Moves the cursor to the first column of the current line.

Source

pub fn push_input(&self, s: &str)

Pushes a character sequence to the back of the input queue.

Source

pub fn read_input(&self, buf: &mut [u8]) -> usize

Reads some input from the input buffer.

Source

pub fn resize(&self, new_size: Size)

Changes the size of the terminal buffer. The buffer will be truncated or filled with spaces, as necessary.

§Panics

If either of the lines or columns fields are 0 or if the area exceeds usize maximum.

Source

pub fn scroll_up(&self, n: usize)

Moves the contents of the buffer up n lines. The first n lines of text will be erased.

Source

pub fn cursor(&self) -> (usize, usize)

Returns the (line, column) position of the cursor.

Source

pub fn set_cursor_mode(&self, mode: CursorMode)

Sets the cursor mode.

Source

pub fn cursor_mode(&self) -> CursorMode

Returns the cursor mode.

Source

pub fn size(&self) -> Size

Returns the size of the terminal buffer.

Source

pub fn write(&self, s: &str)

Writes some text into the buffer.

If the text extends beyond the length of the current line without a newline character ('\n'), the extraneous text will be dropped.

Trait Implementations§

Source§

impl Clone for MemoryTerminal

Source§

fn clone(&self) -> MemoryTerminal

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MemoryTerminal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MemoryTerminal

Source§

fn default() -> MemoryTerminal

Returns the “default value” for a type. Read more
Source§

impl Terminal for MemoryTerminal

Source§

type PrepareState = ()

Returned by prepare; passed to restore to restore state.
Source§

fn name(&self) -> &str

Returns the name of the terminal.
Source§

fn lock_read<'a>(&'a self) -> Box<dyn TerminalReader<Self> + 'a>

Acquires a lock on terminal read operations and returns a value holding that lock and granting access to such operations. Read more
Source§

fn lock_write<'a>(&'a self) -> Box<dyn TerminalWriter<Self> + 'a>

Acquires a lock on terminal write operations and returns a value holding that lock and granting access to such operations. Read more
Source§

impl<'a> TerminalReader<MemoryTerminal> for MemoryReadGuard<'a>

Source§

fn wait_for_input(&mut self, _timeout: Option<Duration>) -> Result<bool>

Waits timeout for user input. If timeout is None, waits indefinitely. Read more
Source§

fn prepare( &mut self, _block_signals: bool, _report_signals: SignalSet, ) -> Result<()>

Prepares the terminal for line reading and editing operations. Read more
Source§

unsafe fn prepare_with_lock( &mut self, _lock: &mut dyn TerminalWriter<MemoryTerminal>, _block_signals: bool, _report_signals: SignalSet, ) -> Result<()>

Like prepare, but called when the write lock is already held. Read more
Source§

fn restore(&mut self, _state: ()) -> Result<()>

Restores the terminal state using the given state data.
Source§

unsafe fn restore_with_lock( &mut self, _lock: &mut dyn TerminalWriter<MemoryTerminal>, _state: (), ) -> Result<()>

Like restore, but called when the write lock is already held. Read more
Source§

fn read(&mut self, buf: &mut Vec<u8>) -> Result<RawRead>

Reads some input from the terminal and appends it to the given buffer.
Source§

impl<'a> TerminalWriter<MemoryTerminal> for MemoryWriteGuard<'a>

Source§

fn size(&self) -> Result<Size>

Returns the size of the terminal window
Source§

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

Presents a clear terminal screen, with cursor at first row, first column. Read more
Source§

fn clear_to_screen_end(&mut 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.
Source§

fn move_up(&mut self, n: usize) -> Result<()>

Moves the cursor up n cells; n may be zero.
Source§

fn move_down(&mut self, n: usize) -> Result<()>

Moves the cursor down n cells; n may be zero.
Source§

fn move_left(&mut self, n: usize) -> Result<()>

Moves the cursor left n cells; n may be zero.
Source§

fn move_right(&mut self, n: usize) -> Result<()>

Moves the cursor right n cells; n may be zero.
Source§

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

Moves the cursor to the first column of the current line
Source§

fn set_cursor_mode(&mut self, mode: CursorMode) -> Result<()>

Set the current cursor mode
Source§

fn write(&mut self, s: &str) -> Result<()>

Writes output to the terminal. Read more
Source§

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

Flushes any currently buffered output data. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.