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 Read for Term
pub fn stdout() -> TermⓘNotable traits for Termimpl Write for Termimpl Read for Term
Return a new unbuffered terminal
sourcepub fn stderr() -> TermⓘNotable traits for Termimpl Write for Termimpl Read for Term
pub fn stderr() -> TermⓘNotable traits for Termimpl Write for Termimpl Read for Term
Return a new unbuffered terminal to stderr
sourcepub fn buffered_stdout() -> TermⓘNotable traits for Termimpl Write for Termimpl Read for Term
pub fn buffered_stdout() -> TermⓘNotable traits for Termimpl Write for Termimpl Read for Term
Return a new buffered terminal
sourcepub fn buffered_stderr() -> TermⓘNotable traits for Termimpl Write for Termimpl Read for Term
pub fn buffered_stderr() -> TermⓘNotable traits for Termimpl Write for Termimpl Read for Term
Return a new buffered terminal to stderr
sourcepub fn target(&self) -> TermTarget
pub fn target(&self) -> TermTarget
Returns the targert
sourcepub fn write_line(&self, s: &str) -> Result<()>
pub fn write_line(&self, s: &str) -> Result<()>
Writes a string to the terminal and adds 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_secure_line(&self) -> Result<String>
pub fn read_secure_line(&self) -> Result<String>
Read securely a line of input.
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<()>
Flushes 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 is_term(&self) -> bool
pub fn is_term(&self) -> bool
Checks if the terminal is indeed a terminal.
This is a shortcut for features().is_attended()
.
sourcepub fn features(&self) -> TermFeatures<'_>
pub fn features(&self) -> TermFeatures<'_>
Checks for common terminal features.
sourcepub fn want_emoji(&self) -> bool
👎Deprecated since 0.8.0: Use features().wants_emoji() instead
pub fn want_emoji(&self) -> bool
Checks if this terminal wants emoji output.
sourcepub fn size_checked(&self) -> Option<(u16, u16)>
pub fn size_checked(&self) -> Option<(u16, u16)>
Returns the terminal size in rows and columns.
If the size cannot be reliably determined None is returned.
sourcepub fn move_cursor_up(&self, n: usize) -> Result<()>
pub fn move_cursor_up(&self, n: usize) -> Result<()>
Moves the cursor up n
lines
sourcepub fn move_cursor_down(&self, n: usize) -> Result<()>
pub fn move_cursor_down(&self, n: usize) -> Result<()>
Moves the cursor down n
lines
sourcepub fn clear_line(&self) -> Result<()>
pub fn clear_line(&self) -> Result<()>
Clears the current line.
The positions the cursor at the beginning of the line again.
sourcepub fn clear_last_lines(&self, n: usize) -> Result<()>
pub fn clear_last_lines(&self, n: usize) -> Result<()>
Clear the last n
lines.
This positions the cursor at the beginning of the first line that was cleared.
Trait Implementations
sourceimpl 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 Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresourceimpl 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
)