sigildocs

(sigil tui)

(sigil tui) - Terminal UI toolkit main module

Ties together terminal control, event parsing, grid rendering, layout, and components into a main loop.

(import (sigil tui))

(tui-run
  (lambda (state)
    (vertical-split 0.9
      (panel "Hello" (text-block '(("Welcome to TUI!"))))
      (status-bar "ready" "" "Ctrl-Q quit")))
  initial-state: my-state
  on-event: (lambda (state event) state)
  fps: 30)

Exports

tui-runprocedure

Run a TUI application.

render: (state) -> UI tree (layout description) initial-state: starting application state on-event: (state event) -> new-state (or 'quit to exit) fps: target frames per second (default 30)

with-terminalprocedure

Run a thunk with the terminal in raw mode and alternate screen.

Sets up raw mode, alternate screen, and hidden cursor on entry. Restores everything on exit (normal or exception).

(with-terminal
  (lambda ()
    ;; Terminal is in raw mode, alternate screen active
    (terminal-write-raw "Hello from raw mode!")
    (let loop ()
      (let ((input (terminal-read-raw 64)))
        (when input (loop))))))

Re-exported from (sigil tui terminal)

Switch to the alternate screen buffer.

Re-exported from (sigil tui terminal)

Switch back to the normal screen buffer.

Re-exported from (sigil tui terminal)

Enable SGR extended mouse tracking.

Re-exported from (sigil tui terminal)

Disable mouse tracking.

Re-exported from (sigil tui terminal)

Get the number of terminal columns.

Re-exported from (sigil tui terminal)

terminal-rowsprocedure

Get the number of terminal rows.

Re-exported from (sigil tui terminal)

Re-exported from (sigil tui event)

parse-inputprocedure

Parse raw terminal input bytes into a list of events.

Takes a parser state (for buffering incomplete sequences) and a bytevector of raw input. Returns a list of events.

(define state (make-parser-state))
(define events (parse-input state #u8(97)))  ;; => ((key #\a))

Re-exported from (sigil tui event)

key-event?procedure

Check if an event is a key event.

Re-exported from (sigil tui event)

mouse-event?procedure

Check if an event is a mouse event.

Re-exported from (sigil tui event)

resize-event?procedure

Check if an event is a resize event.

Re-exported from (sigil tui event)

key-event-keyprocedure

Get the key from a key event (char or symbol).

Re-exported from (sigil tui event)

Get the modifier from a key event, or #f if none.

Re-exported from (sigil tui event)

Get the type from a mouse event (press, release, scroll-up, scroll-down).

Re-exported from (sigil tui event)

Get the column from a mouse event.

Re-exported from (sigil tui event)

Get the row from a mouse event.

Re-exported from (sigil tui event)

make-gridprocedure

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

Re-exported from (sigil tui grid)

grid-widthprocedure

Get the grid width.

Re-exported from (sigil tui grid)

grid-heightprocedure

Get the grid height.

Re-exported from (sigil tui grid)

grid-refprocedure

Get the cell at (col, row).

Re-exported from (sigil tui grid)

grid-set!procedure

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

Re-exported from (sigil tui grid)

grid-clear!procedure

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

Re-exported from (sigil tui grid)

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

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

Re-exported from (sigil tui grid)

Fill a rectangle with a character and style.

Re-exported from (sigil tui grid)

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.

Re-exported from (sigil tui grid)

grid-copyprocedure

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

Re-exported from (sigil tui grid)

make-cellprocedure

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

Re-exported from (sigil tui grid)

default-cellvariable

Re-exported from (sigil tui grid)

cell-charprocedure

Get the character from a cell.

Re-exported from (sigil tui grid)

cell-fgprocedure

Get the foreground color from a cell.

Re-exported from (sigil tui grid)

cell-bgprocedure

Get the background color from a cell.

Re-exported from (sigil tui grid)

cell-attrsprocedure

Get the attributes from a cell.

Re-exported from (sigil tui grid)

cell=?procedure

Compare two cells for equality.

Re-exported from (sigil tui grid)

color-256procedure

Create a 256-color palette index.

Re-exported from (sigil tui grid)

color-rgbprocedure

Pack RGB values into a truecolor integer.

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

Re-exported from (sigil tui grid)

Re-exported from (sigil tui grid)

color-blackvariable

Re-exported from (sigil tui grid)

color-redvariable

Re-exported from (sigil tui grid)

color-greenvariable

Re-exported from (sigil tui grid)

color-yellowvariable

Re-exported from (sigil tui grid)

color-bluevariable

Re-exported from (sigil tui grid)

Re-exported from (sigil tui grid)

color-cyanvariable

Re-exported from (sigil tui grid)

color-whitevariable

Re-exported from (sigil tui grid)

Re-exported from (sigil tui grid)

Re-exported from (sigil tui grid)

Re-exported from (sigil tui grid)

Re-exported from (sigil tui grid)

Re-exported from (sigil tui grid)

Re-exported from (sigil tui grid)

Re-exported from (sigil tui grid)

Re-exported from (sigil tui grid)

attr-nonevariable

Re-exported from (sigil tui grid)

attr-boldvariable

Re-exported from (sigil tui grid)

attr-dimvariable

Re-exported from (sigil tui grid)

attr-italicvariable

Re-exported from (sigil tui grid)

Re-exported from (sigil tui grid)

attr-inversevariable

Re-exported from (sigil tui grid)

Re-exported from (sigil tui grid)

Split space horizontally (side by side) at the given ratio. ratio is the fraction of width for the left child (0.0-1.0).

Re-exported from (sigil tui layout)

Split space vertically (top/bottom) at the given ratio. ratio is the fraction of height for the top child (0.0-1.0).

Re-exported from (sigil tui layout)

panelprocedure

A bordered panel with an optional title. Insets child by 1 on all sides.

Re-exported from (sigil tui layout)

text-blockprocedure

A block of text lines with style. lines is a list of (string fg bg attrs) tuples.

Re-exported from (sigil tui layout)

A selectable list of items with a highlight index. items is a list of (string fg bg attrs) tuples.

Re-exported from (sigil tui layout)

scrollableprocedure

A scrollable view with a scroll offset. child is a text-block or similar content widget.

Re-exported from (sigil tui layout)

status-barprocedure

A status bar with left, center, and right text.

Re-exported from (sigil tui layout)

A text input widget showing the current input state. prompt is the prompt string, value is current text, cursor is cursor position in value.

Re-exported from (sigil tui layout)

fillerprocedure

An empty filler that takes up space.

Re-exported from (sigil tui layout)

layout-treeprocedure

Lay out a UI tree into a flat list of render commands.

Each render command is (type x y w h ...extra-data). The renderer processes these sequentially to draw into the grid.

Re-exported from (sigil tui layout)

Render a list of layout commands into a grid.

Re-exported from (sigil tui components)

Create a new input state with empty value.

Re-exported from (sigil tui input)

input-valueprocedure

Get the current input value.

Re-exported from (sigil tui input)

input-cursorprocedure

Get the current cursor position.

Re-exported from (sigil tui input)

Set the input value.

Re-exported from (sigil tui input)

Set the cursor position.

Re-exported from (sigil tui input)

Handle a key event, returning a symbol or #f.

Returns 'submit when Enter is pressed, #f otherwise. Modifies the input state in place.

Re-exported from (sigil tui input)

input-clear!procedure

Clear the input.

Re-exported from (sigil tui input)