[−][src]Struct mortal::screen::Screen
Provides operations on an underlying terminal device in screen mode.
Screen
uses an internal buffer to store rendered text, colors, and style.
Each set of changes must be followed by a call to refresh
to flush these
changes to the 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 Screen
[src]
pub fn new(config: PrepareConfig) -> Result<Screen>
[src]
Opens a new screen interface on stdout
.
pub fn stderr(config: PrepareConfig) -> Result<Screen>
[src]
Opens a new screen interface on stderr
.
pub fn with_terminal(term: Terminal, config: PrepareConfig) -> Result<Screen>
[src]
Begins a new screen session using the given Terminal
instance.
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<ScreenReadGuard>
[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<ScreenWriteGuard>
[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<ScreenReadGuard>
[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<ScreenWriteGuard>
[src]
Attempts to acquire an exclusive lock on terminal write operations.
If the lock cannot be acquired immediately, Err(_)
is returned.
impl Screen
[src]
Locking
The following methods internally acquire the read lock.
The lock is released before the method returns.
These methods are also implemented on ScreenReadGuard
,
which holds the Screen
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.
Notes
Some low-level terminal events may not generate an Event
value.
Therefore, this method may return Ok(true)
, while a follow-up call
to read_event
may not immediately return an event.
pub fn read_event(&self, timeout: Option<Duration>) -> Result<Option<Event>>
[src]
Reads an event from the terminal.
If timeout
elapses without an event occurring, this method will return
Ok(None)
.
If timeout
is None
, this method will wait indefinitely.
impl Screen
[src]
Locking
The following methods internally acquire the write lock.
The lock is released before the method returns.
These methods are also implemented on ScreenWriteGuard
,
which holds the Screen
write lock until the value is dropped.
pub fn size(&self) -> Size
[src]
Returns the current size of the terminal screen.
pub fn cursor(&self) -> Cursor
[src]
Returns the current cursor position.
pub fn set_cursor<C: Into<Cursor>>(&self, pos: C)
[src]
Sets the cursor position.
pub fn next_line(&self, column: usize)
[src]
Moves the cursor to the given column on the next 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 Unix systems, this setting may have no effect.
pub fn clear_screen(&self)
[src]
Clears the internal screen buffer.
pub fn add_style(&self, style: Style)
[src]
Adds a set of Style
flags to the current style setting.
pub fn remove_style(&self, style: Style)
[src]
Removes a set of Style
flags to the current style setting.
pub fn set_style<S: Into<Option<Style>>>(&self, style: S)
[src]
Sets the current style setting to the given set of flags.
pub fn set_fg<C: Into<Option<Color>>>(&self, fg: C)
[src]
Sets or removes foreground text color.
pub fn set_bg<C: Into<Option<Color>>>(&self, bg: C)
[src]
Sets or removes background text color.
pub fn set_theme(&self, theme: Theme)
[src]
Sets all attributes for the screen.
pub fn clear_attributes(&self)
[src]
Removes color and style attributes.
pub fn bold(&self)
[src]
Adds bold to the current style setting.
This is equivalent to self.add_style(Style::BOLD)
.
pub fn italic(&self)
[src]
Adds italic to the current style setting.
This is equivalent to self.add_style(Style::ITALIC)
.
pub fn underline(&self)
[src]
Adds underline to the current style setting.
This is equivalent to self.add_style(Style::UNDERLINE)
.
pub fn reverse(&self)
[src]
Adds reverse to the current style setting.
This is equivalent to self.add_style(Style::REVERSE)
.
pub fn refresh(&self) -> Result<()>
[src]
Renders the internal buffer to the terminal screen.
pub fn write_at<C>(&self, position: C, text: &str) where
C: Into<Cursor>,
[src]
C: Into<Cursor>,
Writes text at the given position within the screen buffer.
Any non-printable characters, such as escape sequences, will be ignored.
pub fn write_styled<F, B, S>(&self, fg: F, bg: B, style: S, text: &str) where
F: Into<Option<Color>>,
B: Into<Option<Color>>,
S: Into<Option<Style>>,
[src]
F: Into<Option<Color>>,
B: Into<Option<Color>>,
S: Into<Option<Style>>,
Writes text with the given attributes at the current cursor position.
Any non-printable characters, such as escape sequences, will be ignored.
pub fn write_styled_at<C, F, B, S>(
&self,
position: C,
fg: F,
bg: B,
style: S,
text: &str
) where
C: Into<Cursor>,
F: Into<Option<Color>>,
B: Into<Option<Color>>,
S: Into<Option<Style>>,
[src]
&self,
position: C,
fg: F,
bg: B,
style: S,
text: &str
) where
C: Into<Cursor>,
F: Into<Option<Color>>,
B: Into<Option<Color>>,
S: Into<Option<Style>>,
Writes text with the given attributes at the given position within the screen buffer.
Any non-printable characters, such as escape sequences, will be ignored.
pub fn write_char(&self, ch: char)
[src]
Writes a single character at the cursor position using the current style and color settings.
If the character is a non-printable character, it will be ignored.
pub fn write_str(&self, s: &str)
[src]
Writes a string at the cursor position using the current style and color settings.
Any non-printable characters, such as escape sequences, will be ignored.
pub fn write_fmt(&self, args: Arguments)
[src]
Writes formatted text at the cursor position using the current style and color settings.
This method enables Screen
to be used as the receiver to
the write!
and writeln!
macros.
Any non-printable characters, such as escape sequences, will be ignored.
Examples
let screen = Screen::new(Default::default())?; writeln!(screen, "Hello, world!");
Trait Implementations
impl TerminalExt for Screen
[src]
Auto Trait Implementations
impl RefUnwindSafe for Screen
impl Send for Screen
impl Sync for Screen
impl Unpin for Screen
impl UnwindSafe for Screen
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,