Skip to main content

ScreenBuffer

Struct ScreenBuffer 

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

A buffer representing the entire terminal screen as a 2D grid of cells.

This buffer maintains a complete snapshot of what should be displayed on the terminal, allowing for efficient diffing between frames.

Implementations§

Source§

impl ScreenBuffer

Source

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

Creates a new screen buffer with the given dimensions.

All cells are initialized as empty (spaces with no styling).

Source

pub fn get_cell(&self, x: u16, y: u16) -> Option<&Cell>

Gets a reference to the cell at the given position.

Returns None if the position is out of bounds.

Source

pub fn get_cell_mut(&mut self, x: u16, y: u16) -> Option<&mut Cell>

Gets a mutable reference to the cell at the given position.

Returns None if the position is out of bounds.

Source

pub fn set_cell(&mut self, x: u16, y: u16, cell: Cell)

Sets the cell at the given position.

Does nothing if the position is out of bounds.

Source

pub fn clear(&mut self)

Clears the buffer by setting all cells to empty.

Source

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

Resizes the buffer to new dimensions.

If the new size is larger, new cells are filled with empty cells. If the new size is smaller, cells are truncated.

Source

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

Gets the dimensions of the buffer.

Source

pub fn fill_rect(&mut self, x: u16, y: u16, width: u16, height: u16, cell: Cell)

Fills a rectangular region with the given cell.

Source

pub fn write_str( &mut self, x: u16, y: u16, text: &str, fg: Option<Color>, bg: Option<Color>, )

Writes a string starting at the given position.

The string is written horizontally. If it extends beyond the buffer width, it is truncated. Properly handles wide characters (CJK, emoji) that take 2 columns.

Source

pub fn write_styled_str( &mut self, x: u16, y: u16, text: &str, text_style: Option<&TextStyle>, )

Writes a string with full text styling starting at the given position.

The string is written horizontally. If it extends beyond the buffer width, it is truncated. Properly handles wide characters (CJK, emoji) that take 2 columns.

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> 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, 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.