pub struct Terminal { /* private fields */ }
Expand description
A struct representing the terminal interface for input and output operations. Only simple operations are enabled; lock the respective stream for more methods.
Implementations§
Source§impl Terminal
impl Terminal
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new instance of the Terminal
struct, initializing the underlying input and output streams.
Sourcepub fn lock_stdin(&self) -> Option<StdinLock>
pub fn lock_stdin(&self) -> Option<StdinLock>
Locks the standard input stream, allowing for synchronous read operations.
Returns [Some(StdinLock)
] if successful, or None
if locking the stream fails.
Sourcepub fn lock_stdout(&self) -> StdoutLock
pub fn lock_stdout(&self) -> StdoutLock
Locks the standard output stream, allowing for synchronous write operations.
Sourcepub fn lock_stderr(&self) -> StderrLock
pub fn lock_stderr(&self) -> StderrLock
Locks the standard error stream, allowing for synchronous write operations.
Sourcepub fn print(&self, target: Target, str: &str)
pub fn print(&self, target: Target, str: &str)
Prints a string to the specified target stream.
If the target is Target::Stderr
, the string is printed to the standard error stream.
If the target is Target::Stdout
, the string is printed to the standard output stream.
Panics if an error occurs during writing.
Sourcepub fn println(&self, target: Target, str: &str)
pub fn println(&self, target: Target, str: &str)
Prints a string followed by a newline to the specified target stream.
If the target is Target::Stderr
, the string is printed to the standard error stream.
If the target is Target::Stdout
, the string is printed to the standard output stream.
Panics if an error occurs during writing.
Sourcepub fn clear(&self)
pub fn clear(&self)
Clears the screen by sending an escape sequence. This function sends the escape sequence to clear the entire screen. It moves the cursor to the top-left corner of the terminal. Panics if an error occurs during writing.
Sourcepub fn hide(&self)
pub fn hide(&self)
Hides the cursor in the terminal. This function sends the escape sequence to hide the cursor in the terminal. Panics if an error occurs during writing.
Sourcepub fn show(&self)
pub fn show(&self)
Shows the cursor in the terminal. This function sends the escape sequence to show the cursor in the terminal. Panics if an error occurs during writing.
Sourcepub fn read_key(&self) -> Key
pub fn read_key(&self) -> Key
Reads a single key from the standard input stream. Panics if an error occurs during reading.
Sourcepub fn read_string(&self) -> String
pub fn read_string(&self) -> String
Reads a line of text from the standard input stream. Panics if an error occurs during reading.