pub struct Terminal(_);
Expand description

Provides concurrent read and write access to a terminal device

Concurrency

Access to read and write operations is controlled by two internal locks: One for reading and one for writing. Each lock may be held independently of the other.

If any one thread wishes to hold both locks, the read lock must be acquired first, in order to prevent deadlocks.

Implementations

Opens a new interface to the terminal on stdout.

Opens a new interface to the terminal on stderr.

Returns the name of the terminal.

Notes

On Unix, this method returns the contents of the TERM environment variable.

On Windows, this method always returns the string "windows-console".

Attempts to acquire an exclusive lock on terminal read operations.

The current thread will block until the lock can be acquired.

Attempts to acquire an exclusive lock on terminal write operations.

The current thread will block until the lock can be acquired.

Attempts to acquire an exclusive lock on terminal read operations.

If the lock cannot be acquired immediately, Err(_) is returned.

Attempts to acquire an exclusive lock on terminal write operations.

If the lock cannot be acquired immediately, Err(_) is returned.

Locking

The following methods internally acquire both the read and write locks.

The locks are released before the method returns.

These methods are also implemented on TerminalReadGuard, which holds the Terminal read lock until the value is dropped.

Prepares the terminal to read input.

When reading operations have concluded, restore should be called with the resulting PrepareState value to restore the terminal to its previous state.

This method may be called more than once before a corresponding restore call. However, each restore call must receive the most recently created PrepareState value.

See PrepareConfig for details.

Restores the terminal to its previous state.

Locking

The following methods internally acquire the read lock.

The lock is released before the method returns.

These methods are also implemented on TerminalReadGuard, which holds the Terminal read lock until the value is dropped.

Waits for an event from the terminal.

Returns Ok(false) if timeout elapses without an event occurring.

If timeout is None, this method will wait indefinitely.

Waits for input and reads an event from the terminal.

Returns Ok(None) if timeout elapses without an event occurring.

If timeout is None, this method will wait indefinitely.

Locking

The following methods internally acquire the write lock.

The lock is released before the method returns.

These methods are also implemented on TerminalWriteGuard, which holds the Terminal write lock until the value is dropped.

Returns the size of the terminal.

Clears the terminal screen, placing the cursor at the first line and column.

If the terminal contains a scrolling window over a buffer, the window will be scrolled downward, preserving as much of the existing buffer as possible.

Clears the current line, starting at cursor position.

Clears the screen, starting at cursor position.

Moves the cursor up n lines.

Moves the cursor down n lines.

Moves the cursor left n columns.

Moves the cursor right n columns.

Moves the cursor to the first column of the current line

Set the current cursor mode.

This setting is a visible hint to the user. It produces no change in behavior.

Notes

On some systems, this setting may have no effect.

Adds a set of Style flags to the current style setting.

Removes a set of Style flags from the current style setting.

Sets the current style to the given set of flags.

Sets all attributes for the terminal.

Sets the foreground text color.

Sets the background text color.

Removes color and style attributes.

Adds bold to the current style setting.

This is equivalent to self.add_style(Style::BOLD).

Adds italic to the current style setting.

This is equivalent to self.add_style(Style::ITALIC).

Adds underline to the current style setting.

This is equivalent to self.add_style(Style::UNDERLINE).

Adds reverse to the current style setting.

This is equivalent to self.add_style(Style::REVERSE).

Writes output to the terminal with the given color and style.

All attributes are removed after the given text is written.

Writes a single character to the terminal using the current style and color settings.

Writes a string to the terminal using the current style and color settings.

Writes formatted text to the terminal using the current style and color settings.

This method enables Terminal to be used as the receiver to the write! and writeln! macros.

Examples
let term = Terminal::new()?;

writeln!(term, "Hello, world!")?;

Trait Implementations

Opens a terminal interface on the device at the given path. Read more

Reads raw data from the terminal. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.