pub struct Screen {
pub cursor: (usize, usize),
/* private fields */
}Expand description
A rows x cols grid of Cells plus a cursor position, both 0-based.
Fields§
§cursor: (usize, usize)Where the cursor should rest after rendering: (row, col), 0-based.
Implementations§
Source§impl Screen
impl Screen
Sourcepub fn new(rows: usize, cols: usize) -> Self
pub fn new(rows: usize, cols: usize) -> Self
A blank screen (all default cells, cursor at the origin).
pub fn rows(&self) -> usize
pub fn cols(&self) -> usize
Sourcepub fn clear(&mut self)
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.
Sourcepub fn cell(&self, row: usize, col: usize) -> Cell
pub fn cell(&self, row: usize, col: usize) -> Cell
The cell at (row, col); out of bounds returns a default cell.
Sourcepub fn set(&mut self, row: usize, col: usize, cell: Cell)
pub fn set(&mut self, row: usize, col: usize, cell: Cell)
Set one cell. Out-of-bounds writes are ignored.
Sourcepub fn write_str(&mut self, row: usize, col: usize, text: &str, style: Style)
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 set Cell::width and use Screen::set or
Screen::copy_cells.
Sourcepub fn copy_cells(&mut self, row: usize, col: usize, cells: &[Cell])
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.
Sourcepub fn diff(&self, next: &Screen) -> Vec<u8> ⓘ
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.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.
Sourcepub fn render_full(&self) -> Vec<u8> ⓘ
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
self.cursor.