package miaou-driver-matrix

  1. Overview
  2. Docs

Module Miaou_driver_matrix.Matrix_diffSource

Diff algorithm for the Matrix driver.

Compares front and back buffers to compute minimal changes needed to update the terminal display. Optimizes for:

  • Skipping unchanged cells
  • Minimizing cursor movements
  • Batching consecutive characters
  • Minimizing style changes
Sourcetype change =
  1. | MoveTo of int * int
    (*

    Move cursor to (row, col), 0-indexed

    *)
  2. | SetStyle of Matrix_cell.style
    (*

    Change current text style

    *)
  3. | WriteChar of string
    (*

    Write a single character

    *)
  4. | WriteRun of string * int
    (*

    Write character repeated N times

    *)

A single change operation.

Sourceval compute : Matrix_buffer.t -> change list

Compute diff between front (displayed) and back (new) buffers. Returns list of changes to transform front into back. NOT thread-safe - use compute_atomic for two-domain architecture.

Sourceval compute_atomic : Matrix_buffer.t -> change list

Compute diff atomically with buffer lock held. Thread-safe for two-domain architecture. Also swaps buffers while holding the lock to prevent torn reads. Use this from the render domain.

Sourceval compute_region : Matrix_buffer.t -> row:int -> col:int -> width:int -> height:int -> change list

Compute diff for a specific region of the buffer.

Sourceval count_changes : Matrix_buffer.t -> int

Count number of cells that differ between front and back.