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
impl ScreenBuffer
Sourcepub fn new(width: u16, height: u16) -> Self
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).
Sourcepub fn get_cell(&self, x: u16, y: u16) -> Option<&Cell>
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.
Sourcepub fn get_cell_mut(&mut self, x: u16, y: u16) -> Option<&mut Cell>
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.
Sourcepub fn set_cell(&mut self, x: u16, y: u16, cell: Cell)
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.
Sourcepub fn resize(&mut self, width: u16, height: u16)
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.
Sourcepub fn dimensions(&self) -> (u16, u16)
pub fn dimensions(&self) -> (u16, u16)
Gets the dimensions of the buffer.
Sourcepub fn fill_rect(&mut self, x: u16, y: u16, width: u16, height: u16, cell: Cell)
pub fn fill_rect(&mut self, x: u16, y: u16, width: u16, height: u16, cell: Cell)
Fills a rectangular region with the given cell.
Sourcepub fn write_str(
&mut self,
x: u16,
y: u16,
text: &str,
fg: Option<Color>,
bg: Option<Color>,
)
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.
Sourcepub fn write_styled_str(
&mut self,
x: u16,
y: u16,
text: &str,
text_style: Option<&TextStyle>,
)
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.