pub struct Buffer {
pub area: Rect,
pub content: Vec<Cell>,
/* private fields */
}Expand description
A 2D grid of Cells backing the terminal display.
Two buffers are kept (current + previous); only the diff is flushed to the terminal, giving immediate-mode ergonomics with retained-mode efficiency.
The buffer also maintains a clip stack. Push a Rect with
Buffer::push_clip to restrict writes to that region, and pop it with
Buffer::pop_clip when done.
Fields§
§area: RectThe area this buffer covers, in terminal coordinates.
content: Vec<Cell>Flat row-major storage of all cells. Length equals area.width * area.height.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn push_clip(&mut self, rect: Rect)
pub fn push_clip(&mut self, rect: Rect)
Push a clipping rectangle onto the clip stack.
Subsequent writes are restricted to the intersection of all active clip regions. Nested calls intersect with the current clip, so the effective clip can only shrink, never grow.
Sourcepub fn pop_clip(&mut self)
pub fn pop_clip(&mut self)
Pop the most recently pushed clipping rectangle.
After this call, writes are clipped to the previous region (or unclipped if the stack is now empty).
Sourcepub fn in_bounds(&self, x: u32, y: u32) -> bool
pub fn in_bounds(&self, x: u32, y: u32) -> bool
Returns true if (x, y) is within the buffer’s area.
Sourcepub fn get(&self, x: u32, y: u32) -> &Cell
pub fn get(&self, x: u32, y: u32) -> &Cell
Return a reference to the cell at (x, y).
Panics if (x, y) is out of bounds.
Sourcepub fn get_mut(&mut self, x: u32, y: u32) -> &mut Cell
pub fn get_mut(&mut self, x: u32, y: u32) -> &mut Cell
Return a mutable reference to the cell at (x, y).
Panics if (x, y) is out of bounds.
Sourcepub fn set_string(&mut self, x: u32, y: u32, s: &str, style: Style)
pub fn set_string(&mut self, x: u32, y: u32, s: &str, style: Style)
Write a string into the buffer starting at (x, y).
Respects cell boundaries and Unicode character widths. Wide characters (e.g., CJK) occupy two columns; the trailing cell is blanked. Writes that fall outside the current clip region are skipped but still advance the cursor position.
Sourcepub fn set_char(&mut self, x: u32, y: u32, ch: char, style: Style)
pub fn set_char(&mut self, x: u32, y: u32, ch: char, style: Style)
Write a single character at (x, y) with the given style.
No-ops if (x, y) is out of bounds or outside the current clip region.
Sourcepub fn diff<'a>(&'a self, other: &'a Buffer) -> Vec<(u32, u32, &'a Cell)>
pub fn diff<'a>(&'a self, other: &'a Buffer) -> Vec<(u32, u32, &'a Cell)>
Compute the diff between self (current) and other (previous).
Returns (x, y, cell) tuples for every cell that changed. The run loop
uses this to emit only the minimal set of terminal escape sequences
needed to update the display.