Skip to main content

Screen

Struct Screen 

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

A rows x cols grid of Cells plus a Cursor, both 0-based.

Implementations§

Source§

impl Screen

Source

pub fn new(rows: usize, cols: usize) -> Self

A blank screen (all default cells, cursor at the origin).

Source

pub fn rows(&self) -> usize

Source

pub fn cols(&self) -> usize

Source

pub fn cursor(&self) -> Cursor

Where the cursor rests after rendering.

Source

pub fn set_cursor(&mut self, cursor: Cursor)

Move the cursor, clamped onto the grid: a row or column past the edge lands on the last row or column (the origin on an empty screen). The renderers park the terminal cursor here.

Source

pub fn clear(&mut self)

Reset all cells to default and the cursor to the origin, reusing the existing allocation. The caller must ensure the screen is already the right size; use Screen::new when the size changes.

Source

pub fn cell(&self, row: usize, col: usize) -> Cell

The cell at (row, col); out of bounds returns a default cell.

Source

pub fn set(&mut self, row: usize, col: usize, cell: Cell)

Set one cell. Out-of-bounds writes are ignored.

Source

pub fn write_str(&mut self, row: usize, col: usize, text: &str, style: Style)

Write a string across a row starting at (row, col), truncating at the right edge. Each char takes one cell (single-width); callers that need double-width layout use Cell::wide with Screen::set or Screen::copy_cells.

Source

pub fn copy_cells(&mut self, row: usize, col: usize, cells: &[Cell])

Copy a contiguous run of cells into row starting at column col, clipping the run at the right edge (and ignoring an out-of-range row or start column). Equivalent to calling Screen::set for each cell in turn, but with a single bounds check for the whole run — the fast path a compositor uses to blit a row slice.

Source

pub fn diff(&self, next: &Screen) -> Vec<u8> ⓘ

The bytes that transform a terminal currently showing self into one showing next: cursor moves (CUP), minimal SGR transitions, and the changed characters, ending with a style reset and the cursor parked at next’s cursor. Equal screens produce no bytes at all.

Both screens must have the same dimensions; if they differ (a resize), the diff falls back to a full repaint of next.

Source

pub fn render_full(&self) -> Vec<u8> ⓘ

A from-scratch repaint: clear the screen, then paint every non-default cell, ending with a style reset and the cursor parked at this screen’s cursor.

Trait Implementations§

Source§

impl Clone for Screen

Source§

fn clone(&self) -> Screen

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
Source§

impl Eq for Screen

Source§

impl PartialEq for Screen

Source§

fn eq(&self, other: &Screen) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Screen

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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.