pub struct Term { /* private fields */ }Expand description
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
sourceimpl Term
impl Term
sourcepub fn stdout() -> TermⓘNotable traits for Termimpl Write for Termimpl<'a> Write for &'a Termimpl Read for Termimpl<'a> Read for &'a Term
pub fn stdout() -> TermⓘNotable traits for Termimpl Write for Termimpl<'a> Write for &'a Termimpl Read for Termimpl<'a> Read for &'a Term
Return a new unbuffered terminal.
sourcepub fn stderr() -> TermⓘNotable traits for Termimpl Write for Termimpl<'a> Write for &'a Termimpl Read for Termimpl<'a> Read for &'a Term
pub fn stderr() -> TermⓘNotable traits for Termimpl Write for Termimpl<'a> Write for &'a Termimpl Read for Termimpl<'a> Read for &'a Term
Return a new unbuffered terminal to stderr.
sourcepub fn buffered_stdout() -> TermⓘNotable traits for Termimpl Write for Termimpl<'a> Write for &'a Termimpl Read for Termimpl<'a> Read for &'a Term
pub fn buffered_stdout() -> TermⓘNotable traits for Termimpl Write for Termimpl<'a> Write for &'a Termimpl Read for Termimpl<'a> Read for &'a Term
Return a new buffered terminal.
sourcepub fn buffered_stderr() -> TermⓘNotable traits for Termimpl Write for Termimpl<'a> Write for &'a Termimpl Read for Termimpl<'a> Read for &'a Term
pub fn buffered_stderr() -> TermⓘNotable traits for Termimpl Write for Termimpl<'a> Write for &'a Termimpl Read for Termimpl<'a> Read for &'a Term
Return a new buffered terminal to stderr.
sourcepub fn read_write_pair<R, W>(read: R, write: W) -> TermⓘNotable traits for Termimpl Write for Termimpl<'a> Write for &'a Termimpl Read for Termimpl<'a> Read for &'a Termwhere
R: Read + Debug + AsRawFd + Send + 'static,
W: Write + Debug + AsRawFd + Send + 'static,
pub fn read_write_pair<R, W>(read: R, write: W) -> TermⓘNotable traits for Termimpl Write for Termimpl<'a> Write for &'a Termimpl Read for Termimpl<'a> Read for &'a Termwhere
R: Read + Debug + AsRawFd + Send + 'static,
W: Write + Debug + AsRawFd + Send + 'static,
Return a terminal for the given Read/Write pair styled like stderr.
sourcepub fn read_write_pair_with_style<R, W>(read: R, write: W, style: Style) -> TermⓘNotable traits for Termimpl Write for Termimpl<'a> Write for &'a Termimpl Read for Termimpl<'a> Read for &'a Termwhere
R: Read + Debug + AsRawFd + Send + 'static,
W: Write + Debug + AsRawFd + Send + 'static,
pub fn read_write_pair_with_style<R, W>(read: R, write: W, style: Style) -> TermⓘNotable traits for Termimpl Write for Termimpl<'a> Write for &'a Termimpl Read for Termimpl<'a> Read for &'a Termwhere
R: Read + Debug + AsRawFd + Send + 'static,
W: Write + Debug + AsRawFd + Send + 'static,
Return a terminal for the given Read/Write pair.
sourcepub fn target(&self) -> TermTarget
pub fn target(&self) -> TermTarget
Return the target of this terminal.
sourcepub fn write_line(&self, s: &str) -> Result<()>
pub fn write_line(&self, s: &str) -> Result<()>
Write a string to the terminal and add a newline.
sourcepub fn read_char(&self) -> Result<char>
pub 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 is entered.
sourcepub fn read_key(&self) -> Result<Key>
pub fn read_key(&self) -> Result<Key>
Read a single key form the terminal.
This does not echo anything. If the terminal is not user attended the return value will always be the unknown key.
sourcepub fn read_line(&self) -> Result<String>
pub 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.
sourcepub fn read_line_initial_text(&self, initial: &str) -> Result<String>
pub fn read_line_initial_text(&self, initial: &str) -> Result<String>
Read one line of input with initial text.
This does not include the trailing newline. If the terminal is not user attended the return value will always be an empty string.
sourcepub fn read_secure_line(&self) -> Result<String>
pub fn read_secure_line(&self) -> Result<String>
Read a line of input securely.
This is similar to read_line but will not echo the output. This
also switches the terminal into a different mode where not all
characters might be accepted.
sourcepub fn flush(&self) -> Result<()>
pub 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.
sourcepub fn features(&self) -> TermFeatures<'_>
pub fn features(&self) -> TermFeatures<'_>
Check for common terminal features.
sourcepub fn size(&self) -> (u16, u16)
pub fn size(&self) -> (u16, u16)
Return the terminal size in rows and columns or gets sensible defaults.
sourcepub fn size_checked(&self) -> Option<(u16, u16)>
pub fn size_checked(&self) -> Option<(u16, u16)>
Return the terminal size in rows and columns.
If the size cannot be reliably determined None is returned.
sourcepub fn move_cursor_to(&self, x: usize, y: usize) -> Result<()>
pub fn move_cursor_to(&self, x: usize, y: usize) -> Result<()>
Move the cursor to row x and column y. Values are 0-based.
sourcepub fn move_cursor_up(&self, n: usize) -> Result<()>
pub fn move_cursor_up(&self, n: usize) -> Result<()>
Move the cursor up by n lines, if possible.
If there are less than n lines above the current cursor position,
the cursor is moved to the top line of the terminal (i.e., as far up as possible).
sourcepub fn move_cursor_down(&self, n: usize) -> Result<()>
pub fn move_cursor_down(&self, n: usize) -> Result<()>
Move the cursor down by n lines, if possible.
If there are less than n lines below the current cursor position,
the cursor is moved to the bottom line of the terminal (i.e., as far down as possible).
sourcepub fn move_cursor_left(&self, n: usize) -> Result<()>
pub fn move_cursor_left(&self, n: usize) -> Result<()>
Move the cursor n characters to the left, if possible.
If there are fewer than n characters 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).
sourcepub fn move_cursor_right(&self, n: usize) -> Result<()>
pub fn move_cursor_right(&self, n: usize) -> Result<()>
Move the cursor n characters to the right.
If there are fewer than n characters 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).
sourcepub fn clear_line(&self) -> Result<()>
pub fn clear_line(&self) -> Result<()>
Clear the current line.
Position the cursor at the beginning of the current line.
sourcepub fn clear_last_lines(&self, n: usize) -> Result<()>
pub fn clear_last_lines(&self, n: usize) -> Result<()>
Clear the last n lines before the current line.
Position the cursor at the beginning of the first line that was cleared.
sourcepub fn clear_screen(&self) -> Result<()>
pub fn clear_screen(&self) -> Result<()>
Clear the entire screen.
Move the cursor to the upper left corner of the screen.
sourcepub fn clear_to_end_of_screen(&self) -> Result<()>
pub 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.
sourcepub fn clear_chars(&self, n: usize) -> Result<()>
pub fn clear_chars(&self, n: usize) -> Result<()>
Clear the last n characters of the current line.
sourcepub fn show_cursor(&self) -> Result<()>
pub fn show_cursor(&self) -> Result<()>
Make the cursor visible again.
sourcepub fn hide_cursor(&self) -> Result<()>
pub fn hide_cursor(&self) -> Result<()>
Hide the cursor.
Trait Implementations
sourceimpl<'a> Read for &'a Term
impl<'a> Read for &'a Term
sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · sourcefn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moresourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · sourcefn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
buf. Read more1.0.0 · sourcefn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moresourcefn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)sourcefn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · sourcefn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Read. Read moresourceimpl Read for Term
impl Read for Term
sourcefn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · sourcefn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moresourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · sourcefn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
buf. Read more1.0.0 · sourcefn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moresourcefn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)sourcefn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · sourcefn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Read. Read moresourceimpl<'a> Write for &'a Term
impl<'a> Write for &'a Term
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · sourcefn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
sourcefn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)sourceimpl Write for Term
impl Write for Term
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector)1.0.0 · sourcefn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
sourcefn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored)