Build terminal apps in Go
tui is a terminal UI framework built on the Elm Architecture. Standard library only, with 60+ widgets, flex and grid layout, a cell-diff renderer and a headless test harness.
go get github.com/ows4444/tuidashboard simulated machine ╭─ CPU ─────────────────────────────────────────────────────────────────── 53% ╮ │Total 53% load 4.04 3.78 3.27 │ │▃▃▄▄▄▄▅▆▆▇█▇▇▆▅▄▄▃▄▅▄▄▄▃▂▂▂▁▃▂▄▅▃▃▂▁▁▁▂▂▇▆▇▆▅▅▅▆▆▆▆▅▄▄▃▃▁▂▂▃▃█▆▆▇█▇▇▇▆▅▄▅▅▅▅▆▆│ │core 0 █████████████████████████████████████████████████████████████████░░░░░░│ │core 1 ████████████████████████████████████████████████████████████████████░░░│ │core 2 ██████████████████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░│ │core 3 ████████████████████████████████████████████████████████████████░░░░░░░│ │core 4 ██████████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ │core 5 ███████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░│ │core 6 ███████████████████████████████████████████████████████████████████████│ │core 7 █████████████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░│ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯ ● live every 1s 120 samples CPU [tab] panel [enter] zoom [< >] move [space] pause [+/-] speed [f1] help …
- 0module dependencies
- 80+packages and widgets
- 45runnable examples
- 7supported OSes
Why tui
Everything a terminal app needs, nothing it doesn’t
One module, the Go standard library, and conventions enforced by tests.
The Elm Architecture
A Model has
Init,UpdateandView.Updatereturns Cmds for side effects; the Program runs them and feeds the results back as Msgs.Standard library only
go.modhas norequiredirective, and a test ininternal/archtestfails if any package imports outside the standard library.Cell-diff rendering
Each frame is parsed into a grid of cells and only the cells that changed are written, with relative cursor movement.
Widgets that compose
Inputs, tables, trees, dialogs, menus, pickers, charts and more. Every widget has a
LayoutNode()adapter and an accessibleLinearizeform.Layout and theming
Flex, grid and overlay layout nodes. 16 preset themes, component tokens, and glyph sets with an ASCII fallback.
Accessible output
WithAccessibleswitches to append-only, unstyled output for screen readers; reduced motion followsNO_ANIMATIONandREDUCE_MOTION.Terminal-aware
Colour depth from the environment (honours
NO_COLOR), an opt-in capability probe, bracketed paste, mouse and kitty keyboard support.Testable
The
tuitestharness drives a Program headlessly. Every example checks its screens against golden files: the screens on this site.
How it works
Three methods and a Program
- Model holds your state. Any value with
Init,UpdateandViewis one. - Update gets every key, mouse event and resize as a Msg, and returns the next Model plus any Cmd to run.
- View returns a string. The Program diffs it cell by cell and writes only what changed.
- Run takes over the terminal and restores it on every way out.
This is ExampleNewProgram from example_test.go, which go test runs. Running a Program →
type counter struct{ n int }
func (c counter) Init() tui.Cmd { return nil }
func (c counter) Update(msg tui.Msg) (tui.Model, tui.Cmd) { if k, ok := msg.(tui.Key); ok && k.Type == tui.KeyRunes { switch k.Text { case "+": c.n++ case "q": return c, tui.Quit() } } return c, nil}
func (c counter) View() string { return fmt.Sprintf("count: %d", c.n) }
func main() { if _, err := tui.NewProgram(counter{}).Run(); err != nil { fmt.Println(err) }}Built with tui
Real screens, not mock-ups
Each is the first frame an example’s own test checks, at 80×24.
charts Temperature (°C) Temperature Latency Waves Growth Line Scatter Bars Histogram 30┤ ⣀⣀⣀⣀⡠⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⠤⣀⣀ │ ⣀⠤⠔⠒⠊⠉⠉ ⠉⠉⠒⠒⠤⠤⣀⡀ │ ⣀⠤⠒⠉ ⠈⠉⠑⠢⢄⡀ │ ⣀⠤⠒⠉ ⠈⠒⢄⡀ 20┤ ⣀⡠⠔⠊⠉ ⢀⣀⡠⠤⠔⠒⠒⠒⠒⠒⠒⠒⠒⠤⣀ ⠈⠑⠤⣀ │ ⣀⠤⠔⠒⠉ ⢀⡠⠤⠒⠊⠉⣁⡠⠤⠔⠒⠉⠉⠑⠒⠒⠒⠤⠤⣀ ⠉⠒⠤⣀ ⠉⠒⠤⣀ │⠒⠒⠒⠊⠉⠉⠉⠉ ⣀⠤⠒⠉⠁⣀⡠⠔⠊⠉ ⠉⠢⢄ ⠑⠢⢄⡀ ⠉ │ ⣀⠔⠊ ⣀⠤⠒⠉ ⠉⠒⢄⡀ ⠈⠒⠤⣀ 10┤ ⣀⠤⠒⠉ ⢀⠔⠊ ⠈⠑⠢⣀ ⠑⠢⢄⡀ │ ⢀⡠⠔⠊⠉ ⢀⠤⠊⠁ ⠉⠒⢄⡀ ⠈⠑⠢⢄ │ ⢀⡠⠔⠊⠁ ⡠⠔⠊⠁ ⠈⠑⠤⡀ ⠉⠒⠤⣀ 0┤⣀⣀⣀⡠⠤⠤⠤⠔⠊⠁ ⢀⠤⠒⠉ ⠈⠑⠢⢄⣀⡀ ⠉⠒⠤ │ ⢀⡠⠔⠊⠁ ⠈⠉⠒⠒⠤ │⠤⠤⠤⠤⠤⠤⠤⠔⠊⠁ │ -10┤ └─────────────────────────────────────────────────────────────────────────── Jan Apr Jun Sep Dec ● 1 Berlin ● 2 Cairo ● 3 Oslo all 12 points · hover for values, wheel to zoom, drag to pan [←→] cursor [+/-] zoom [tab] data [t] type [1-3] series [f1] help [q] quit
workspace ▸Files Outline 1/18 │▸main.go notes.md todo.txt 1/26 ▾ workspace │ 1 package main ▾ cmd │ 2 main.go │ 3 import ( ▾ internal │ 4 "flag" ▸ cache │ 5 "fmt" ▸ config │ 6 "os" ▸ server │ 7 ) doc.go │ 8 ▾ testdata │ 9 // run starts the server and waits for it to stop golden.txt │ 10 func run(addr string) error { sample.json │ 11 s := newServer(addr) README.md │─────────────────────────────────────────────────────── go.mod │▸Output Problems Log 1/31 go.sum │build step 1 of 30: ok Makefile │build step 2 of 30: ok LICENSE │build step 3 of 30: ok CHANGELOG.md │build step 4 of 30: ok .gitignore │build step 5 of 30: ok │build step 6 of 30: ok │build step 7 of 30: ok Editor focused · main.go [tab] pane [.,] tab [[ ]] resize [c] collapse [z] zoom [?] help [q] quit
kanban 2 of 8 done To do (4) Doing (2) Done (2) ▌Write the release notes Review the form groups p Cut rc.1 Fix the flaky resize tes Record the demo for the Add the colour toolkit Reply to the issue about Plan the v1 freeze + add + add + add 8 cards · drag a card to another column [←→↑↓] select [<>] move [a] add [e] rename [d] delete [?] help [q] quit
Processes 24 running CPU ███████████░░░░░░░░░ 54.6% ▅▆▇██▆▅▆▅▄▄▃▃▂▂▁▂▂▂▁▂▃▃▄▃▃▃▄▄▃▄▅▅▆▇▇▇▇▇█ MEM ███████████░░░░░░░░░ 57.3% ▇▇▇▇▇██▇▇▇██▇█▇▆▇▇▇▇▆▅▆▆▅▆▅▅▅▅▅▄▄▄▃▃▄▄▃▁ PID NAME USER CPU%▼ MEM% STATE 931 compile mdawais 77.9 3.1 R 688 node mdawais 28.2 3.6 R 142 WindowServer _window 23.5 2.7 R 612 docker mdawais 18.2 5.5 S 702 Code Helper mdawais 14.6 6.8 R 790 Slack mdawais 10.1 4.5 S 88 kernel_task root 8.9 4.0 R 703 Code Helper (GPU) mdawais 7.7 2.2 S 930 go mdawais 7.4 1.8 R 745 Safari mdawais 5.8 9.1 R 420 postgres postgres 4.9 4.8 S 1410 Music mdawais 2.9 3.0 S 421 postgres: writer postgres 1.4 0.7 I 507 redis-server redis 1.4 0.6 S 311 sshd root 1.2 0.6 S 1201 cupsd root 1.2 0.3 I 1522 ssh-agent mdawais 1.0 0.1 S 1044 Spotlight mdawais 0.9 0.6 I [ Kill ] [ Pause ] [ Filter / ] [click header] sort [k] kill [space] pause [q] quit
Learn
Start where you are
FAQ
Frequently asked questions
What is tui?
tui is a terminal UI (TUI) framework for Go, at
github.com/ows4444/tui. An application is a
Model with Init, Update and View (the Elm Architecture); tui.NewProgram
runs it, reads keys, mouse events and resizes, and redraws View with a cell
diff so only changed cells are written.
How do I install tui?
Run go get github.com/ows4444/tui. It needs Go 1.26 or later. It resolves to
the latest tagged release. v1.0 freezes the exported identifiers of the stable packages; until it is tagged a release may change exported
identifiers, and the changelog lists each one.
Does tui have any dependencies?
No. tui uses only the Go standard library: go.mod has no require directive,
and a test in internal/archtest fails if any package imports outside the
standard library and the module.
Which platforms does tui support?
Linux, macOS, Windows, FreeBSD, OpenBSD, NetBSD and DragonFly BSD. CI runs the tests on Linux, macOS, Windows and FreeBSD; OpenBSD, NetBSD and DragonFly BSD are cross-compiled. Other operating systems, including Solaris and illumos, fail to build on purpose.
Does tui work with screen readers?
tui.WithAccessible(true) switches a Program to an append-only, unstyled
plain-text transcript that a screen reader can follow, and WithAccessibleAuto
turns it on for ACCESSIBLE=1 or TERM=dumb. No run with VoiceOver, NVDA or
Orca is recorded yet, so screen-reader support is unverified. See
Accessibility.
How do I test a tui application?
The tuitest package runs a model in a real tui.Program against an in-memory
terminal: keys, pastes, resizes and messages go in, and the emulated screen
comes out as lines that can be compared against golden files. See
Testing.
What license is tui under?
MIT.
Ready to build?
Install the module and have a running program in a few minutes.