(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-256procedureCreate a 256-color palette index.
color-rgbprocedurePack RGB values into a truecolor integer.
(color-rgb 255 128 0) ;; => orangecell-charprocedureGet the character from a cell.
cell-fgprocedureGet the foreground color from a cell.
cell-bgprocedureGet the background color from a cell.
cell-attrsprocedureGet the attributes from a cell.
cell=?procedureCompare two cells for equality.
make-cellprocedureCreate a cell with the given character, colors, and attributes.
make-gridprocedureCreate a grid of width x height cells, filled with default cells.
grid?procedureCheck if a value is a native grid.
grid-widthprocedureGet the grid width.
grid-heightprocedureGet the grid height.
grid-refprocedureGet the cell at (col, row).
grid-set!procedureSet a cell at (col, row) by mutating it in place.
grid-clear!procedureClear the grid to default cells (space, default colors, no attrs).
grid-write-string!procedureWrite a string to the grid at (col, row) with the given style.
Characters are written left-to-right, truncated at the grid edge.
grid-fill-rect!procedureFill a rectangle with a character and style.
grid-diffprocedureCompute 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-copyprocedureCreate a deep copy of a grid (copies cell contents, not references).