Struct vt100::Screen

source ·
pub struct Screen { /* private fields */ }
Expand description

Represents the overall terminal state.

Implementations§

source§

impl Screen

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(&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, input_mode_formatted, and title_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, input_mode_diff, title_diff, and bells_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 title_formatted(&self) -> Vec<u8>

Returns terminal escape sequences sufficient to set the current terminal’s window title.

source

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

Returns terminal escape sequences sufficient to change the previous terminal’s window title to the window title set in the current terminal.

source

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

Returns terminal escape sequences sufficient to cause audible and visual bells to occur if they have been received since the terminal described by prev.

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
  • 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 title(&self) -> &str

Returns the terminal’s window title.

source

pub fn icon_name(&self) -> &str

Returns the terminal’s icon name.

source

pub fn audible_bell_count(&self) -> usize

Returns a value which changes every time an audible bell is received.

Typically you would store this number after each call to process, and trigger an audible bell whenever it changes.

You shouldn’t rely on the exact value returned here, since the exact value will not be maintained by contents_formatted or contents_diff.

source

pub fn visual_bell_count(&self) -> usize

Returns a value which changes every time an visual bell is received.

Typically you would store this number after each call to process, and trigger an visual bell whenever it changes.

You shouldn’t rely on the exact value returned here, since the exact value will not be maintained by contents_formatted or contents_diff.

source

pub fn errors(&self) -> usize

Returns the number of parsing errors seen so far.

Currently this only tracks invalid UTF-8 and control characters other than 0x07-0x0f. This can give an idea of whether the input stream being fed to the parser is reasonable or not.

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 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 copy 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
source§

impl Perform for Screen

source§

fn print(&mut self, c: char)

Draw a character to the screen and update states.
source§

fn execute(&mut self, b: u8)

Execute a C0 or C1 control function.
source§

fn esc_dispatch(&mut self, intermediates: &[u8], _ignore: bool, b: u8)

The final character of an escape sequence has arrived. Read more
source§

fn csi_dispatch(
&mut self,
params: &Params,
intermediates: &[u8],
_ignore: bool,
c: char
)

A final character has arrived for a CSI sequence Read more
source§

fn osc_dispatch(&mut self, params: &[&[u8]], _bel_terminated: bool)

Dispatch an operating system command.
source§

fn hook(
&mut self,
params: &Params,
intermediates: &[u8],
_ignore: bool,
action: char
)

Invoked when a final character arrives in first part of device control string. Read more
source§

fn put(&mut self, _byte: u8)

Pass bytes as part of a device control string to the handle chosen in hook. C0 controls will also be passed to the handler.
source§

fn unhook(&mut self)

Called when a device control string is terminated. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere
T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere
T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere
U: From<T>,

const: unstable · 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 Twhere
T: Clone,

§

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 Twhere
U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere
U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.