TUI Components Overview
Invowk™ includes a set of interactive terminal UI components inspired by gum. Use them in your scripts to create interactive prompts, selections, and styled output.
Available Components
| Component | Description | Use Case |
|---|---|---|
| input | Single-line text input | Names, paths, simple values |
| write | Multi-line text editor | Descriptions, commit messages |
| choose | Select from options | Menus, choices |
| confirm | Yes/no prompt | Confirmations |
| filter | Fuzzy filter list | Search through options |
| file | File picker | Select files/directories |
| table | Display tabular data | CSV, data tables |
| spin | Spinner with command | Long-running tasks |
| pager | Scrollable content viewer | Logs, code review, long output |
| format | Format text (markdown, code) | Rendering content |
| style | Style text (colors, bold) | Decorating output |
Quick Examples
# Get user input
NAME=$(invowk tui input --title "What's your name?")
# Choose from options
COLOR=$(invowk tui choose --title "Pick a color" red green blue)
# Confirm action
if invowk tui confirm "Continue?"; then
echo "Proceeding..."
fi
# Show spinner during long task
invowk tui spin --title "Installing..." -- npm install
# Style output
echo "Success!" | invowk tui style --foreground "#00FF00" --bold
Using in Invowkfiles
TUI components work great inside command scripts, including those running in containers with interactive mode (-i):
:::tip Container Support TUI components work seamlessly inside containers when using interactive mode. The components render as modal overlays on your host terminal. See Container Runtime - Interactive Mode for details. :::
{
name: "setup"
description: "Interactive project setup"
implementations: [{
script: {content: """
#!/bin/bash
# Gather information
NAME=$(invowk tui input --title "Project name:")
TYPE=$(invowk tui choose --title "Type:" cli library api)
# Confirm
echo "Creating $TYPE project: $NAME"
if ! invowk tui confirm "Proceed?"; then
echo "Cancelled."
exit 0
fi
# Execute with spinner
invowk tui spin --title "Creating project..." -- mkdir -p "$NAME"
# Success message
echo "Project created!" | invowk tui style --foreground "#00FF00" --bold
"""}
runtimes: [{name: "native"}]
platforms: [{name: "linux"}, {name: "macos"}]
}]
}
Common Patterns
Input with Validation
while true; do
EMAIL=$(invowk tui input --title "Email address:")
if echo "$EMAIL" | grep -qE '^[^@]+@[^@]+\\.[^@]+$'; then
break
fi
echo "Invalid email format" | invowk tui style --foreground "#FF0000"
done
Menu System
ACTION=$(invowk tui choose --title "What would you like to do?"
"Build project"
"Run tests"
"Deploy"
"Exit")
case "$ACTION" in
"Build project") make build ;;
"Run tests") make test ;;
"Deploy") make deploy ;;
"Exit") exit 0 ;;
esac
Progress Feedback
echo "Step 1: Installing dependencies..."
invowk tui spin --title "Installing..." -- npm install
echo "Step 2: Building..."
invowk tui spin --title "Building..." -- npm run build
echo "Done!" | invowk tui style --foreground "#00FF00" --bold
Styled Headers
invowk tui style --bold --foreground "#00BFFF" "=== Project Setup ==="
echo ""
# ... rest of script
Piping and Capture
The components draw their UI on your terminal (/dev/tty on Unix, the console on Windows) and read keys from it, not from stdin and stdout. stdout carries only the result, so NAME=$(invowk tui input) captures exactly the answer, with no control sequences. On supporting terminals, standalone interactive components also emit OSC 7501 Program Status (app="invowk": blocked for question/auth/permission, working for spin, idle for pager and non-selectable table) to the terminal device (never stdout) and emit state=clear on exit or interruption. The UI stays visible when stderr is redirected, and stdin stays free for piped data such as filter options or table rows. format and style are the exception: their styled text is their result, so they write it to stdout.
pager and a table without --selectable only display content. When their stdout is not a terminal, they write that content to stdout and do not open the terminal: pager passes it through unchanged, like less in a pipe, and the table prints its rows as plain text.
# Pipe to filter
ls | invowk tui filter --title "Select file"
# Capture output
SELECTED=$(invowk tui choose opt1 opt2 opt3)
echo "You selected: $SELECTED"
# Pipe for styling
echo "Important message" | invowk tui style --bold
Without a Terminal
If the controlling terminal cannot be opened, a component draws on stderr and reads keys from stdin when both are terminals. With no terminal at all, as in a CI job:
input,write,choose,confirm,filter,fileandtable --selectableexit with status 1, print an error saying the component needs a terminal, and leave stdout empty;spinruns its command once, without the spinner, and keeps the command's output and exit status;pagerwrites the content unchanged to stdout and exits 0;- a
tablewithout--selectableprints its rows as plain text and exits 0.
Exit Codes
Components use exit codes to communicate:
| Component | Exit 0 | Exit 1 |
|---|---|---|
| confirm | User said yes | User said no |
| input | Value entered | Cancelled |
| choose | Option selected | Cancelled |
| filter | Option selected | Cancelled |
| pager | Exited normally | Error occurred |
| spin | Command succeeded | Cancelled with Ctrl+C, the command was killed by a signal, or it was still running 15 seconds after it was stopped (any other failure forwards the command's own code) |
Use in conditionals:
if invowk tui confirm "Delete files?"; then
rm -rf ./temp
fi
Next Steps
Explore each component in detail:
- Input and Write - Text entry
- Choose and Confirm - Selection and confirmation
- Filter and File - Search and file picking
- Table and Spin - Data display and spinners
- Pager - Scrollable content viewing
- Format and Style - Text formatting and styling