pub struct Terminal { /* private fields */ }
Expand description
High-performance WebGL2 terminal renderer.
Terminal
encapsulates the complete terminal rendering system, providing a
simplified API over the underlying Renderer
and TerminalGrid
components.
§Selection and Mouse Input
The renderer supports mouse-driven text selection with automatic clipboard integration:
// Enable default selection handler
use beamterm_renderer::{SelectionMode, Terminal};
let terminal = Terminal::builder("#canvas")
.default_mouse_input_handler(SelectionMode::Linear, true)
.build()?;
// Or implement custom mouse handling
let terminal = Terminal::builder("#canvas")
.mouse_input_handler(|event, grid| {
// Custom handler logic
})
.build()?;
§Examples
use beamterm_renderer::{CellData, Terminal};
// Create and render a simple terminal
let mut terminal = Terminal::builder("#canvas").build()?;
// Update cells with content
let cells: Vec<CellData> = unimplemented!();
terminal.update_cells(cells.into_iter())?;
// Render frame
terminal.render_frame()?;
// Handle window resize
let (new_width, new_height) = (800, 600);
terminal.resize(new_width, new_height)?;
Implementations§
Source§impl Terminal
impl Terminal
Sourcepub fn builder(canvas: impl Into<CanvasSource>) -> TerminalBuilder
pub fn builder(canvas: impl Into<CanvasSource>) -> TerminalBuilder
Creates a new terminal builder with the specified canvas source.
§Parameters
canvas
- Canvas identifier (CSS selector) orHtmlCanvasElement
§Examples
// Using CSS selector
use web_sys::HtmlCanvasElement;
use beamterm_renderer::Terminal;
let terminal = Terminal::builder("my-terminal").build()?;
// Using canvas element
let canvas: &HtmlCanvasElement = unimplemented!("document.get_element_by_id(...)");
let terminal = Terminal::builder(canvas).build()?;
Sourcepub fn update_cells<'a>(
&mut self,
cells: impl Iterator<Item = CellData<'a>>,
) -> Result<(), Error>
pub fn update_cells<'a>( &mut self, cells: impl Iterator<Item = CellData<'a>>, ) -> Result<(), Error>
Updates terminal cell content efficiently.
This method batches all cell updates and uploads them to the GPU in a single operation. For optimal performance, collect all changes and update in one call rather than making multiple calls for individual cells.
Delegates to TerminalGrid::update_cells
.
Sourcepub fn update_cells_by_position<'a>(
&mut self,
cells: impl Iterator<Item = (u16, u16, CellData<'a>)>,
) -> Result<(), Error>
pub fn update_cells_by_position<'a>( &mut self, cells: impl Iterator<Item = (u16, u16, CellData<'a>)>, ) -> Result<(), Error>
Updates terminal cell content efficiently.
This method batches all cell updates and uploads them to the GPU in a single operation. For optimal performance, collect all changes and update in one call rather than making multiple calls for individual cells.
Delegates to TerminalGrid::update_cells_by_position
.
Sourcepub fn gl(&self) -> &WebGl2RenderingContext
pub fn gl(&self) -> &WebGl2RenderingContext
Returns the WebGL2 rendering context.
Sourcepub fn resize(&mut self, width: i32, height: i32) -> Result<(), Error>
pub fn resize(&mut self, width: i32, height: i32) -> Result<(), Error>
Resizes the terminal to fit new canvas dimensions.
This method updates both the renderer viewport and terminal grid to match the new canvas size. The terminal dimensions (in cells) are automatically recalculated based on the cell size from the font atlas.
Combines Renderer::resize
and TerminalGrid::resize
operations.
Sourcepub fn terminal_size(&self) -> (u16, u16)
pub fn terminal_size(&self) -> (u16, u16)
Returns the terminal dimensions in cells.
Sourcepub fn cell_count(&self) -> usize
pub fn cell_count(&self) -> usize
Returns the total number of cells in the terminal grid.
Sourcepub fn canvas_size(&self) -> (i32, i32)
pub fn canvas_size(&self) -> (i32, i32)
Returns the size of the canvas in pixels.
Sourcepub fn canvas(&self) -> &HtmlCanvasElement
pub fn canvas(&self) -> &HtmlCanvasElement
Returns a reference to the HTML canvas element used for rendering.
Sourcepub fn grid(&self) -> Rc<RefCell<TerminalGrid>>
pub fn grid(&self) -> Rc<RefCell<TerminalGrid>>
Returns a reference to the terminal grid.
Sourcepub fn get_text(&self, selection: CellQuery) -> CompactString
pub fn get_text(&self, selection: CellQuery) -> CompactString
Returns the textual content of the specified cell selection.
Sourcepub fn render_frame(&mut self) -> Result<(), Error>
pub fn render_frame(&mut self) -> Result<(), Error>
Renders the current terminal state to the canvas.
This method performs the complete render pipeline: frame setup, grid rendering, and frame finalization. Call this after updating terminal content to display the changes.
Combines Renderer::begin_frame
, Renderer::render
, and Renderer::end_frame
.