sigildocs

(sigil tui grid)

(sigil tui grid) - Character grid with cell-level diffing

Provides a double-buffered character grid for efficient terminal rendering. Each cell stores a character, foreground color, background color, and text attributes. The diff algorithm emits minimal ANSI escape sequences to update only changed cells.

Grid operations are implemented in native C code (native/grid.c) for performance. The native module is linked when building packages that depend on sigil-tui.

Color encoding:

  • -1 = default terminal color
  • 0-7 = standard colors (black, red, green, yellow, blue, magenta, cyan, white)
  • 8-15 = bright colors
  • 16-255 = 256-color palette
  • >= 256 = truecolor RGB (pack with color-rgb)

Exports

color-256procedure

Create a 256-color palette index.

color-rgbprocedure

Pack RGB values into a truecolor integer.

(color-rgb 255 128 0)  ;; => orange
cell-charprocedure

Get the character from a cell.

cell-fgprocedure

Get the foreground color from a cell.

cell-bgprocedure

Get the background color from a cell.

cell-attrsprocedure

Get the attributes from a cell.

cell=?procedure

Compare two cells for equality.

make-cellprocedure

Create a cell with the given character, colors, and attributes.

make-gridprocedure

Create a grid of width x height cells, filled with default cells.

grid?procedure

Check if a value is a native grid.

grid-widthprocedure

Get the grid width.

grid-heightprocedure

Get the grid height.

grid-refprocedure

Get the cell at (col, row).

grid-set!procedure

Set a cell at (col, row) by mutating it in place.

grid-clear!procedure

Clear the grid to default cells (space, default colors, no attrs).

Write a string to the grid at (col, row) with the given style.

Characters are written left-to-right, truncated at the grid edge.

Fill a rectangle with a character and style.

grid-diffprocedure

Compute the diff between prev and curr grids, return an ANSI string.

Scans cell-by-cell, emitting cursor moves and SGR sequences only where cells differ. Returns the string to write atomically via terminal-write-raw.

grid-copyprocedure

Create a deep copy of a grid (copies cell contents, not references).