Skip to content

Examples

Every directory under examples/ is a runnable program. Clone the repository and run one from its root, for example go run ./examples/dashboard.

The screens are not mock-ups: each is the first frame the example’s own size-matrix test renders at 80×24, shown with the colours its View produces. Only the 16 basic terminal colours depend on a palette, as in any terminal.

Full screens that show what a tui program can look like.

dashboard

Source
┌────────────────────────────────────────────────────────────────────────┐
│                                                                        │
│ Service Dashboard                                               v2.1.0 │
│ ─────────────────────────────── status ─────────────────────────────── │
│                                                                        │
│ ✓ API           ✓ healthy      ✓ Build → ● Test → ○ Deploy             │
│ ⚠ Worker Queue  ⚠ degraded     ⠋ Deploying build  █████░░░░░░░░░░      │
│ ✗ Database      ✗ down                                                 │
│                                                                        │
│ ────────────────────────────── metrics ─────────────────────────────── │
│                                                                        │
│ CPU  ▅▆▄▁▁▄▂▃▃▆▂▅▃▆▇▅▂█▅▆  69.2%                                       │
│ Mem  █▄▆▂▃▇▄▄▃▂▄▇▃▂▆▁▅▁▁▃  30.2%                                       │
│ Disk ███░░░░░░░░░░░░       17.3%                                       │
│                                                                        │
│ ────────────────────────────────────────────────────────────────────── │
│ [r] refresh  [d] about  [q] quit                                       │
│                                                                        │
└────────────────────────────────────────────────────────────────────────┘

canvas

Source

canvas is a custom widget that draws straight into the cell grid through DrawCells: a colour gradient with a moving marker.

@                                                                               
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
arrows move, q quits

chat

Source

chat is a manual showcase of the InkUI-parity widgets added after the original dashboard/form/list examples: Gauge, CodeBlock, DiffView, markdown.Render, streamtext (Typewriter), TokenCounter and layout.Column and layout.Row.

Chat                            session #1      ⣀⣤⣤⣤⣤⣀
                                             ⢀⣴⠟⠉⠁  ⠈⠉⠻⣦⡀
                                            ⢠⡟⠁        ⠈⢻⡄
                                            ⣿⠁   35%    ⠈⣿

┌──────────────────────────────────────────────────────────┐
│                                                          │
│ Refactor parseArgs to return an error instead of calling │
│ os.Exit.                                                 │
│                                                          │
│ • keep the flag order                                    │
│ • add a regression test                                  │
│                                                          │
└──────────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────────┐
│                                                          │
│ █                                                        │
│                                                          │
└──────────────────────────────────────────────────────────┘

