pub struct TerminalGrid { /* private fields */ }
Expand description
A high-performance terminal grid renderer using instanced rendering.
TerminalGrid
renders a grid of terminal cells using WebGL2 instanced drawing.
Each cell can display a character from a font atlas with customizable foreground
and background colors. The renderer uses a 2D texture array to efficiently
store glyph data and supports real-time updates of cell content.
Implementations§
Source§impl TerminalGrid
impl TerminalGrid
Sourcepub fn cell_iter(
&self,
start: (u16, u16),
end: (u16, u16),
mode: SelectionMode,
) -> CellIterator ⓘ
pub fn cell_iter( &self, start: (u16, u16), end: (u16, u16), mode: SelectionMode, ) -> CellIterator ⓘ
Zero-allocation iterator over cell indices for a given selection range and mode.
Creates an efficient iterator that yields cell indices and newline indicators without allocating intermediate collections.
§Returns
Iterator yielding (cell_index, needs_newline_after) tuples.
Sourcepub fn get_text(&self, selection: CellQuery) -> CompactString
pub fn get_text(&self, selection: CellQuery) -> CompactString
Extracts text content from the terminal based on the selection query.
Retrieves the text within the selection range, optionally trimming trailing whitespace from each line based on the query configuration.
§Arguments
selection
- Query defining the selection range and options
§Returns
The selected text as a CompactString
, or empty string if no selection.
Source§impl TerminalGrid
impl TerminalGrid
pub fn new( gl: &WebGl2RenderingContext, atlas: FontAtlas, screen_size: (i32, i32), ) -> Result<Self, Error>
Sourcepub fn set_fallback_glyph(&mut self, fallback: &str)
pub fn set_fallback_glyph(&mut self, fallback: &str)
Sets the fallback glyph for missing characters.
Sourcepub fn terminal_size(&self) -> (u16, u16)
pub fn terminal_size(&self) -> (u16, u16)
Returns the size of the terminal grid in cells.
Sourcepub fn cell_data_mut(&mut self, x: u16, y: u16) -> Option<&mut CellDynamic>
pub fn cell_data_mut(&mut self, x: u16, y: u16) -> Option<&mut CellDynamic>
Returns a mutable reference to the cell data at the specified cell coordinates.
Sourcepub fn cell_count(&self) -> usize
pub fn cell_count(&self) -> usize
Returns the total number of cells in the terminal grid.
Sourcepub fn update_cells<'a>(
&mut self,
gl: &WebGl2RenderingContext,
cells: impl Iterator<Item = CellData<'a>>,
) -> Result<(), Error>
pub fn update_cells<'a>( &mut self, gl: &WebGl2RenderingContext, cells: impl Iterator<Item = CellData<'a>>, ) -> Result<(), Error>
Updates the content of terminal cells with new data.
This method efficiently updates the dynamic instance buffer with new cell data. The iterator must provide exactly the same number of cells as the grid contains, in row-major order.
§Parameters
gl
- WebGL2 rendering contextcells
- Iterator providingCellData
for each cell in the grid
§Returns
Ok(())
- Successfully updated cell dataErr(Error)
- Failed to update buffer or other WebGL error
Sourcepub fn resize(
&mut self,
gl: &WebGl2RenderingContext,
canvas_size: (i32, i32),
) -> Result<(), Error>
pub fn resize( &mut self, gl: &WebGl2RenderingContext, canvas_size: (i32, i32), ) -> Result<(), Error>
Resizes the terminal grid to fit the new canvas dimensions.
This method recalculates the terminal dimensions based on the canvas size and cell dimensions, then recreates the necessary GPU buffers if the grid size changed. Existing cell content is preserved where possible during resizing.
§Parameters
gl
- WebGL2 rendering contextcanvas_size
- New canvas dimensions in pixels as(width, height)
§Returns
Ok(())
- Successfully resized the terminalErr(Error)
- Failed to recreate buffers or other WebGL error
Sourcepub fn base_glyph_id(&self, symbol: &str) -> Option<u16>
pub fn base_glyph_id(&self, symbol: &str) -> Option<u16>
Returns the base glyph identifier for a given symbol.