Struct Term
pub struct Term { /* private fields */ }
Abstraction around a terminal.
A terminal can be cloned. If a buffer is used it's shared across all clones which means it largely acts as a handle.
Implementations
impl Term
fn stdout() -> TermReturn a new unbuffered terminal.
fn stderr() -> TermReturn a new unbuffered terminal to stderr.
fn buffered_stdout() -> TermReturn a new buffered terminal.
fn buffered_stderr() -> TermReturn a new buffered terminal to stderr.
fn read_write_pair<R, W>(read: R, write: W) -> Term where R: Read + Debug + AsRawFd + Send + 'static, W: Write + Debug + AsRawFd + Send + 'static,Return a terminal for the given Read/Write pair styled like stderr.
fn read_write_pair_with_style<R, W>(read: R, write: W, style: Style) -> Term where R: Read + Debug + AsRawFd + Send + 'static, W: Write + Debug + AsRawFd + Send + 'static,Return a terminal for the given Read/Write pair.
fn style(&self) -> StyleReturn the style for this terminal.
fn target(&self) -> TermTargetReturn the target of this terminal.
fn write_line(&self, s: &str) -> Result<()>Write a string to the terminal and add a newline.
fn read_char(&self) -> Result<char>Read a single character from the terminal.
This does not echo the character and blocks until a single character or complete key chord is entered. If the terminal is not user attended the return value will be an error.
fn read_key(&self) -> Result<Key>Read a single key from the terminal.
This does not echo anything. If the terminal is not user attended the return value will always be the unknown key.
fn read_key_raw(&self) -> Result<Key>fn read_line(&self) -> Result<String>Read one line of input.
This does not include the trailing newline. If the terminal is not user attended the return value will always be an empty string.
fn read_line_initial_text(&self, initial: &str) -> Result<String>Read one line of input with initial text.
This method blocks until no other thread is waiting for this read_line before reading a line from the terminal. This does not include the trailing newline. If the terminal is not user attended the return value will always be an empty string.
fn read_secure_line(&self) -> Result<String>Read a line of input securely.
This is similar to
read_linebut will not echo the output. This also switches the terminal into a different mode where not all characters might be accepted.fn flush(&self) -> Result<()>Flush internal buffers.
This forces the contents of the internal buffer to be written to the terminal. This is unnecessary for unbuffered terminals which will automatically flush.
fn is_term(&self) -> boolCheck if the terminal is indeed a terminal.
fn features(&self) -> TermFeatures<'_>Check for common terminal features.
fn size(&self) -> (u16, u16)Return the terminal size in rows and columns or gets sensible defaults.
fn size_checked(&self) -> Option<(u16, u16)>Return the terminal size in rows and columns.
If the size cannot be reliably determined
Noneis returned.fn move_cursor_to(&self, x: usize, y: usize) -> Result<()>Move the cursor to row
xand columny. Values are 0-based.fn move_cursor_up(&self, n: usize) -> Result<()>Move the cursor up by
nlines, if possible.If there are less than
nlines above the current cursor position, the cursor is moved to the top line of the terminal (i.e., as far up as possible).fn move_cursor_down(&self, n: usize) -> Result<()>Move the cursor down by
nlines, if possible.If there are less than
nlines below the current cursor position, the cursor is moved to the bottom line of the terminal (i.e., as far down as possible).fn move_cursor_left(&self, n: usize) -> Result<()>Move the cursor
ncharacters to the left, if possible.If there are fewer than
ncharacters to the left of the current cursor position, the cursor is moved to the beginning of the line (i.e., as far to the left as possible).fn move_cursor_right(&self, n: usize) -> Result<()>Move the cursor
ncharacters to the right.If there are fewer than
ncharacters to the right of the current cursor position, the cursor is moved to the end of the current line (i.e., as far to the right as possible).fn clear_line(&self) -> Result<()>Clear the current line.
Position the cursor at the beginning of the current line.
fn clear_last_lines(&self, n: usize) -> Result<()>Clear the last
nlines before the current line.Position the cursor at the beginning of the first line that was cleared.
fn clear_screen(&self) -> Result<()>Clear the entire screen.
Move the cursor to the upper left corner of the screen.
fn clear_to_end_of_screen(&self) -> Result<()>Clear everything from the current cursor position to the end of the screen. The cursor stays in its position.
fn clear_chars(&self, n: usize) -> Result<()>Clear the last
ncharacters of the current line.fn set_title<T: Display>(&self, title: T)Set the terminal title.
fn show_cursor(&self) -> Result<()>Make the cursor visible again.
fn hide_cursor(&self) -> Result<()>Hide the cursor.
Trait Implementations
impl AsRawFd for Term
fn as_raw_fd(&self) -> RawFd
impl Clone for Term
fn clone(&self) -> Self
impl Debug for Term
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Read for Term
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
impl Write for Term
fn write(&mut self, buf: &[u8]) -> Result<usize>fn flush(&mut self) -> Result<()>
Auto Trait Implementations
impl Freeze for Term
impl RefUnwindSafe for Term
impl Send for Term
impl Sync for Term
impl Unpin for Term
impl UnsafeUnpin for Term
impl UnwindSafe for Term
Blanket Implementations
impl<T> Any for Term
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Term
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Term
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Term
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Term
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Term
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Term
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Term
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Term
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>