tui-engineering
Skill4 starsChanged 54 days agoMITView on GitHub
Build production-grade, phone-friendly terminal UIs (full-screen TUI dashboards) with zero terminal libraries — pure-core architecture, ANSI-safe layout math, line-diffed painting, SGR mouse + touch gestures, hit-testing, narrow-width responsive layouts, and a headless test harness. Distilled from the axfleet fleet-monitoring TUI. MUST trigger when the user says: "build a TUI", "terminal dashboard", "terminal UI", "full-screen CLI", "ncurses-style", "做个 TUI", "终端面板", "终端界面", "命令行 dashboard", "TUI 适配手机/Moshi", "mouse support in terminal", or asks to add tabs/mouse/touch/responsive behavior to an existing terminal program. Cross-platform: works on Claude Code, OpenAI Codex, OpenCode, and OpenClaw.
In this repository39 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agentic-repo-scaffoldSkill
- agent-travel-plannerSkill
- ai-workflow-spineSkill
- ana-awardSkill
- analyze-video-evidenceSkill
- apple-pdfSkill
- audit-fix-loopSkill
- autonomous-grindSkill
- award-flightsSkill
- banxian-skillSkill
- big-taskSkill
- clean-room-rewriteSkill
- cloudflare-r2-setupSkill
- codebase-sweepSkill
- context-infrastructureSkill
- deep-researchSkill
- download-web-videoSkill
- dr-sharpSkill
- game-script-creationSkill
- gemini-imageSkill
- gpt-imageSkill
- investigateSkill
- jewelry-marketingSkill
- learning-coachSkill
- mineru-pdf-parserSkill
- mtcSkill
- narrative-researchSkill
- neat-freakSkill
- pet-forgeSkill
- plan-design-reviewSkill
- pr-fix-loopSkill
- proxy-node-setupSkill
- serenity-bottleneck-researchSkill
- task-shaped-agent-routingSkill
- transcribeSkill
- tridentSkill
- wandian-writerSkill
- web-novel-writingSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Every rule in this skill states the failure it prevents.
- Very specific: line 57
All layout math flows through here.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
TUI Engineering — phone-friendly terminal dashboards from scratch
Cross-platform Agent Skill — Claude Code · OpenAI Codex · OpenCode · OpenClaw 通用。
Build a full-screen terminal UI the way axfleet is built: no ncurses, no
blessed, no ink — the terminal layer is ~500 lines you own and can test.
Every rule in this skill states the failure it prevents; every mechanism has a
runnable reference implementation at
xingfanxia/axfleet-ui-public
(fixture-driven demo — bun install && bun run tui). The reference stack is
Bun + TypeScript; the architecture is stack-agnostic.
When to use / not use
- ✅ Full-screen dashboards, monitors, pickers, multi-tab tools; anything that must stay readable at phone width (Moshi ≈45 cols) over mosh/SSH.
- ✅ Retrofitting mouse/touch/narrow-mode onto an existing raw-ANSI TUI.
- ❌ Line-oriented CLI output (just print), one-shot prompts (use readline), or apps already committed to a TUI framework (follow that framework).
Architecture (non-negotiable shape)
contracts/ typed data model — the single shape everything renders from
state.ts pure transitions: (state, event) → new state (never mutate)
render/ pure renderers: (state, cols, rows) → string[] (one per tab)
term.ts THE ONLY module touching stdin/stdout
api.ts data source behind fetch/stream fns returning {ok,data}|{ok,error}
index.ts impure event loop wiring term → state → render → paintEverything except term.ts/index.ts is a pure function — that's what makes
layout, input decoding, and gestures unit-testable without a TTY. Transitions
return the same reference when nothing changed; the loop skips redraws on
identity. Detail: references/architecture.md.
Build order (follow this sequence)
contracts/— the typed data model. Fixtures and renderers both compile against it, sotscproves demo data is shape-complete.ansi.ts+ tests —visibleWidth/truncate/padEnd/wrapPlain. All layout math flows through here. CJK/emoji = 2 cells. NeverString.length. → architecture.md §2term.ts— alt screen, raw mode, line-diffed paints, crash restore, puredecodeEventswith split-chunk carry-over + escape timeout. → architecture.md §3, input.mdstate.ts+ tests — tabs, selection, scroll, data application.render/frame.ts— chrome + first tab; add the layout-contract test NOW (every tab × sizes: exactlyrowslines, each ≤cols). Future tabs inherit the guarantee by joining the loop. → testing.md- Remaining tabs — one pure renderer each.
- Fixtures + demo api — deterministic noise, pure fn of (key, time). The TUI now runs headless; every later change is eyeball-verifiable. → testing.md §fixtures
- Mouse/touch — SGR decode → direction-locked gesture machine → hit ranges. Tests before wiring. → input.md
- Narrow-mode pass — render every tab at ~45 cols with fixtures, catalog information loss, fix by stacking/compressing, pin with survival tests. → responsive.md
- Footer hints + README — document keys; keep single-key next/prev aliases bindable from phone-terminal shortcut slots.
Invariants checklist (verify before calling it done)
- Frame is exactly
rowslines, every linevisibleWidth ≤ cols, at ALL sizes (45×30 / 76×24 / 120×40 minimum) — soft-wrap corrupts diff paints - Crash path restores the terminal (
uncaughtException→term.exit()) - Unknown CSI consumed through final byte (F5 must not leak "1","5")
- Trailing escape fragments carried across chunks + escape timeout (~40ms); NEVER eagerly treat chunk-final ESC as the ESC key if ESC quits
- Mouse modes disabled on exit in reverse order of enable
- Selectable list rows are ONE line each, list at top of pane (pane line == item index — hit-testing and follow-selection depend on it)
- Narrow mode stacks/wraps instead of truncating; survival tests assert full message text present at 45 cols
- Fixtures typed against
contracts/; day-spaced noise periods don't divide a day evenly (aliasing) - One command runs typecheck + all tests headless (
bun run verify)
Phone terminals — what actually arrives (hard-won facts)
| Phone action | What the TUI receives (Moshi, measured 2026-07) |
| tap | SGR press + release |
| vertical pan | wheel-up/down burst |
| horizontal swipe | nothing by default — armed only by moshi-hook's live env read of $TMUX_PANE/$ZELLIJ/$HERDR_ENV (that precedence); on detection swipe sends the mux's prefix chord (Ctrl-B n/p). Two verified recipes: tmux conditional binding forwards the chord into a pane titled via OSC 2 (input.md §6.5 — the default-setup path), or bare-shell HERDR_ENV=1 impersonation + speak the chord (§6.6) |
| Mouse-Mode drag | press/drag/release forwarded (gesture recognizer applies) |
Consequences: tap-the-tab-label is primary phone navigation, never make swipe
the only path, map D-pad ←/→ to next/prev, keep single-key aliases
(n/p) for custom shortcut slots. Full table + gesture state machine:
references/input.md.
References
- references/architecture.md — layers, ANSI width math, diffed painting, frame contract
- references/input.md — key/mouse decoding (with code), gestures, hit-testing, phone-terminal channels
- references/responsive.md — narrow-mode methodology (stack-don't-truncate) + audit workflow
- references/testing.md — layered test strategy, deterministic fixtures, verify harness
- Runnable reference: https://github.com/xingfanxia/axfleet-ui-public (code +
docs/tui-methodology.md)
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

