[][src]Struct mortal::terminal::Terminal

pub struct Terminal(_);

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.

Methods

impl Terminal[src]

pub fn new() -> Result<Terminal>[src]

Opens a new interface to the terminal on stdout.

pub fn stderr() -> Result<Terminal>[src]

Opens a new interface to the terminal on stderr.

pub fn name(&self) -> &str[src]

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".

pub fn lock_read(&self) -> LockResult<TerminalReadGuard>[src]

Attempts to acquire an exclusive lock on terminal read operations.

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

pub fn lock_write(&self) -> LockResult<TerminalWriteGuard>[src]

Attempts to acquire an exclusive lock on terminal write operations.

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

pub fn try_lock_read(&self) -> TryLockResult<TerminalReadGuard>[src]

Attempts to acquire an exclusive lock on terminal read operations.

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

pub fn try_lock_write(&self) -> TryLockResult<TerminalWriteGuard>[src]

Attempts to acquire an exclusive lock on terminal write operations.

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

impl Terminal[src]

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.

pub fn prepare(&self, config: PrepareConfig) -> Result<PrepareState>[src]

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.

pub fn restore(&self, state: PrepareState) -> Result<()>[src]

Restores the terminal to its previous state.

impl Terminal[src]

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.

pub fn wait_event(&self, timeout: Option<Duration>) -> Result<bool>[src]

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.

pub fn read_event(&self, timeout: Option<Duration>) -> Result<Option<Event>>[src]

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.

impl Terminal[src]

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.

pub fn size(&self) -> Result<Size>[src]

Returns the size of the terminal.

pub fn clear_screen(&self) -> Result<()>[src]

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.

pub fn clear_to_line_end(&self) -> Result<()>[src]

Clears the current line, starting at cursor position.

pub fn clear_to_screen_end(&self) -> Result<()>[src]

Clears the screen, starting at cursor position.

pub fn move_up(&self, n: usize) -> Result<()>[src]

Moves the cursor up n lines.

pub fn move_down(&self, n: usize) -> Result<()>[src]

Moves the cursor down n lines.

pub fn move_left(&self, n: usize) -> Result<()>[src]

Moves the cursor left n columns.

pub fn move_right(&self, n: usize) -> Result<()>[src]

Moves the cursor right n columns.

pub fn move_to_first_column(&self) -> Result<()>[src]

Moves the cursor to the first column of the current line

pub fn set_cursor_mode(&self, mode: CursorMode) -> Result<()>[src]

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.

pub fn add_style(&self, style: Style) -> Result<()>[src]

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

pub fn remove_style(&self, style: Style) -> Result<()>[src]

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

pub fn set_style<S>(&self, style: S) -> Result<()> where
    S: Into<Option<Style>>, 
[src]

Sets the current style to the given set of flags.

pub fn set_theme(&self, theme: Theme) -> Result<()>[src]

Sets all attributes for the terminal.

pub fn set_fg<C: Into<Option<Color>>>(&self, fg: C) -> Result<()>[src]

Sets the foreground text color.

pub fn set_bg<C: Into<Option<Color>>>(&self, bg: C) -> Result<()>[src]

Sets the background text color.

pub fn clear_attributes(&self) -> Result<()>[src]

Removes color and style attributes.

pub fn bold(&self) -> Result<()>[src]

Adds bold to the current style setting.

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

pub fn italic(&self) -> Result<()>[src]

Adds italic to the current style setting.

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

pub fn underline(&self) -> Result<()>[src]

Adds underline to the current style setting.

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

pub fn reverse(&self) -> Result<()>[src]

Adds reverse to the current style setting.

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

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>>, 
[src]

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

All attributes are removed after the given text is written.

pub fn write_char(&self, ch: char) -> Result<()>[src]

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

pub fn write_str(&self, s: &str) -> Result<()>[src]

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

pub fn write_fmt(&self, args: Arguments) -> Result<()>[src]

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

impl OpenTerminalExt for Terminal[src]

impl TerminalExt for Terminal[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.