Struct Terminal

Source
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

Source

pub fn builder(canvas: impl Into<CanvasSource>) -> TerminalBuilder

Creates a new terminal builder with the specified canvas source.

§Parameters
  • canvas - Canvas identifier (CSS selector) or HtmlCanvasElement
§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()?;
Source

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.

Source

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.

Source

pub fn gl(&self) -> &WebGl2RenderingContext

Returns the WebGL2 rendering context.

Source

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.

Source

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

Returns the terminal dimensions in cells.

Source

pub fn cell_count(&self) -> usize

Returns the total number of cells in the terminal grid.

Source

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

Returns the size of the canvas in pixels.

Source

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

Returns the size of each cell in pixels.

Source

pub fn canvas(&self) -> &HtmlCanvasElement

Returns a reference to the HTML canvas element used for rendering.

Source

pub fn renderer(&self) -> &Renderer

Returns a reference to the underlying renderer.

Source

pub fn grid(&self) -> Rc<RefCell<TerminalGrid>>

Returns a reference to the terminal grid.

Source

pub fn get_text(&self, selection: CellQuery) -> CompactString

Returns the textual content of the specified cell selection.

Source

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.

Trait Implementations§

Source§

impl Debug for Terminal

Source§

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

Formats the value using the given formatter. 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.