Page
Library
Module
Module type
Parameter
Class
Class type
Source
Miaou_driver_matrix.Matrix_bufferSourceDouble-buffered terminal grid for the Matrix driver.
Maintains two cell grids (front and back). The back buffer is the write target during rendering, while the front buffer holds the last displayed state for diff computation. After rendering, buffers are swapped via O(1) pointer swap.
Thread-safe: All operations use internal mutex for cross-domain safety.
Create a new buffer with given dimensions. Both front and back are initialized to empty cells.
Resize the buffer in-place, preserving content where possible. New cells are initialized to empty. Marks buffer as dirty.
Set a cell in the back buffer. Out-of-bounds writes are silently ignored. Thread-safe.
Set cell by copying character and style from another cell. More efficient than set when you have a cell to copy from. Thread-safe.
Get a cell from the back buffer. Returns empty cell for out-of-bounds reads. Thread-safe.
Set character and style directly in back buffer. Thread-safe.
Get a cell from the front buffer. Returns empty cell for out-of-bounds reads.
Check if a cell differs between front and back buffers.
Mark all cells as needing redraw (for full refresh after resize). Thread-safe.
val mark_region_dirty :
t ->
row_start:int ->
row_end:int ->
col_start:int ->
col_end:int ->
unitMark a region of cells as needing redraw. Thread-safe. Used for partial refresh and modal regions.
type batch_ops = {clear : unit -> unit;Clear back buffer
*)set_char : row:int ->
col:int ->
char:string ->
style:Matrix_cell.style ->
unit;get : row:int -> col:int -> Matrix_cell.t;Get cell from back buffer
*)rows : int;Current row count
*)cols : int;Current column count
*)}Record of unlocked operations available within with_back_buffer.
Execute function with buffer lock held. Marks dirty after. The callback receives batch_ops for safe unlocked access. If force_full_redraw is true, clears the front buffer first (atomically, while holding the lock) so all cells appear changed. This avoids race conditions when a full redraw is needed.
Execute a read operation with the buffer lock held. Use this for atomic diff computation to prevent torn reads.
Get front cell without locking - use inside with_read_lock.
Get back cell without locking - use inside with_read_lock.
Clear dirty flag without locking - use inside with_read_lock.