Raxol.LiveView.Renderer (Raxol v2.0.1)
View SourceCore buffer-to-HTML rendering engine for Raxol web terminals.
This module handles the conversion of terminal buffers (grid of cells) into optimized HTML suitable for web rendering with character-perfect monospace grid alignment.
Features
- Virtual DOM-style diffing to minimize DOM updates
- Smart caching for common characters and styles
- Efficient iodata-based string building
- Dirty checking to skip unnecessary renders
- Graceful error handling with fallback rendering
Usage
buffer = %{
lines: [%{cells: [%{char: "H", style: %{bold: true}}]}],
width: 80,
height: 24
}
renderer = Raxol.LiveView.Renderer.new()
{html, new_renderer} = Raxol.LiveView.Renderer.render(renderer, buffer)
Summary
Functions
Invalidates all caches, forcing a full re-render on next call.
Creates a new renderer with empty caches.
Renders a buffer to HTML, using diffing and caching for performance.
Returns statistics about cache performance.
Validates a buffer structure.
Types
Functions
Invalidates all caches, forcing a full re-render on next call.
@spec new() :: t()
Creates a new renderer with empty caches.
Renders a buffer to HTML, using diffing and caching for performance.
Returns {html_string, updated_renderer}. On error, returns a fallback
empty terminal HTML and logs the error.
Examples
renderer = Renderer.new()
{html, new_renderer} = Renderer.render(renderer, buffer)
# With invalid buffer - returns empty terminal, logs error
{html, renderer} = Renderer.render(renderer, nil)
Returns statistics about cache performance.
Validates a buffer structure.
Returns :ok if valid, or {:error, reason} if invalid.