Skip to main content

Screen

Struct Screen 

Source
pub struct Screen { /* private fields */ }
Expand description

Represents the overall terminal state.

Implementations§

Source§

impl Screen

Source

pub fn set_size(&mut self, rows: u16, cols: u16)

Resizes the terminal.

Source

pub fn size(&self) -> (u16, u16)

Returns the current size of the terminal.

The return value will be (rows, cols).

Source

pub fn scrollback_len(&self) -> usize

Returns the number of lines in the scrollback.

Source

pub fn set_scrollback(&mut self, rows: usize)

Scrolls to the given position in the scrollback.

This position indicates the offset from the top of the screen, and should be 0 to put the normal screen in view.

This affects the return values of methods called on the screen: for instance, screen.cell(0, 0) will return the top left corner of the screen after taking the scrollback offset into account.

The value given will be clamped to the actual size of the scrollback.

Source

pub fn scrollback(&self) -> usize

Returns the current position in the scrollback.

This position indicates the offset from the top of the screen, and is 0 when the normal screen is in view.

Source

pub fn contents(&self) -> String

Returns the text contents of the terminal.

This will not include any formatting information, and will be in plain text format.

Source

pub fn rows(&self, start: u16, width: u16) -> impl Iterator<Item = String> + '_

Returns the text contents of the terminal by row, restricted to the given subset of columns.

This will not include any formatting information, and will be in plain text format.

Newlines will not be included.

Source

pub fn contents_between( &self, start_row: u16, start_col: u16, end_row: u16, end_col: u16, ) -> String

Returns the text contents of the terminal logically between two cells. This will include the remainder of the starting row after start_col, followed by the entire contents of the rows between start_row and end_row, followed by the beginning of the end_row up until end_col. This is useful for things like determining the contents of a clipboard selection.

Source

pub fn state_formatted(&self) -> Vec<u8>

Return escape codes sufficient to reproduce the entire contents of the current terminal state. This is a convenience wrapper around contents_formatted and input_mode_formatted.

Source

pub fn state_diff(&self, prev: &Self) -> Vec<u8>

Return escape codes sufficient to turn the terminal state of the screen prev into the current terminal state. This is a convenience wrapper around contents_diff and input_mode_diff.

Source

pub fn contents_formatted(&self) -> Vec<u8>

Returns the formatted visible contents of the terminal.

Formatting information will be included inline as terminal escape codes. The result will be suitable for feeding directly to a raw terminal parser, and will result in the same visual output.

Source

pub fn rows_formatted( &self, start: u16, width: u16, ) -> impl Iterator<Item = Vec<u8>> + '_

Returns the formatted visible contents of the terminal by row, restricted to the given subset of columns.

Formatting information will be included inline as terminal escape codes. The result will be suitable for feeding directly to a raw terminal parser, and will result in the same visual output.

You are responsible for positioning the cursor before printing each row, and the final cursor position after displaying each row is unspecified.

Source

pub fn contents_diff(&self, prev: &Self) -> Vec<u8>

Returns a terminal byte stream sufficient to turn the visible contents of the screen described by prev into the visible contents of the screen described by self.

The result of rendering prev.contents_formatted() followed by self.contents_diff(prev) should be equivalent to the result of rendering self.contents_formatted(). This is primarily useful when you already have a terminal parser whose state is described by prev, since the diff will likely require less memory and cause less flickering than redrawing the entire screen contents.

Source

pub fn rows_diff<'a>( &'a self, prev: &'a Self, start: u16, width: u16, ) -> impl Iterator<Item = Vec<u8>> + 'a

Returns a sequence of terminal byte streams sufficient to turn the visible contents of the subset of each row from prev (as described by start and width) into the visible contents of the corresponding row subset in self.

You are responsible for positioning the cursor before printing each row, and the final cursor position after displaying each row is unspecified.

Source

pub fn input_mode_formatted(&self) -> Vec<u8>

Returns terminal escape sequences sufficient to set the current terminal’s input modes.

Supported modes are:

  • application keypad
  • application cursor
  • bracketed paste
  • xterm mouse support
Source

pub fn input_mode_diff(&self, prev: &Self) -> Vec<u8>

Returns terminal escape sequences sufficient to change the previous terminal’s input modes to the input modes enabled in the current terminal.

Source

pub fn attributes_formatted(&self) -> Vec<u8>

Returns terminal escape sequences sufficient to set the current terminal’s drawing attributes.

Supported drawing attributes are:

  • fgcolor
  • bgcolor
  • bold
  • dim
  • italic
  • underline
  • inverse

This is not typically necessary, since contents_formatted will leave the current active drawing attributes in the correct state, but this can be useful in the case of drawing additional things on top of a terminal output, since you will need to restore the terminal state without the terminal contents necessarily being the same.

Source

pub fn cursor_position(&self) -> (u16, u16)

Returns the current cursor position of the terminal.

The return value will be (row, col).

Source

pub fn cursor_state_formatted(&self) -> Vec<u8>

Returns terminal escape sequences sufficient to set the current cursor state of the terminal.

This is not typically necessary, since contents_formatted will leave the cursor in the correct state, but this can be useful in the case of drawing additional things on top of a terminal output, since you will need to restore the terminal state without the terminal contents necessarily being the same.

Note that the bytes returned by this function may alter the active drawing attributes, because it may require redrawing existing cells in order to position the cursor correctly (for instance, in the case where the cursor is past the end of a row). Therefore, you should ensure to reset the active drawing attributes if necessary after processing this data, for instance by using attributes_formatted.

Source

pub fn cell(&self, row: u16, col: u16) -> Option<&Cell>

Returns the Cell object at the given location in the terminal, if it exists.

Source

pub fn row_wrapped(&self, row: u16) -> bool

Returns whether the text in row row should wrap to the next line.

Source

pub fn alternate_screen(&self) -> bool

Returns whether the alternate screen is currently in use.

Source

pub fn application_keypad(&self) -> bool

Returns whether the terminal should be in application keypad mode.

Source

pub fn application_cursor(&self) -> bool

Returns whether the terminal should be in application cursor mode.

Source

pub fn hide_cursor(&self) -> bool

Returns whether the terminal should be in hide cursor mode.

Source

pub fn bracketed_paste(&self) -> bool

Returns whether the terminal should be in bracketed paste mode.

Source

pub fn mouse_protocol_mode(&self) -> MouseProtocolMode

Returns the currently active MouseProtocolMode.

Source

pub fn mouse_protocol_encoding(&self) -> MouseProtocolEncoding

Returns the currently active MouseProtocolEncoding.

Source

pub fn fgcolor(&self) -> Color

Returns the currently active foreground color.

Source

pub fn bgcolor(&self) -> Color

Returns the currently active background color.

Source

pub fn bold(&self) -> bool

Returns whether newly drawn text should be rendered with the bold text attribute.

Source

pub fn dim(&self) -> bool

Returns whether newly drawn text should be rendered with the dim text attribute.

Source

pub fn italic(&self) -> bool

Returns whether newly drawn text should be rendered with the italic text attribute.

Source

pub fn underline(&self) -> bool

Returns whether newly drawn text should be rendered with the underlined text attribute.

Source

pub fn inverse(&self) -> bool

Returns whether newly drawn text should be rendered with the inverse text attribute.

Trait Implementations§

Source§

impl Clone for Screen

Source§

fn clone(&self) -> Screen

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Screen

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Screen

§

impl RefUnwindSafe for Screen

§

impl Send for Screen

§

impl Sync for Screen

§

impl Unpin for Screen

§

impl UnwindSafe for Screen

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.