Struct Terminal

Source
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

Source

pub fn new() -> Self

Creates a new instance of the Terminal struct, initializing the underlying input and output streams.

Source

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.

Source

pub fn lock_stdout(&self) -> StdoutLock

Locks the standard output stream, allowing for synchronous write operations.

Source

pub fn lock_stderr(&self) -> StderrLock

Locks the standard error stream, allowing for synchronous write operations.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn read_key(&self) -> Key

Reads a single key from the standard input stream. Panics if an error occurs during reading.

Source

pub fn read_string(&self) -> String

Reads a line of text from the standard input stream. Panics if an error occurs during reading.

Trait Implementations§

Source§

impl Debug for Terminal

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Terminal

Source§

fn default() -> Terminal

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.