┌──────────────────────────────────────────────────────────┐
│ 1 │ func parseArgs(args []string) (Config, error) {      │
│ 2 │     if len(args) < 2 {                               │

welcomescreen

Source

welcomescreen is the canonical reference for a static informational splash composed entirely from the existing widget catalog — widgets.Panel, widgets.BigText, widgets.Header and widgets.KeyValue side by side in a layout.Row.

╭──────────────────────────────────────────────────────────╮
│                                                          │
│ Welcome to TUI                                           │
│                                                          │
│ ┌──────────────────────┐  ┌────────────────────────────┐ │
│ │                      │  │                            │ │
│ │ █████ █ █ ███        │  │ Info                       │ │
│ │  █ █ █ █             │  │ ────────────────────────── │ │
│ │  █ █ █ █             │  │ Version: v1.0.0            │ │
│ │  █ █ █ █             │  │ User: Ada Lovelace         │ │
│ │  █ ██ ███            │  │ Workspace: acline          │ │
│ │                      │  │                            │ │
│ └──────────────────────┘  └────────────────────────────┘ │
│                                                          │
│ enter/esc continue  ctrl+c quit                          │
│                                                          │
╰──────────────────────────────────────────────────────────╯

splashscreen

Source

splashscreen follows the same composition-only shape as examples/welcomescreen and examples/loginflow: widgets.BigText for the logo and widgets.Header for a tagline, dismissed by any keypress.

█████ █  █ ███
  █   █  █  █
  █   █  █  █
  █   █  █  █
  █    ██  ███

Loading your workspace…

press any key to continue

probe

Source

probe shows what your terminal supports, using the library's opt-in capability options: colour depth (with NO_COLOR, COLORTERM and TERM honoured), focus in/out reporting, and OSC 11 background detection.

tui probe: what does your terminal do?

  TERM="xterm-256color"  COLORTERM="truecolor"  NO_COLOR=""
  Colour profile:  truecolor   (detected; drives the strip below)
                                                  

  Focus reports:   in=0 out=0  last=unknown   (click another window, then back)
  Background:      waiting  theme=-   (asked once at start, 700ms timeout)
  Last key:        -
  Size (resize):   80x24

  q or ctrl+c to quit; a summary line stays in your scrollback
  probe: profile=truecolor focus_in=0 focus_out=0 background=waiting theme=-
  focus timeline:
    focus reporting enabled: (not yet)

faces

Source

faces is a gallery for the faces package.

faces  #1 of 50


   ⣠⣾⣿⣿⣷⣄
   ⣿⣧⣿⣿⣼⣿
   ⠙⢿⣯⣽⡿⠋

Pip · blink · 1/8

click a face to play · ←/→ change · s size · w wall · space loop · q quit

Text fields, sign-in and multi-step flows, focus and the cursor.

loginflow

Source

loginflow is the canonical reference for a login-shaped screen composed entirely from the existing widget catalog — widgets.BigText for the title, widgets.Banner for an announcement, and picker.Model configured as a numbered-select account menu.

█     ██   ███ ███ █   █
█    █  █ █     █  ██  █
█    █  █ █ ██  █  █ █ █
█    █  █ █  █  █  █  ██
████  ██   ███ ███ █   █

ℹ Pick an account to continue — no password requir

> Continue as Ada Lovelace
  Continue as guest
  Quit

enter select  ctrl+c quit

setupflow

Source

setupflow follows the same composition-only shape as examples/welcomescreen and examples/loginflow: widgets.BigText for the title, widgets.Alert for a status message, and picker.Model as a numbered-select menu of setup steps.

 ███ ████ █████ █  █ ███
█    █      █   █  █ █  █
 ██  ███    █   █  █ ███
   █ █      █   █  █ █
███  ████   █    ██  █

┌────────────────────────────────────────────────┐
│                                                │
│ ℹ No step applied yet.                         │
│                                                │
└────────────────────────────────────────────────┘

> Configure workspace
  Configure notifications
  Finish

enter apply  ctrl+c quit

login

Source

login is a credential sign-in screen built on package form, with a live design-system panel beside it for trying every theming control the library has.

┌──────────────────────────────────────────────┐
│                                              │
│ Sign in                                      │
│                                              │
│ demo: ada / lovelace                         │
│                                              │
│ Username:  ada                               │
│ Password:                                    │
│ [ ] Remember me                              │
│                                              │
│ [tab] next  [enter] sign in  [ctrl+t] design │
│                                              │
└──────────────────────────────────────────────┘

signup

Source

signup is a small account form built on package form: text, secret, select and checkbox fields with validation, Tab and Shift+Tab to move between them, the arrow keys and Space to change a choice, Enter to submit (Esc quits).

┌────────────────────────────────────────────────────┐
│                                                    │
│ Create an account                                  │
│                                                    │
│ Name:  Ada Lovelace                                │
│ Email: ada@example.com                             │
│ Password:                                          │
│ Plan: < Free >                                     │
│ [ ] Accept terms                                   │
│                                                    │
│ [tab] next  [←→/space] change  [enter] submit      │
│                                                    │
└────────────────────────────────────────────────────┘

form

Source
╭──────────────────────────────────────────────╮
│                                              │
│ Sign up                                      │
│                                              │
│ ● Edit → ○ Confirm                           │
│                                              │
│ Name:      Ada Lovelace                      │
│ Email:    ada@example.com                    │
│ Language: start typing...                    │
│                                              │
│ tab next field  enter next/confirm  esc quit │
│                                              │
╰──────────────────────────────────────────────╯

focus

Source

focus is the canonical, minimal reference for coordinating Focus()/Blur() across mixed widget types in this repo.

╭───────────────────────────────────────────╮
│                                           │
│ Focus/Blur reference                      │
│                                           │
│ ╭───────────────────────────────────────╮ │
│ │Name:      Ada Lovelace                │ │
│ ╰───────────────────────────────────────╯ │
│ ╭───────────────────────────────────────╮ │
│ │Password:                              │ │
│ ╰───────────────────────────────────────╯ │
│ ╭───────────────────────────────────────╮ │
│ │a few words about you...               │ │
│ ╰───────────────────────────────────────╯ │
│                                           │
│ tab next  shift+tab prev  esc/ctrl+c quit │
│                                           │
╰───────────────────────────────────────────╯

cursorfield

Source

cursorfield shows a text input whose cursor is the terminal's real cursor: the model implements tui.CursorPlacer by forwarding textinput.Model.CursorCell, so an IME or a screen magnifier can follow the field.

Name (Enter quits):
>  

Selection, tabs, scrolling and switching screens.

inspector

Source
┌──────────────────────────────────────────────────────────┐
│                                                          │
│ [Table]  JSON                                            │
│                                                          │
│   Name   Status    CPU                                   │
│   ────────────────────                                   │
│ > api-1  running   12%                                   │
│   api-2  running   8%                                    │
│   api-3  degraded  41%                                   │
│                                                          │
│ [←→] tabs  [↑↓] move  [enter] select/toggle  [q] quit    │
│                                                          │
└──────────────────────────────────────────────────────────┘

table

Source

table is a dedicated, standalone example for datatable.Model's interactive row selection: Up/Down move the cursor and Enter confirms the row under it via SelectedMsg.

  Name               Role
  ────────────────────────────────
> Ada Lovelace       Engineer     
  Grace Hopper       Rear Admiral
  Margaret Hamilton  Director
  Katherine Johnson  Mathematician

Selected: (none yet — press Enter)

[↑/↓] move  [enter] select  [q] quit

list

Source
╭─────────────────────────────────────────────────────────╮  ┌───────┐
│                                                         │  │       │
│ Tasks                                                   │  │ Done  │
│                                                         │  │       │
│ > [ ] Design raw-mode terminal layer                    │  │ 0 / 6 │
│   [ ] Build ANSI styling package                        │  │       │
│   [ ] Write escape-sequence key parser                  │  └───────┘
│   [ ] Implement Elm-architecture event loop             │
│   [ ] Add diff-based renderer                           │
│   [ ] Ship zero-dependency TUI                          │
│                                                         │
│ up/down move  space/click toggle  enter confirm  q quit │
│                                                         │
╰─────────────────────────────────────────────────────────╯

settings

Source
┌──────────────────────────────────────────────────────┐
│                                                      │
│ [General]  Advanced                                  │
│                                                      │
│ > ▸ Display                                          │
│   ▸ Notifications                                    │
│                                                      │
│ [←→/click] tabs  [↑↓] move  [enter] toggle  [q] quit │
│                                                      │
└──────────────────────────────────────────────────────┘

router

Source

router is the canonical reference for switching between independent top-level screens in this repo, the way examples/focus is the canonical reference for Focus/Blur coordination.

╭───────────────────────────╮
│                           │
│ Router reference — Menu   │
│                           │
│ > Settings                │
│   About                   │
│   Quit                    │
│                           │
│ enter select  ctrl+c quit │
│                           │
╰───────────────────────────╯

pager

Source
╭──────────────────────────────────────────────────────────────╮
│                                                              │
│ Pager                                                        │
│                                                              │
│ Paragraph 1                                                  │
│ This from-scratch TUI framework talks to the terminal        │
│ directly via raw syscall ioctls, no golang.org/x/term and no │
│ Bubble Tea.                                                  │
│                                                              │
│ Paragraph 2                                                  │
│ The event loop follows the Elm Architecture: a Model         │
│ implements Init, Update, and View, and Program owns the      │
│ terminal, the input parsing, and a line-level diffing        │
│ renderer.                                                    │
│                                                              │
╰──────────────────────────────────────────────────────────────╯
up/down/pgup/pgdown/home/end/wheel scroll  gg top  G bottom  q quit    0%

Composing string and cell children, and the smallest program.

mixedscreen

Source

mixedscreen composes a string child and a cell child into one screen with DrawChild and DrawView.

Mixed string and cell screen


















      █ █ █
  █   █ █ █
  █ █ █ █ █ █
█ █ █ █ █ █ █
q quits

counter

Source
From-scratch TUI — Counter

  Count: 0

(80x24) ↑/→ increment ↓/← decrement q/ctrl+c quit

Commands that resolve later, child processes and committed output.

asyncload

Source

asyncload demonstrates the async-Cmd-resolves-into-a-Msg pattern: a tui.Cmd is just a func() tui.Msg, and Program.dispatch (see program.go) runs each Cmd on its own goroutine and feeds whatever Msg it returns back into the event loop.

╭────────────────────╮
│                    │
│ Loading...         │
│                    │
│ ⠋ fetching data... │
│                    │
╰────────────────────╯

procstream

Source

procstream demonstrates streaming a child process's stdout into a scrolling widget (logview.Model) line by line, as it arrives, rather than buffering the whole thing and rendering it once the process exits.

procstream — streaming a child process's stdout














status: running...
(q/esc to quit)

buildlog

Source

buildlog demonstrates tui.Println (see cmds.go): a Cmd that commits text permanently to the terminal's real scrollback, above the live-updating region, rather than being part of an ordinary View() repaint.

0/4 steps complete

⠋ Running: Fetching dependencies...

agentshell

Source

agentshell is a template for an agent CLI.

>  Ask the agent (paste is fine, Enter sends)

Programs that draw in the normal scrollback instead of the alternate screen; their first frame is small by design.

inlinespinners

Source

inlinespinners is an inline-mode (no alternate screen) list of tasks: finished tasks show a check, the running one a spinner, the rest wait.

⠋ resolve
[ ] fetch
[ ] build
[ ] verify

inlinebuild

Source

inlinebuild is an inline-mode (no alternate screen) build log.

building...

inlinechat

Source

inlinechat is an inline-mode (no alternate screen) chat prompt.

> _

inlinetall

Source

inlinetall is an inline-mode (no alternate screen) transcript that grows past the terminal height.

transcript (Enter adds a line, Esc quits)