Raxol.Terminal.Renderer (Raxol v0.4.0)
View SourceTerminal renderer module.
This module handles rendering of terminal output, including:
- Character cell rendering
- Text styling
- Cursor rendering
- Performance optimizations
Integration with Other Modules
The Renderer module works closely with several specialized modules:
Manipulation Module
- Receives text and style updates from the Manipulation module
- Renders text with proper styling and positioning
- Handles text insertion, deletion, and modification
Selection Module
- Renders text selections with visual highlighting
- Supports multiple selections
- Handles selection state changes
Validation Module
- Renders validation errors and warnings
- Applies visual indicators for invalid input
- Shows validation state through styling
Performance Optimizations
The renderer includes several optimizations:
- Only renders changed cells
- Batches style updates for consecutive cells
- Minimizes DOM updates
- Caches rendered output when possible
Usage
# Create a new renderer
buffer = ScreenBuffer.new(80, 24)
renderer = Renderer.new(buffer)
# Render with selection
selection = %{selection: {0, 0, 0, 5}}
output = Renderer.render(renderer, selection: selection)
# Render with validation
validation = Validation.validate_input(buffer, 0, 0, "text")
output = Renderer.render(renderer, validation: validation)
Summary
Functions
Clears the cursor position.
Creates a new renderer with the given screen buffer.
Renders the screen buffer to a string.
Sets the cursor position.
Updates the font settings.
Updates the theme settings.
Types
@type t() :: %Raxol.Terminal.Renderer{ cursor: {non_neg_integer(), non_neg_integer()} | nil, font_settings: map(), screen_buffer: Raxol.Terminal.ScreenBuffer.t(), theme: map() }
Functions
Clears the cursor position.
Examples
iex> screen_buffer = ScreenBuffer.new(80, 24)
iex> renderer = Renderer.new(screen_buffer)
iex> renderer = Renderer.set_cursor(renderer, {10, 5})
iex> renderer = Renderer.clear_cursor(renderer)
iex> renderer.cursor
nil
Creates a new renderer with the given screen buffer.
Examples
iex> screen_buffer = ScreenBuffer.new(80, 24)
iex> renderer = Renderer.new(screen_buffer)
iex> renderer.screen_buffer
%ScreenBuffer{}
Renders the screen buffer to a string.
Options
:selection
- A single selection to highlight:selections
- Multiple selections to highlight:validation
- Validation state to apply:theme
- Override the default theme:font_settings
- Override the default font settings
Examples
iex> screen_buffer = ScreenBuffer.new(80, 24)
iex> renderer = Renderer.new(screen_buffer)
iex> output = Renderer.render(renderer)
iex> is_binary(output)
true
iex> screen_buffer = ScreenBuffer.new(80, 24)
iex> renderer = Renderer.new(screen_buffer)
iex> selection = %{selection: {0, 0, 0, 5}}
iex> output = Renderer.render(renderer, selection: selection)
iex> output =~ "background-color: #0000FF"
true
Sets the cursor position.
Examples
iex> screen_buffer = ScreenBuffer.new(80, 24)
iex> renderer = Renderer.new(screen_buffer)
iex> renderer = Renderer.set_cursor(renderer, {10, 5})
iex> renderer.cursor
{10, 5}
Updates the font settings.
Examples
iex> screen_buffer = ScreenBuffer.new(80, 24)
iex> renderer = Renderer.new(screen_buffer)
iex> settings = %{family: "Fira Code"}
iex> renderer = Renderer.set_font_settings(renderer, settings)
iex> renderer.font_settings
%{family: "Fira Code"}
Updates the theme settings.
Examples
iex> screen_buffer = ScreenBuffer.new(80, 24)
iex> renderer = Renderer.new(screen_buffer)
iex> theme = %{foreground: %{default: "#FFF"}}
iex> renderer = Renderer.set_theme(renderer, theme)
iex> renderer.theme
%{foreground: %{default: "#FFF"}}