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 Term
where
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 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.
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 Term
where
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 Term
where
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
Returns the target
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_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 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 features(&self) -> TermFeatures<'_>
pub fn features(&self) -> TermFeatures<'_>
Checks for common terminal features.
sourcepub fn size(&self) -> (u16, u16)
pub fn size(&self) -> (u16, u16)
Returns 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)>
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 move_cursor_left(&self, n: usize) -> Result<()>
pub fn move_cursor_left(&self, n: usize) -> Result<()>
Moves the cursor left n
lines
sourcepub fn move_cursor_right(&self, n: usize) -> Result<()>
pub fn move_cursor_right(&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.
sourcepub fn clear_screen(&self) -> Result<()>
pub fn clear_screen(&self) -> Result<()>
Clears the entire screen.
sourcepub fn clear_to_end_of_screen(&self) -> Result<()>
pub fn clear_to_end_of_screen(&self) -> Result<()>
Clears the entire screen.
sourcepub fn clear_chars(&self, n: usize) -> Result<()>
pub fn clear_chars(&self, n: usize) -> Result<()>
Clears the last char in the the current line.
sourcepub fn show_cursor(&self) -> Result<()>
pub fn show_cursor(&self) -> Result<()>
Makes cursor visible again
sourcepub fn hide_cursor(&self) -> Result<()>
pub fn hide_cursor(&self) -> Result<()>
Hides 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>
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
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>
Like read
, except that it reads into a slice of buffers. Read more
sourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
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>
Read all bytes until EOF in this source, placing them into buf
. Read more
1.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>
Read all bytes until EOF in this source, appending them to buf
. Read more
1.6.0 · sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Read the exact number of bytes required to fill buf
. Read more
sourcefn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
read_buf
)Pull some bytes from this source into the specified buffer. Read more
sourcefn read_buf_exact(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
read_buf
)Read the exact number of bytes required to fill buf
. Read more
1.0.0 · sourcefn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Creates a “by reference” adaptor for this instance of Read
. Read more
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>
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
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>
Like read
, except that it reads into a slice of buffers. Read more
sourcefn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
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>
Read all bytes until EOF in this source, placing them into buf
. Read more
1.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>
Read all bytes until EOF in this source, appending them to buf
. Read more
1.6.0 · sourcefn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
Read the exact number of bytes required to fill buf
. Read more
sourcefn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
read_buf
)Pull some bytes from this source into the specified buffer. Read more
sourcefn read_buf_exact(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, buf: &mut ReadBuf<'_>) -> Result<(), Error>
read_buf
)Read the exact number of bytes required to fill buf
. Read more
1.0.0 · sourcefn by_ref(&mut self) -> &mut Self
fn by_ref(&mut self) -> &mut Self
Creates a “by reference” adaptor for this instance of Read
. Read more
sourceimpl<'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>
Write a buffer into this writer, returning how many bytes were written. Read more
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
1.0.0 · sourcefn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
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
)Attempts to write multiple buffers into this writer. Read more
sourceimpl Write for Term
impl Write for Term
sourcefn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this writer, returning how many bytes were written. Read more
sourcefn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
sourcefn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
1.0.0 · sourcefn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
Attempts to write an entire buffer into this writer. Read more
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
)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations
impl RefUnwindSafe for Term
impl Send for Term
impl Sync for Term
impl Unpin for Term
impl UnwindSafe for Term
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more