Skip to main content

Screen

Struct Screen 

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

A double-buffered screen of cells.

The screen tracks the current state of every cell. When rendering, the diff from the previous frame determines which cells need updating. This avoids redrawing the entire screen on every frame.

Implementations§

Source§

impl Screen

Source

pub fn new(width: u16, height: u16) -> Self

Create a new screen with the given dimensions, filled with default cells.

Source

pub fn resize(&mut self, width: u16, height: u16)

Resize the screen, clearing all content.

Source

pub fn clear(&mut self)

Clear the entire screen to default cells.

Source

pub fn width(&self) -> u16

Get the screen width in columns.

Source

pub fn height(&self) -> u16

Get the screen height in rows.

Source

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

Get a cell at the given position. Returns None if out of bounds.

Source

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

Get a mutable cell at the given position. Returns None if out of bounds.

Source

pub fn set_cell(&mut self, row: u16, col: u16, cell: Cell)

Set a cell at the given position. Does nothing if out of bounds.

Source

pub fn write_str( &mut self, row: u16, col: u16, text: &str, fg: Color, bg: Color, style: Style, )

Write a string starting at the given position, with the given style.

Characters that exceed the screen width are truncated.

Source

pub fn write_str_wrapped( &mut self, start_row: u16, start_col: u16, text: &str, fg: Color, bg: Color, style: Style, wrap: bool, ) -> u16

Write a string starting at the given position, truncating or wrapping.

If wrap is true, text wraps to the next line. If false, text is truncated at the right edge.

Source

pub fn write_str_wrapped_clipped( &mut self, start_row: u16, start_col: u16, text: &str, fg: Color, bg: Color, style: Style, left_margin: u16, max_row: u16, wrap_col: u16, ) -> u16

Write a string with wrapping, but clip rendering at the given maximum row and wrap at the given column.

wrap_col is the maximum column number; text wraps when col >= wrap_col. max_row is the maximum row; text stops when row > max_row. left_margin is the column where wrapped lines start.

Source

pub fn write_str_wrapped_skip_clipped( &mut self, start_row: u16, start_col: u16, text: &str, fg: Color, bg: Color, style: Style, left_margin: u16, max_row: u16, wrap_col: u16, skip_rows: usize, )

Write a string with wrapping, skip the first skip_rows visual rows, and clip rendering at the given maximum row and wrap column.

wrap_col is the maximum column number; text wraps when col >= wrap_col. skip_rows is the number of visual rows to skip before rendering. max_row is the maximum row; text stops when row > max_row. left_margin is the column where wrapped lines start.

Source

pub fn fill_rect(&mut self, rect: Rect, cell: Cell)

Fill a rectangular area with the given cell.

Source

pub fn hline( &mut self, row: u16, col_start: u16, col_end: u16, ch: char, fg: Color, bg: Color, )

Draw a horizontal line using the given character.

Source

pub fn vline( &mut self, col: u16, row_start: u16, row_end: u16, ch: char, fg: Color, bg: Color, )

Draw a vertical line using the given character.

Source

pub fn draw_box(&mut self, rect: Rect, fg: Color, bg: Color, style: Style)

Draw a box (border) around a rectangular area.

Source

pub fn diff_from(&self, previous: &Screen) -> Vec<DiffOp>

Compute the diff between this screen and a previous frame.

Returns a list of DiffOp entries that, when applied in order, will bring the terminal from the previous state to the current state.

Source

pub fn render_diff(ops: &[DiffOp], width: u16) -> String

Render a list of diff operations to an ANSI escape sequence string.

This is the core of the efficient rendering: we only write cells that actually changed, and we batch cursor movements.

Trait Implementations§

Source§

impl Clone for Screen

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more