Skip to main content

TerminalGrid

Struct TerminalGrid 

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

A high-performance terminal grid renderer using instanced rendering.

TerminalGrid renders a grid of terminal cells using GL 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

Source

pub fn cell_iter(&self, selection: CellQuery) -> 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.

Source

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

Source

pub fn new( gl: &Context, atlas: FontAtlas, screen_size: (i32, i32), pixel_ratio: f32, glsl_version: &GlslVersion, ) -> Result<TerminalGrid, Error>

Source

pub fn delete(self, gl: &Context)

Deletes all GPU resources owned by this terminal grid.

This must be called before dropping the TerminalGrid to avoid GPU resource leaks on native OpenGL targets. On WASM, WebGL context teardown handles cleanup automatically, but explicit deletion is still recommended.

Source

pub fn set_fallback_glyph(&mut self, fallback: &str)

Sets the fallback glyph for missing characters.

Source

pub fn replace_atlas(&mut self, gl: &Context, atlas: FontAtlas)

Replaces the current font atlas with a new one, translating all existing glyph IDs to the new atlas.

This method handles the transition between atlases by:

  1. Looking up the symbol for each existing glyph ID in the old atlas
  2. Resolving the corresponding glyph slot in the new atlas
  3. Updating double-width glyphs (emoji, wide chars) across both cells
  4. Resizing the grid if cell dimensions changed
Source

pub fn atlas(&self) -> &FontAtlas

Returns the FontAtlas used by this terminal grid.

Source

pub fn atlas_mut(&mut self) -> &mut FontAtlas

Returns a mutable reference to the font atlas.

Source

pub fn set_bg_alpha(&mut self, gl: &Context, alpha: f32)

Sets the background opacity for terminal cells.

When less than 1.0, cell backgrounds become semi-transparent, allowing content rendered behind the terminal grid to show through. Text remains fully opaque regardless of this setting.

The change takes effect on the next call to resize or when the UBO data is next uploaded.

Source

pub fn canvas_size(&self) -> (i32, i32)

Returns the canvas size in pixels.

Source

pub fn cell_size(&self) -> (i32, i32)

Returns the effective cell dimensions in pixels (base size * cell scale).

Source

pub fn css_cell_size(&self) -> (f32, f32)

Returns the cell dimensions in CSS pixels (effective size / device pixel ratio).

Use this for converting browser mouse coordinates (which are in CSS pixels) to terminal grid coordinates.

Source

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

Returns the size of the terminal grid in cells.

Source

pub fn render(&self, gl: &Context, state: &mut GlState) -> Result<(), Error>

Renders the terminal grid in a single call.

This is a convenience method that constructs a RenderContext and executes the full Drawable lifecycle (preparedrawcleanup). For advanced use cases such as compositing with other GL content, use the Drawable trait methods directly.

Source

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.

Source

pub fn selection_tracker(&self) -> SelectionTracker

Returns the active selection state of the terminal grid.

Source

pub fn cell_count(&self) -> usize

Returns the total number of cells in the terminal grid.

Source

pub fn update_cells<'a>( &mut self, cells: impl Iterator<Item = CellData<'a>>, ) -> Result<(), Error>

Updates the content of terminal cells with new data.

Source

pub fn update_cells_by_position<'a>( &mut self, cells: impl Iterator<Item = (u16, u16, CellData<'a>)>, ) -> Result<(), Error>

Source

pub fn update_cells_by_index<'a>( &mut self, cells: impl Iterator<Item = (usize, CellData<'a>)>, ) -> Result<(), Error>

Source

pub fn update_cell( &mut self, x: u16, y: u16, cell_data: CellData<'_>, ) -> Result<(), Error>

Source

pub fn update_cell_by_index( &mut self, idx: usize, cell_data: CellData<'_>, ) -> Result<(), Error>

Source

pub fn flush_cells(&mut self, gl: &Context) -> Result<(), Error>

Flushes pending cell updates to the GPU.

Source

pub fn resize( &mut self, gl: &Context, canvas_size: (i32, i32), pixel_ratio: f32, ) -> Result<(), Error>

Resizes the terminal grid to fit the new canvas dimensions.

Source

pub fn recreate_resources( &mut self, gl: &Context, glsl_version: &GlslVersion, ) -> Result<(), Error>

Recreates all GPU resources after a context loss.

Note: After a context loss, old GL resources are already invalid, so we skip explicit deletion and just create fresh resources.

Source

pub fn recreate_atlas_texture(&mut self, gl: &Context) -> Result<(), Error>

Recreates the font atlas texture after a context loss.

Source

pub fn base_glyph_id(&self, symbol: &str) -> Option<u16>

Returns the base glyph identifier for a given symbol.

Trait Implementations§

Source§

impl Debug for TerminalGrid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Drawable for TerminalGrid

Source§

fn prepare(&self, context: &mut RenderContext<'_>) -> Result<(), Error>

Prepares the object for rendering. Read more
Source§

fn draw(&self, context: &mut RenderContext<'_>)

Performs the actual rendering. Read more
Source§

fn cleanup(&self, context: &mut RenderContext<'_>)

Cleans up after rendering. Read more

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.