Raxol.Core.Runtime.Rendering.Buffer (Raxol v0.4.0)
View SourceProvides a screen buffer implementation for efficient rendering in Raxol applications.
This module is responsible for:
- Maintaining the screen buffer state
- Calculating diffs between buffer states
- Optimizing rendering by only updating changed cells
Summary
Types
A cell represents a single character position on the screen.
A buffer is a map containing cells indexed by their position.
Functions
Clears the buffer by removing all cells.
Computes the diff between two buffers.
Builds a buffer from a list of cells.
Gets the cell at the specified position.
Merges another buffer's cells into this buffer.
Creates a new empty buffer with the given dimensions.
Resizes the buffer to new dimensions.
Sets a cell in the buffer.
Converts the buffer to a flat list of cells.
Types
A cell represents a single character position on the screen.
It is represented as a tuple with the following elements:
x
: X coordinate (column)y
: Y coordinate (row)ch
: Character to displayfg
: Foreground colorbg
: Background colorattrs
: List of attributes (e.g., :bold, :underline)
@type t() :: %Raxol.Core.Runtime.Rendering.Buffer{ cells: %{ required({integer(), integer()}) => {String.t(), term(), term(), list()} }, dirty: boolean(), height: integer(), width: integer() }
A buffer is a map containing cells indexed by their position.
The buffer also contains metadata about its dimensions.
Functions
Clears the buffer by removing all cells.
Parameters
buffer
: The buffer to clear
Returns
Cleared buffer.
Computes the diff between two buffers.
The diff contains only the cells that need to be updated.
Parameters
old_buffer
: Previous buffer statenew_buffer
: Current buffer state
Returns
List of changed cells.
Builds a buffer from a list of cells.
Parameters
cells
: List of cellswidth
: Width of the buffer in columnsheight
: Height of the buffer in rows
Returns
A new buffer containing the cells.
Gets the cell at the specified position.
Parameters
buffer
: The buffer to queryx
: X coordinatey
: Y coordinate
Returns
The cell tuple if found, nil otherwise.
Merges another buffer's cells into this buffer.
Cells from the other buffer overwrite cells in this buffer.
Parameters
buffer
: The destination bufferother
: The source bufferoffset_x
: X offset to apply when mergingoffset_y
: Y offset to apply when merging
Returns
Updated buffer.
Creates a new empty buffer with the given dimensions.
Parameters
width
: Width of the buffer in columnsheight
: Height of the buffer in rows
Returns
A new buffer struct.
Resizes the buffer to new dimensions.
Cells outside the new dimensions are discarded.
Parameters
buffer
: The buffer to resizewidth
: New widthheight
: New height
Returns
Resized buffer.
Sets a cell in the buffer.
Parameters
buffer
: The buffer to modifyx
: X coordinatey
: Y coordinatech
: Characterfg
: Foreground colorbg
: Background colorattrs
: Attributes list
Returns
Updated buffer.
Converts the buffer to a flat list of cells.
Parameters
buffer
: The buffer to convert
Returns
List of cells.