# Examples

> Every program under examples/, with the 80×24 screen its test checks.

Web: https://tui.nizaami.com/examples/

Every directory under [examples/](https://github.com/ows4444/tui/tree/code/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.

## Showcase

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

### dashboard

Run: `go run ./examples/dashboard`

````text
┌────────────────────────────────────────────────────────────────────────┐
│                                                                        │
│ 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                                       │
│                                                                        │
└────────────────────────────────────────────────────────────────────────┘
````

[Source](https://github.com/ows4444/tui/tree/code/examples/dashboard)

### canvas

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

Run: `go run ./examples/canvas`

````text
@                                                                               
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
arrows move, q quits
````

[Source](https://github.com/ows4444/tui/tree/code/examples/canvas)

### chat

`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.

Run: `go run ./examples/chat`

````text
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 {                               │
````

[Source](https://github.com/ows4444/tui/tree/code/examples/chat)

### welcomescreen

`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.

Run: `go run ./examples/welcomescreen`

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

[Source](https://github.com/ows4444/tui/tree/code/examples/welcomescreen)

### splashscreen

`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.

Run: `go run ./examples/splashscreen`

````text
█████ █  █ ███           
  █   █  █  █            
  █   █  █  █            
  █   █  █  █            
  █    ██  ███           
                         
Loading your workspace…  
                         
press any key to continue
````

[Source](https://github.com/ows4444/tui/tree/code/examples/splashscreen)

### probe

`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.

Run: `go run ./examples/probe`

````text
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)
````

[Source](https://github.com/ows4444/tui/tree/code/examples/probe)

### faces

`faces` is a gallery for the faces package.

Run: `go run ./examples/faces`

````text
faces  #1 of 50                                                          
                                                                         
                                                                         
   ⣠⣾⣿⣿⣷⣄                                                                
   ⣿⣧⣿⣿⣼⣿                                                                
   ⠙⢿⣯⣽⡿⠋                                                                
                                                                         
Pip · blink · 1/8                                                        
                                                                         
click a face to play · ←/→ change · s size · w wall · space loop · q quit
````

[Source](https://github.com/ows4444/tui/tree/code/examples/faces)

## Forms and input

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

### loginflow

`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.

Run: `go run ./examples/loginflow`

````text
█     ██   ███ ███ █   █                          
█    █  █ █     █  ██  █                          
█    █  █ █ ██  █  █ █ █                          
█    █  █ █  █  █  █  ██                          
████  ██   ███ ███ █   █                          
                                                  
ℹ Pick an account to continue — no password requir
                                                  
> Continue as Ada Lovelace                        
  Continue as guest                               
  Quit                                            
                                                  
enter select  ctrl+c quit
````

[Source](https://github.com/ows4444/tui/tree/code/examples/loginflow)

### setupflow

`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.

Run: `go run ./examples/setupflow`

````text
 ███ ████ █████ █  █ ███                          
█    █      █   █  █ █  █                         
 ██  ███    █   █  █ ███                          
   █ █      █   █  █ █                            
███  ████   █    ██  █                            
                                                  
┌────────────────────────────────────────────────┐
│                                                │
│ ℹ No step applied yet.                         │
│                                                │
└────────────────────────────────────────────────┘
                                                  
> Configure workspace                             
  Configure notifications                         
  Finish                                          
                                                  
enter apply  ctrl+c quit
````

[Source](https://github.com/ows4444/tui/tree/code/examples/setupflow)

### login

`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.

Run: `go run ./examples/login`

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

[Source](https://github.com/ows4444/tui/tree/code/examples/login)

### signup

`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).

Run: `go run ./examples/signup`

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

[Source](https://github.com/ows4444/tui/tree/code/examples/signup)

### form

Run: `go run ./examples/form`

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

[Source](https://github.com/ows4444/tui/tree/code/examples/form)

### focus

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

Run: `go run ./examples/focus`

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

[Source](https://github.com/ows4444/tui/tree/code/examples/focus)

### cursorfield

`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.

Run: `go run ./examples/cursorfield`

````text
Name (Enter quits):
>
````

[Source](https://github.com/ows4444/tui/tree/code/examples/cursorfield)

## Lists, tables and navigation

Selection, tabs, scrolling and switching screens.

### inspector

Run: `go run ./examples/inspector`

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

[Source](https://github.com/ows4444/tui/tree/code/examples/inspector)

### table

`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.

Run: `go run ./examples/table`

````text
  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
````

[Source](https://github.com/ows4444/tui/tree/code/examples/table)

### list

Run: `go run ./examples/list`

````text
╭─────────────────────────────────────────────────────────╮  ┌───────┐
│                                                         │  │       │
│ 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 │           
│                                                         │           
╰─────────────────────────────────────────────────────────╯
````

[Source](https://github.com/ows4444/tui/tree/code/examples/list)

### settings

Run: `go run ./examples/settings`

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

[Source](https://github.com/ows4444/tui/tree/code/examples/settings)

### router

`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.

Run: `go run ./examples/router`

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

[Source](https://github.com/ows4444/tui/tree/code/examples/router)

### pager

Run: `go run ./examples/pager`

````text
╭──────────────────────────────────────────────────────────────╮         
│                                                              │         
│ 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%
````

[Source](https://github.com/ows4444/tui/tree/code/examples/pager)

## Layout and rendering

Composing string and cell children, and the smallest program.

### mixedscreen

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

Run: `go run ./examples/mixedscreen`

````text
Mixed string and cell screen


















      █ █ █   
  █   █ █ █   
  █ █ █ █ █ █ 
█ █ █ █ █ █ █ 
q quits
````

[Source](https://github.com/ows4444/tui/tree/code/examples/mixedscreen)

### counter

Run: `go run ./examples/counter`

````text
From-scratch TUI — Counter

  Count: 0

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

[Source](https://github.com/ows4444/tui/tree/code/examples/counter)

## Async and streaming

Commands that resolve later, child processes and committed output.

### asyncload

`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.

Run: `go run ./examples/asyncload`

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

[Source](https://github.com/ows4444/tui/tree/code/examples/asyncload)

### procstream

`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.

Run: `go run ./examples/procstream`

````text
procstream — streaming a child process's stdout             
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
                                                            
status: running...                                          
(q/esc to quit)
````

[Source](https://github.com/ows4444/tui/tree/code/examples/procstream)

### buildlog

`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.

Run: `go run ./examples/buildlog`

````text
0/4 steps complete                 
                                   
⠋ Running: Fetching dependencies...
````

[Source](https://github.com/ows4444/tui/tree/code/examples/buildlog)

### agentshell

`agentshell` is a template for an agent CLI.

Run: `go run ./examples/agentshell`

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

[Source](https://github.com/ows4444/tui/tree/code/examples/agentshell)

## Inline mode

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

### inlinespinners

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

Run: `go run ./examples/inlinespinners`

````text
⠋ resolve
[ ] fetch
[ ] build
[ ] verify
````

[Source](https://github.com/ows4444/tui/tree/code/examples/inlinespinners)

### inlinebuild

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

Run: `go run ./examples/inlinebuild`

````text
building...
````

[Source](https://github.com/ows4444/tui/tree/code/examples/inlinebuild)

### inlinechat

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

Run: `go run ./examples/inlinechat`

````text
> _
````

[Source](https://github.com/ows4444/tui/tree/code/examples/inlinechat)

### inlinetall

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

Run: `go run ./examples/inlinetall`

````text
transcript (Enter adds a line, Esc quits)
````

[Source](https://github.com/ows4444/tui/tree/code/examples/inlinetall)
