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§
source§impl Term
impl Term
sourcepub fn buffered_stdout() -> Term ⓘ
pub fn buffered_stdout() -> Term ⓘ
Return a new buffered terminal.
sourcepub fn buffered_stderr() -> Term ⓘ
pub fn buffered_stderr() -> Term ⓘ
Return a new buffered terminal to stderr.
sourcepub fn read_write_pair<R, W>(read: R, write: W) -> Term ⓘ
pub fn read_write_pair<R, W>(read: R, write: W) -> Term ⓘ
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 ⓘ
pub fn read_write_pair_with_style<R, W>(read: R, write: W, style: Style) -> Term ⓘ
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 or complete key chord is entered. If the terminal is not user attended the return value will be an error.
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.
pub fn read_key_raw(&self) -> Result<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 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.
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§
source§impl<'a> Read for &'a Term
impl<'a> Read for &'a Term
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · source§fn 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 moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn 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 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn 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 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresource§impl Read for Term
impl Read for Term
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · source§fn 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 moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn 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 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn 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 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresource§impl<'a> Write for &'a Term
impl<'a> Write for &'a Term
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)source§impl Write for Term
impl Write for Term
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)Auto Trait Implementations§
impl Freeze for Term
impl RefUnwindSafe for Term
impl Send for Term
impl Sync for Term
impl Unpin for Term
impl UnwindSafe for Term
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)