Zeichenwerk API Overview
May 14, 2026 · View on GitHub
A TUI component library based on tcell/v3.
Widgets
Containers
- Box — bordered box with optional title
- Card — bordered container with title in border, optional footer
- Collapsible — toggleable header that hides/reveals one child
- CRT — Matrix-style power-on/off animation wrapper
- Dialog — single-child container used as popup layer
- Flex — linear layout (horizontal or vertical)
- Form — data-bound form connected to a Go struct
- FormGroup — labeled form controls within a Form
- Grid — table-based layout with cell spanning
- Grow — animated reveal wrapper
- Switcher — shows one child pane at a time
- Viewport — scrollable container for oversized content
Input
- Button — clickable button
- Checkbox — toggleable boolean input
- Combo — text input with suggestion-list popup
- Editor — multi-line text editor
- Filter — search input bound to a Filterable widget
- Input — single-line text field
- List — scrollable selectable list
- Radio — mutually-exclusive choice rendered inline
- Select — dropdown selection
- Slider — horizontal int range input
- Tree — expandable hierarchy of nodes
- TreeFS — Tree pre-wired for filesystem navigation
- Typeahead — input with ghost-text suggestion completion
Display
- BarChart — multi-series stacked bar chart
- Breadcrumb — path-style segment indicator
- Canvas — low-level pixel buffer for custom rendering
- Deck — fixed-height list of items rendered by a callback
- Digits — large ASCII art character display
- Heatmap — coloured cell grid for matrix data
- Rule — horizontal or vertical line separator
- Shortcuts — single-row keyboard hint bar
- Sparkline — inline trend chart
- Static — plain text display
- Styled — rich text with inline markup
- Table — tabular data display
- Tabs — tab navigation
- Terminal — embedded terminal emulator
- Text — multi-line scrollable text
- Tiles — wrapping grid of fixed-size tiles
Animated
- Clock — live wall-clock display
- Marquee — scrolling text ticker
- Progress — progress bar (determinate or indeterminate)
- Scanner — back-and-forth scanning animation
- Shimmer — text with sweeping highlight band
- Spinner — animated loading indicator
- Typewriter — character-by-character text reveal
Custom / Extension
- Custom — widget with a user-supplied render function
Widget Interface
The fundamental interface for all UI components. All widgets share common functionality through Component, which provides default implementations.
Apply(theme *Theme)— applies theme stylesBounds() (x, y, w, h int)— absolute screen coordinatesContent() (x, y, w, h int)— inner content area coordinatesCursor() (x, y int, style string)— cursor position relative to contentDispatch(source Widget, event string, data ...any) bool— dispatches event to handlersFlag(name string) bool— gets boolean state flagHint() (w, h int)— preferred content sizeID() string— unique identifierInfo() string— human-readable descriptionLog(source Widget, level, msg string, params ...any)— logs debug messageOn(event string, handler Handler)— registers event handlerParent() Container— parent containerRefresh()— queues widget redrawRender(r *Renderer)— renders widget to screenSetBounds(x, y, w, h int)— sets absolute position and sizeSetFlag(name string, value bool)— sets boolean state flagSetHint(w, h int)— sets preferred content sizeSetParent(parent Container)— sets parent containerSetStyle(selector string, style *Style)— applies style for selectorState() string— widget state for renderingStyle(selector ...string) *Style— returns style for selector
Container Interface
Extends Widget with child management.
Children() []Widget— all direct child widgetsLayout()— arranges child widgets
Helper functions:
Find(container, id string) Widget— finds widget by ID (depth-first)FindAll[T any](container) []T— finds all widgets of type TFindAt(container, x, y int) Widget— finds widget at coordinatesLayout(container)— recursively lays out all child containersTraverse(container, func(Widget) bool)— depth-first traversal
Component
Embedded struct providing default Widget implementation. Embed in every custom widget.
Constructor: NewComponent(id, class string) *Component
Override in embedding structs:
Render(r *Renderer)— draws margin, border, background; callc.Component.Render(r)firstApply(theme *Theme)— calltheme.Apply(w, w.Selector("mywidget"))Cursor() (int, int, string)— returns(0, 0, "")by default
Additional public methods:
Class() string— style classSelector(t string) string— builds atype.class#idselector stringStyles() []string— all defined style selectors
Animation
Embedded struct for timed animations. Manages ticker and goroutine.
Refresh()— triggers widget redrawRunning() bool— true if animation is activeStart(interval time.Duration)— starts animation goroutineStop()— stops animation gracefullyTick()— called on each frame (override in embedding struct)
UI
Root application class managing screen, events, and rendering.
Constructor: NewUI(theme *Theme, root Container, debug bool) (*UI, error)
Close()— removes topmost layerDraw()— renders entire UIDrawWidget(widget Widget)— renders single widgetEventLoop()— polls tcell events (run as goroutine)Focus(widget Widget)— sets keyboard focusHandle(event tcell.Event) bool— processes tcell eventsLayout()— recalculates layout for all layersLog(source Widget, levelStr, msg string, params ...any)— adds structured log entryLogs() *TableLog— returns table log widgetNewBuilder() *Builder— creates builder with current themePopup(x, y, w, h int, popup Container)— shows container as overlayRedraw(widget Widget)— queues widget for individual redrawRefresh()— queues full screen redrawRun() error— starts main event loop (blocks)SetFocus(which string)— navigates focus:"first","last","next","previous"SetLogLevel(level slog.Level)— changes log level at runtimeSetTheme(theme *Theme)— changes active themeShowCursor()— positions and shows cursorShowDebug()— renders debug info barTheme() *Theme— current theme
Keyboard shortcuts:
| Keys | Action |
|---|---|
Tab, Right, Down | Next focusable widget |
Backtab, Left, Up | Previous focusable widget |
Escape | Close topmost popup |
Ctrl+C, Ctrl+Q, q, Q | Quit application |
Ctrl+D | Open inspector popup (debug mode) |
Builder
Fluent API for constructing UIs.
Constructor: NewBuilder(theme *Theme) *Builder
Control:
Build() *UI— returns UI instanceRun()— builds and runs (blocks)
Navigation:
Container() Container— returns top-level containerEnd() *Builder— pops current container from stackFind(id string) Widget— finds widget by IDWith(fn func(*Builder)) *Builder— inline composition helper
Widget methods (all return *Builder):
Box(id, title string)Button(id, text string)Checkbox(id, text string, checked bool)Dialog(id, title string)Digits(id, text string)Editor(id string)Flex(id string, horizontal bool, alignment string, spacing int)Form(id, title string, data any)Grid(id string, rows, columns int, lines bool)Group(id, title, groupName string, horizontal bool, spacing int)HRule(style string)Input(id string, params ...string)List(id string, values ...string)Progress(id string, horizontal bool)Radio(id string, args ...string)Scanner(id string, width int, charStyle string)Select(id string, args ...string)Slider(id string)Spacer()Spinner(id string, sequence string)Static(id, text string)Styled(id, text string)Switcher(id string, connect bool)Tab(name string)Table(id string, provider TableProvider)Tabs(id string, names ...string)Text(id string, content []string, follow bool, max int)Viewport(id, title string)VRule(style string)
Styling methods (all return *Builder):
Background(params ...string)Border(params ...string)Bounds(x, y, w, h int)Cell(x, y, w, h int)— grid cell placementClass(class string)Columns(columns ...int)Flag(flag string, value bool)Font(params ...string)Foreground(params ...string)Hint(width, height int)Margin(a ...int)— 1–4 valuesPadding(a ...int)— 1–4 valuesPosition(x, y int)Rows(rows ...int)Size(width, height int)
Helper Functions
FindUI(widget Widget) *UI— traverses up hierarchy to find root UIHandleKeyEvent(container Container, id string, fn func(Widget, *tcell.EventKey) bool)— registers key handler by widget IDHandleListEvent(container Container, id, event string, fn func(*List, string, int) bool)— registers list handler by widget IDID(widget Widget) string— returns widget ID or"<nil>"OnActivate(widget Widget, handler func(Widget, int) bool)— registers activate handler; receives item indexOnChange(widget Widget, handler func(Widget, string) bool)— registers change handler; receives new value as stringOnKey(widget Widget, handler func(Widget, *tcell.EventKey) bool)— registers key handlerOnMouse(widget Widget, handler func(Widget, *tcell.EventMouse) bool)— registers mouse handlerOnSelect(widget Widget, handler func(Widget, int) bool)— registers select handler; receives item indexRedraw(widget Widget)— queues widget for redrawUpdate(container Container, id string, value any)— updates widget content by typeWidgetType(widget Widget) string— returns type name without package prefix
Table Providers
type TableProvider interface {
Columns() []TableColumn
Length() int
Str(row, col int) string
}
TableColumn fields: Name string, Width int
Built-in: NewArrayTableProvider(headers []string, data [][]string)
Styles
Selectors: "" (default), ":focus", ":hover", ":disabled", "part", "part:state"
Fallback order for "part:state": exact → part → :state → default.
Style methods:
Background() stringBorder() stringCursor() stringFixed() bool— true if values are explicit (not inherited)Font() stringForeground() stringHorizontal() int— total horizontal margin + paddingMargin() (top, right, bottom, left int)Padding() (top, right, bottom, left int)Vertical() int— total vertical margin + paddingWithBackground(color string) *StyleWithBorder(border string) *StyleWithFont(font string) *StyleWithForeground(color string) *StyleWithMargin(a ...int) *StyleWithPadding(a ...int) *Style
Events
Event handlers have type func(source Widget, event string, data ...any) bool. Returning true stops propagation. Multiple handlers for the same event are called in reverse registration order (newest first).
| Event | Data | Description |
|---|---|---|
"activate" | int | Item activated via Enter (List, Table, Tabs) |
"change" | varies | Content or state modified |
"click" | — | Button activated |
"hide" | — | Switcher pane hidden |
"key" | *tcell.EventKey | Keyboard event |
"mode" | string | Canvas mode changed |
"mouse" | *tcell.EventMouse | Mouse event |
"move" | x, y int | Canvas cursor moved |
"select" | int | Item highlighted (List, Table) |
"show" | — | Switcher pane shown |