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
sourceimpl Terminal
impl Terminal
sourcepub fn name(&self) -> &str
pub fn name(&self) -> &str
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"
.
sourcepub fn lock_read(&self) -> LockResult<TerminalReadGuard<'_>>
pub fn lock_read(&self) -> LockResult<TerminalReadGuard<'_>>
Attempts to acquire an exclusive lock on terminal read operations.
The current thread will block until the lock can be acquired.
sourcepub fn lock_write(&self) -> LockResult<TerminalWriteGuard<'_>>
pub fn lock_write(&self) -> LockResult<TerminalWriteGuard<'_>>
Attempts to acquire an exclusive lock on terminal write operations.
The current thread will block until the lock can be acquired.
sourcepub fn try_lock_read(&self) -> TryLockResult<TerminalReadGuard<'_>>
pub fn try_lock_read(&self) -> TryLockResult<TerminalReadGuard<'_>>
Attempts to acquire an exclusive lock on terminal read operations.
If the lock cannot be acquired immediately, Err(_)
is returned.
sourcepub fn try_lock_write(&self) -> TryLockResult<TerminalWriteGuard<'_>>
pub fn try_lock_write(&self) -> TryLockResult<TerminalWriteGuard<'_>>
Attempts to acquire an exclusive lock on terminal write operations.
If the lock cannot be acquired immediately, Err(_)
is returned.
sourceimpl Terminal
impl Terminal
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.
sourcepub fn prepare(&self, config: PrepareConfig) -> Result<PrepareState>
pub fn prepare(&self, config: PrepareConfig) -> Result<PrepareState>
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.
sourcepub fn restore(&self, state: PrepareState) -> Result<()>
pub fn restore(&self, state: PrepareState) -> Result<()>
Restores the terminal to its previous state.
sourceimpl Terminal
impl Terminal
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.
sourceimpl Terminal
impl Terminal
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.
sourcepub fn clear_screen(&self) -> Result<()>
pub fn clear_screen(&self) -> Result<()>
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.
sourcepub fn clear_to_line_end(&self) -> Result<()>
pub fn clear_to_line_end(&self) -> Result<()>
Clears the current line, starting at cursor position.
sourcepub fn clear_to_screen_end(&self) -> Result<()>
pub fn clear_to_screen_end(&self) -> Result<()>
Clears the screen, starting at cursor position.
sourcepub fn move_right(&self, n: usize) -> Result<()>
pub fn move_right(&self, n: usize) -> Result<()>
Moves the cursor right n
columns.
sourcepub fn move_to_first_column(&self) -> Result<()>
pub fn move_to_first_column(&self) -> Result<()>
Moves the cursor to the first column of the current line
sourcepub fn set_cursor_mode(&self, mode: CursorMode) -> Result<()>
pub fn set_cursor_mode(&self, mode: CursorMode) -> Result<()>
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.
sourcepub fn add_style(&self, style: Style) -> Result<()>
pub fn add_style(&self, style: Style) -> Result<()>
Adds a set of Style
flags to the current style setting.
sourcepub fn remove_style(&self, style: Style) -> Result<()>
pub fn remove_style(&self, style: Style) -> Result<()>
Removes a set of Style
flags from the current style setting.
sourcepub fn set_style<S>(&self, style: S) -> Result<()> where
S: Into<Option<Style>>,
pub fn set_style<S>(&self, style: S) -> Result<()> where
S: Into<Option<Style>>,
Sets the current style to the given set of flags.
sourcepub fn set_fg<C: Into<Option<Color>>>(&self, fg: C) -> Result<()>
pub fn set_fg<C: Into<Option<Color>>>(&self, fg: C) -> Result<()>
Sets the foreground text color.
sourcepub fn set_bg<C: Into<Option<Color>>>(&self, bg: C) -> Result<()>
pub fn set_bg<C: Into<Option<Color>>>(&self, bg: C) -> Result<()>
Sets the background text color.
sourcepub fn clear_attributes(&self) -> Result<()>
pub fn clear_attributes(&self) -> Result<()>
Removes color and style attributes.
sourcepub fn bold(&self) -> Result<()>
pub fn bold(&self) -> Result<()>
Adds bold to the current style setting.
This is equivalent to self.add_style(Style::BOLD)
.
sourcepub fn italic(&self) -> Result<()>
pub fn italic(&self) -> Result<()>
Adds italic to the current style setting.
This is equivalent to self.add_style(Style::ITALIC)
.
sourcepub fn underline(&self) -> Result<()>
pub fn underline(&self) -> Result<()>
Adds underline to the current style setting.
This is equivalent to self.add_style(Style::UNDERLINE)
.
sourcepub fn reverse(&self) -> Result<()>
pub fn reverse(&self) -> Result<()>
Adds reverse to the current style setting.
This is equivalent to self.add_style(Style::REVERSE)
.
sourcepub fn write_styled<F, B, S>(
&self,
fg: F,
bg: B,
style: S,
s: &str
) -> Result<()> where
F: Into<Option<Color>>,
B: Into<Option<Color>>,
S: Into<Option<Style>>,
pub fn write_styled<F, B, S>(
&self,
fg: F,
bg: B,
style: S,
s: &str
) -> Result<()> where
F: Into<Option<Color>>,
B: Into<Option<Color>>,
S: Into<Option<Style>>,
Writes output to the terminal with the given color and style.
All attributes are removed after the given text is written.
sourcepub fn write_char(&self, ch: char) -> Result<()>
pub fn write_char(&self, ch: char) -> Result<()>
Writes a single character to the terminal using the current style and color settings.
sourcepub fn write_str(&self, s: &str) -> Result<()>
pub fn write_str(&self, s: &str) -> Result<()>
Writes a string to the terminal using the current style and color settings.
Trait Implementations
sourceimpl OpenTerminalExt for Terminal
impl OpenTerminalExt for Terminal
Auto Trait Implementations
impl RefUnwindSafe for Terminal
impl Send for Terminal
impl Sync for Terminal
impl Unpin for Terminal
impl UnwindSafe for Terminal
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