Widgets

All widgets are in the tui/widget package. Interactive widgets follow the pattern:

go
widget, cmd = widget.Update(msg)  // in Update
widget.Render(buf, area)           // in Render

Most widgets support SetBlock(tui.Block) for borders and titles.

Text

Static text display with alignment.

go
func NewText(content string) *Text
MethodDescription
SetStyle(Style)Text style
SetAlignment(Alignment)AlignLeft, AlignCenter, AlignRight
SetBlock(Block)Border

Input

Single-line text input with cursor.

go
func NewInput(placeholder string) *Input
FieldDescription
ValueCurrent text value
FocusedWhether input accepts keys
MethodDescription
Update(Msg) (*Input, Cmd)Handle key events
Focus() CmdReturn focus command
SetBlock(Block)Border
SetStyle(Style)Text style

Keyboard: Home, End, Left, Right, Backspace, Delete, Ctrl+U, Ctrl+K, Ctrl+W.

List

Scrollable, selectable list.

go
func NewList(items []string) *List
func NewListFromItems(items []ListItem) *List
MethodDescription
Update(Msg) (*List, Cmd)Navigate with Up/Down/j/k/g/G/PgUp/PgDn
SelectedItem() *ListItemCurrent selection
SetSelectedStyle(Style)Selection highlight
SetBlock(Block)Border

Table

Data table with headers.

go
func NewTable(headers []string) *Table
MethodDescription
SetRows([][]string)Set table data
SetColWidths([]int)Fixed column widths (0 = auto)
Update(Msg) (*Table, Cmd)Navigate rows
SelectedRow() []stringCurrent row data
SetSelectedStyle(Style)Selection highlight
SetBlock(Block)Border

Tabs

Tab bar with keyboard switching.

go
func NewTabs(titles []string) *Tabs
FieldDescription
SelectedActive tab index
ActiveStyleActive tab style
InactiveStyleInactive tab style
SeparatorString between tabs

Navigate with Left/Right arrows or number keys 1-9.

Viewport

Scrollable text viewer.

go
func NewViewport(content string) *Viewport
MethodDescription
SetContent(string)Update text
ScrollTo(y)Jump to line
LineCount() intTotal wrapped lines
Update(Msg)Up/Down/PgUp/PgDn/mouse wheel

Progress

Progress bar with label.

go
func NewProgress() *Progress
FieldDescription
Percent0.0 to 1.0
FilledChar / EmptyCharBar characters
FilledStyle / EmptyStyleBar styles
ShowLabelShow percentage label

Gauge

Full-width gauge with centered overlay label.

go
func NewGauge() *Gauge
MethodDescription
SetPercent(float64)Set value
SetLabel(string)Override label (empty = auto %)

Spinner

Animated loading indicator.

go
func NewSpinner() *Spinner
MethodDescription
Tick() CmdStart animation
Update(Msg) (*Spinner, Cmd)Advance frame
View() stringCurrent frame string
SetLabel(string)Text after spinner
SetSpinnerStyle(SpinnerStyle)Animation style

Styles: SpinnerDots, SpinnerLine, SpinnerCircle, SpinnerBounce, SpinnerMeter, SpinnerGlobe, SpinnerBlock.

Dialog

Modal dialog with buttons.

go
func NewDialog(title, message string) *Dialog
MethodDescription
SetButtons(...string)Set button labels
SelectedButton() stringCurrent button text
Update(Msg)Left/Right to switch

Renders centered over the area.

Sparkline

Mini line chart using block characters.

go
func NewSparkline(data []float64) *Sparkline
MethodDescription
SetData([]float64)Replace data
PushData(val, maxLen)Append with cap
SetMaxVal(float64)Fixed max (0 = auto)

SparklineGroup stacks multiple sparklines vertically.

Scrollbar

Vertical or horizontal scrollbar.

go
func NewScrollbar(total, visible, offset int) *Scrollbar
func NewHScrollbar(total, visible, offset int) *Scrollbar

Hides automatically when total <= visible.

Tree

Navigable tree with expand/collapse.

go
func NewTree(roots ...*TreeNode) *Tree
func NewTreeNode(text string, children ...*TreeNode) *TreeNode
MethodDescription
SelectedNode() *TreeNodeCurrent node
Update(Msg)Up/Down/Left(collapse)/Right(expand)/Enter(toggle)

Vim keys supported: j/k/h/l.

Form

Multi-field labeled input form.

go
func NewForm(fields ...FormField) *Form
func NewFormField(label, placeholder string) FormField
MethodDescription
Values() map[string]stringAll field values
Value(label) stringSingle field value
FocusedField() *FormFieldCurrent field
Update(Msg)Tab/Down=next, Shift+Tab/Up=prev

Image

KGP image display.

go
func NewImage(image.Image) *Image
func NewImageFromPNG([]byte) *Image
func NewImageFromRGBA([]byte, w, h) *Image
func NewImageFromRGB([]byte, w, h) *Image
func NewImageFromFile(path) *Image
func NewImageFromID(uint32) *Image
MethodDescription
SetCompression(bool)ZLIB compress
SetZIndex(int)Layering
SetCrop(x, y, w, h)Source rect
SetVirtual(bool)Unicode placeholder

AnimatedImage

KGP animated image display.

go
func NewAnimatedImage(anim *tui.Animation) *AnimatedImage