(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-runprocedureRun 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-terminalprocedureRun 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)
alternate-screen-onprocedureSwitch to the alternate screen buffer.
Re-exported from (sigil tui terminal)
alternate-screen-offprocedureSwitch back to the normal screen buffer.
Re-exported from (sigil tui terminal)
enable-mouse-trackingprocedureEnable SGR extended mouse tracking.
Re-exported from (sigil tui terminal)
disable-mouse-trackingprocedureDisable mouse tracking.
Re-exported from (sigil tui terminal)
terminal-columnsprocedureGet the number of terminal columns.
Re-exported from (sigil tui terminal)
terminal-rowsprocedureGet the number of terminal rows.
Re-exported from (sigil tui terminal)
make-parser-statevariableRe-exported from (sigil tui event)
parse-inputprocedureParse 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?procedureCheck if an event is a key event.
Re-exported from (sigil tui event)
mouse-event?procedureCheck if an event is a mouse event.
Re-exported from (sigil tui event)
resize-event?procedureCheck if an event is a resize event.
Re-exported from (sigil tui event)
key-event-keyprocedureGet the key from a key event (char or symbol).
Re-exported from (sigil tui event)
key-event-modifierprocedureGet the modifier from a key event, or #f if none.
Re-exported from (sigil tui event)
mouse-event-typeprocedureGet the type from a mouse event (press, release, scroll-up, scroll-down).
Re-exported from (sigil tui event)
mouse-event-colprocedureGet the column from a mouse event.
Re-exported from (sigil tui event)
mouse-event-rowprocedureGet the row from a mouse event.
Re-exported from (sigil tui event)
make-gridprocedureCreate a grid of width x height cells, filled with default cells.
Re-exported from (sigil tui grid)
grid-widthprocedureGet the grid width.
Re-exported from (sigil tui grid)
grid-heightprocedureGet the grid height.
Re-exported from (sigil tui grid)
grid-refprocedureGet the cell at (col, row).
Re-exported from (sigil tui grid)
grid-set!procedureSet a cell at (col, row) by mutating it in place.
Re-exported from (sigil tui grid)
grid-clear!procedureClear the grid to default cells (space, default colors, no attrs).
Re-exported from (sigil tui grid)
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.
Re-exported from (sigil tui grid)
grid-fill-rect!procedureFill a rectangle with a character and style.
Re-exported from (sigil tui grid)
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.
Re-exported from (sigil tui grid)
grid-copyprocedureCreate a deep copy of a grid (copies cell contents, not references).
Re-exported from (sigil tui grid)
make-cellprocedureCreate a cell with the given character, colors, and attributes.
Re-exported from (sigil tui grid)
default-cellvariableRe-exported from (sigil tui grid)
cell-charprocedureGet the character from a cell.
Re-exported from (sigil tui grid)
cell-fgprocedureGet the foreground color from a cell.
Re-exported from (sigil tui grid)
cell-bgprocedureGet the background color from a cell.
Re-exported from (sigil tui grid)
cell-attrsprocedureGet the attributes from a cell.
Re-exported from (sigil tui grid)
cell=?procedureCompare two cells for equality.
Re-exported from (sigil tui grid)
color-256procedureCreate a 256-color palette index.
Re-exported from (sigil tui grid)
color-rgbprocedurePack RGB values into a truecolor integer.
(color-rgb 255 128 0) ;; => orangeRe-exported from (sigil tui grid)
color-defaultvariableRe-exported from (sigil tui grid)
color-blackvariableRe-exported from (sigil tui grid)
color-redvariableRe-exported from (sigil tui grid)
color-greenvariableRe-exported from (sigil tui grid)
color-yellowvariableRe-exported from (sigil tui grid)
color-bluevariableRe-exported from (sigil tui grid)
color-magentavariableRe-exported from (sigil tui grid)
color-cyanvariableRe-exported from (sigil tui grid)
color-whitevariableRe-exported from (sigil tui grid)
color-bright-blackvariableRe-exported from (sigil tui grid)
color-bright-redvariableRe-exported from (sigil tui grid)
color-bright-greenvariableRe-exported from (sigil tui grid)
color-bright-yellowvariableRe-exported from (sigil tui grid)
color-bright-bluevariableRe-exported from (sigil tui grid)
color-bright-magentavariableRe-exported from (sigil tui grid)
color-bright-cyanvariableRe-exported from (sigil tui grid)
color-bright-whitevariableRe-exported from (sigil tui grid)
attr-nonevariableRe-exported from (sigil tui grid)
attr-boldvariableRe-exported from (sigil tui grid)
attr-dimvariableRe-exported from (sigil tui grid)
attr-italicvariableRe-exported from (sigil tui grid)
attr-underlinevariableRe-exported from (sigil tui grid)
attr-inversevariableRe-exported from (sigil tui grid)
attr-strikethroughvariableRe-exported from (sigil tui grid)
horizontal-splitprocedureSplit 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)
vertical-splitprocedureSplit 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)
panelprocedureA bordered panel with an optional title. Insets child by 1 on all sides.
Re-exported from (sigil tui layout)
text-blockprocedureA block of text lines with style. lines is a list of (string fg bg attrs) tuples.
Re-exported from (sigil tui layout)
selectable-listprocedureA selectable list of items with a highlight index. items is a list of (string fg bg attrs) tuples.
Re-exported from (sigil tui layout)
scrollableprocedureA scrollable view with a scroll offset. child is a text-block or similar content widget.
Re-exported from (sigil tui layout)
status-barprocedureA status bar with left, center, and right text.
Re-exported from (sigil tui layout)
text-input-widgetprocedureA 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)
fillerprocedureAn empty filler that takes up space.
Re-exported from (sigil tui layout)
layout-treeprocedureLay 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-commandsprocedureRender a list of layout commands into a grid.
Re-exported from (sigil tui components)
make-input-stateprocedureCreate a new input state with empty value.
Re-exported from (sigil tui input)
input-valueprocedureGet the current input value.
Re-exported from (sigil tui input)
input-cursorprocedureGet the current cursor position.
Re-exported from (sigil tui input)
input-set-value!procedureSet the input value.
Re-exported from (sigil tui input)
input-set-cursor!procedureSet the cursor position.
Re-exported from (sigil tui input)
input-handle-keyprocedureHandle 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!procedureClear the input.
Re-exported from (sigil tui input)