npx skills add https://github.com/hyperb1iss/hyperskills --skill tui-design用于构建卓越终端用户界面的通用设计模式。框架无关——可与 Ratatui、Ink、Textual、Bubbletea 或任何 TUI 工具包配合使用。
核心理念: TUI 通过空间一致性、键盘流畅性以及尊重人类注意力的信息密度来获得其力量。为专家的速度而设计,同时不放弃初学者的可发现性。
digraph tui_design {
rankdir=TB;
"What are you building?" [shape=diamond];
"Select layout paradigm" [shape=box];
"Design interaction model" [shape=box];
"Define visual system" [shape=box];
"Validate against anti-patterns" [shape=box];
"Ship it" [shape=doublecircle];
"What are you building?" -> "Select layout paradigm";
"Select layout paradigm" -> "Design interaction model";
"Design interaction model" -> "Define visual system";
"Define visual system" -> "Validate against anti-patterns";
"Validate against anti-patterns" -> "Ship it";
}
根据您正在构建的内容选择主要布局:
| 应用类型 | 范式 | 示例 |
|---|---|---|
| 文件管理器 | 米勒列 | yazi, ranger |
| Git / DevOps 工具 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 持久多面板 |
| lazygit, lazydocker |
| 系统监视器 | 部件仪表板 | btop, bottom, oxker |
| 数据浏览器 / K8s | 向下钻取堆栈 | k9s, diskonaut |
| SQL / HTTP 客户端 | IDE 三面板 | harlequin, posting |
| Shell 增强 | 覆盖层 / 弹出框 | atuin, fzf |
| 日志 / 事件查看器 | 标题 + 可滚动列表 | htop, tig |
所有面板同时可见。焦点在它们之间切换。用户建立空间记忆——“分支总是在左上角”。
┌─ Status ──┬─────────── Detail ──────────┐
├─ Files ───┤ │
│ > file.rs │ diff content here... │
│ main.rs │ │
├─ Branches ┤ │
│ * main │ │
│ feat/x │ │
├─ Commits ─┤ │
│ abc1234 │ │
└───────────┴──────────────────────────────┘
[q]uit [c]ommit [p]ush [?]help
何时使用: 用户需要同时查看多方面信息的工具(Git 客户端、容器管理器、监控工具)。关键规则: 面板在会话之间保持固定位置。未经用户操作,切勿重新排列。
三窗格过去/现在/未来导航。父目录(左),当前目录(中),预览(右)。
┌── Parent ──┬── Current ──┬── Preview ────────┐
│ .. │ > config/ │ port: 8080 │
│ src/ │ lib/ │ host: localhost │
│ > config/ │ main.rs │ log_level: debug │
│ tests/ │ mod.rs │ db_url: postgres://│
└────────────┴─────────────┴───────────────────┘
何时使用: 分层数据导航(文件系统、树状结构、嵌套配置)。关键规则: 预览窗格内容根据选择类型自适应——代码获得高亮,图像渲染,目录显示内容。
Enter 键向下钻取,Esc 键向上返回。通过分层数据进行类似浏览器的导航。
何时使用: 深度层次结构,同时显示所有层级不切实际(Kubernetes 资源、数据库模式)。关键规则: 始终将当前导航路径显示为面包屑。提供 :resource 命令模式用于直接跳转。
具有独立数据的自包含部件面板。所有信息一目了然,无需导航。
┌─── CPU ──────────────┬─── Memory ──────────┐
│ ▁▂▃▅▇█▇▅▃▂▁▂▃▅▇ │ ████████░░ 78% │
│ core0: 45% core1: 67%│ 12.4G / 16.0G │
├─── Network ──────────┼─── Disk ────────────┤
│ ▲ 1.2 MB/s ▼ 340KB/s│ /: 67% /home: 45% │
├─── Processes ────────┴─────────────────────┤
│ PID USER CPU% MEM% CMD │
│ 1234 root 23.4 4.5 postgres │
└─────────────────────────────────────────────┘
何时使用: 监控、实时状态、系统仪表板。关键规则: 每个部件都是自包含的,有自己的标题。使用盲文/块字符表示高密度数据。
侧边栏(左),编辑器/主区域(中),详细信息/输出(底部)。顶部有标签栏。
何时使用: 专注于编辑的工具(SQL 客户端、HTTP 工具、配置编辑器)。关键规则: 侧边栏可通过单个按键切换。中心面板支持标签页。底部面板可展开至全高。
TUI 按需在 Shell 上方出现,使用后消失。
何时使用: Shell 增强功能(历史搜索、文件选择器、命令面板)。关键规则: 高度可配置。将选择返回给调用者。绝不干扰回滚历史。
带有仪表/统计信息的固定标题,下方为可滚动数据,底部为功能栏。
何时使用: 带有元数据的单列表工具(进程查看器、日志查看器、排序列表)。关键规则: 标题创建自然的“概览后细节”阅读流程。默认按最可操作的维度排序。
终端会调整大小。您的 TUI 必须优雅地处理。
| 策略 | 时机 |
|---|---|
| 按比例分割 | 调整大小时,面板保持百分比比例 |
| 优先级折叠 | 低于最小宽度时,较不重要的面板首先隐藏 |
| 堆叠 | 面板折叠为仅标题栏,活动面板展开(zellij 模式) |
| 断点模式 | 低于阈值时完全切换布局(例如,多面板 → 单面板) |
| 最小尺寸门限 | 如果低于可用最小值,则显示“终端太小” |
规则:
SIGWINCH。| 应用复杂度 | 推荐模型 |
|---|---|
| 单一用途,<20 个操作 | 直接按键绑定(每个键 = 一个操作) |
| 多视图,复杂 | Vim 风格模式 + 上下文相关页脚 |
| 类 IDE,功能繁多 | 命令面板 + 标签页 + vim 移动 |
| 数据浏览器 | 向下钻取 + 模糊搜索 + : 命令模式 |
按四个渐进层级设计按键绑定:
| 层级 | 按键 | 受众 | 始终显示? |
|---|---|---|---|
| L0: 通用 | 方向键,Enter,Esc,q | 所有人 | 是(页脚) |
| L1: Vim 移动 | hjkl,/,?,:,gg,G | 中级用户 | 是(页脚) |
| L2: 操作 | 单助记符:d(elete),c(ommit),p(ush) | 常规用户 | 在 ? 帮助中显示 |
| L3: 高级 | 组合命令、宏、自定义绑定 | 高级用户 | 仅文档 |
按键绑定约定(通用语言):
j/k — 向下/向上移动h/l — 向左/右移动(或折叠/展开)/ — 搜索? — 帮助覆盖层: — 命令模式q — 退出(或 Esc 返回上一级)Enter — 选择 / 确认 / 深入Tab — 在面板之间切换焦点Space — 切换选择g/G — 跳转到顶部/底部绝不绑定: Ctrl+C(中断),Ctrl+Z(挂起),Ctrl+\(退出信号)。这些属于终端。
通用模式:按 /,输入查询,结果实时筛选。
n/N — 下一个/上一个匹配项Esc — 取消搜索' 前缀用于精确匹配| 层级 | 触发方式 | 内容 | 受众 |
|---|---|---|---|
| 始终可见 | 页脚栏 | 3-5 个基本快捷键 | 所有人 |
| 按需显示 | ? 键 | 当前上下文的完整按键绑定覆盖层 | 常规用户 |
| 文档 | --help,man 手册页 | 完整参考 | 高级用户 |
页脚格式: [q]退出 [/]搜索 [?]帮助 [Tab]焦点 [Enter]选择
上下文相关页脚根据活动面板或模式更新。仅显示 当前 可操作的内容。
| 操作严重性 | 模式 |
|---|---|
| 可逆 | 直接执行,在状态栏显示简短确认 |
| 中等(删除文件) | 内联“按 y 确认” |
| 严重(删除数据库) | 需要输入资源名称的模态对话框 |
| 不可逆批量 | --dry-run 标志 + 显式确认 |
设计需在所有三个层级上优雅降级:
| 层级 | 转义序列 | 颜色 | 策略 |
|---|---|---|---|
| 16 ANSI | \033[31m | 16(相对) | 基础。终端主题控制外观。 |
| 256 色 | \033[38;5;{n}m | 256(16 相对 + 240 固定) | 扩展调色板。固定颜色可能与主题冲突。 |
| 真彩色 | \033[38;2;{r};{g};{b}m | 1670 万(绝对) | 完全控制。需要 COLORTERM=truecolor。 |
检测层次结构:
$COLORTERM = truecolor 或 24bit → 真彩色$TERM 包含 256color → 256 色$NO_COLOR 已设置 → 禁用所有颜色黄金法则: 您的 TUI 必须在 16 色模式下 可用。真彩色用于 增强 —— 它从不 创建 层次结构。
按功能而非外观定义颜色。通过主题将语义映射到实际颜色:
| 槽位 | 用途 | 典型深色主题 |
|---|---|---|
fg.default | 正文文本 | 灰白色 (#c0caf5) |
fg.muted | 次要文本,元数据 | 灰色 (#565f89) |
fg.emphasis | 标题,焦点项 | 亮白色 (#e0e0e0) |
bg.base | 主背景 | 近黑色 (#1a1b26) |
bg.surface | 面板/部件背景 | 稍亮 (#24283b) |
bg.overlay | 弹出框/对话框背景 | 更亮 (#414868) |
bg.selection | 选中项高亮 | 显著不同 (#364a82) |
accent.primary | 交互元素,焦点 | 品牌色 (#7aa2f7) |
accent.secondary | 辅助交互 | 互补色 (#bb9af7) |
status.error | 错误,删除 | 红色 (#f7768e) |
status.warning | 警告,注意 | 黄色 (#e0af68) |
status.success | 成功,添加 | 绿色 (#9ece6a) |
status.info | 信息性 | 青色 (#7dcfff) |
切勿在部件代码中硬编码十六进制值。 始终引用语义槽位。
色彩是众多工具之一。结合使用:
| 技术 | 效果 | 用于 |
|---|---|---|
| 粗体 (SGR 1) | 增加视觉重量 | 标题、标签、活动项 |
| 变暗 (SGR 2) | 减少视觉重量 | 元数据、时间戳、次要信息 |
| 斜体 (SGR 3) | 语义区分 | 注释、类型、注解 |
| 下划线 (SGR 4) | 链接,可操作项 | 可点击元素、URL |
| 反色 (SGR 7) | 交换前景/背景 | 选择高亮(始终有效!) |
| 删除线 (SGR 9) | 否定 | 已删除项,已弃用功能 |
层次结构配方: 80% 的内容使用 fg.default。标题使用粗体 + fg.emphasis。元数据使用变暗 + fg.muted。状态使用其语义颜色。强调色仅用于交互元素。
通过分层背景亮度创建深度,无需边框:
bg.base (最深) → bg.surface → bg.overlay (最浅)
在深色主题中,每一步亮度增加约 5-8%。眼睛通过对比度梯度感知深度。这减少了对盒绘制边框的需求,同时保持了清晰的视觉区域。
遵循 Base16 模式:定义 16 个命名的颜色槽位,将它们映射到语义:
默认提供深色主题。通过 OSC 转义查询或 terminal-light crate 检测浅色/深色终端。至少提供一个浅色变体。尊重 NO_COLOR。
| 元素 | 字符 | 分辨率 | 用于 |
|---|---|---|---|
| 全块 | █▉▊▋▌▍▎▏ | 每单元格 8 级 | 进度条,条形图 |
| 阴影块 | ░▒▓█ | 4 种密度 | 热力图,密度图 |
| 盲文 | ⠁⠂⠃...⣿ (U+2800-U+28FF) | 每单元格 2x4 点 | 高分辨率折线图,散点图 |
| 迷你图 | ▁▂▃▄▅▆▇█ | 8 种高度 | 内联迷你图表 |
| 部件 | 模式 | 技巧 |
|---|---|---|
| 进度条 | [████████░░░░] 67% | 显示百分比 + 预计完成时间。根据紧急程度使用绿→黄→红颜色渐变。 |
| 迷你图 | ▁▂▃▅▇█▇▅▃▂ | 非常适合标题/状态栏中的内联时间序列。 |
| 仪表 | CPU [██████████░░] 83% | 标签 + 条 + 数值。按阈值着色。 |
| 表格 | 可排序列,斑马条纹 | 数字右对齐,文本左对齐。用 … 截断。 |
| 树 | ├── ,└── ,│ 引导线 | 每级缩进 2-4 个字符。用 Enter 展开/折叠。 |
| 差异 | 绿色 + 行,红色 - 行 | 在更改行内进行词级高亮可提升质量。 |
| 日志 | 彩色级别,时间戳,消息 | TRACE=变暗,DEBUG=青色,INFO=默认,WARN=黄色,ERROR=红色,FATAL=红色+粗体。 |
| 上下文 | 旋转器 | 间隔 |
|---|---|---|
| 默认 / 现代 | 盲文点 ⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ | 80ms |
| 极简 | 线条 `- | /` |
| 繁重处理 | 方块 ▖▘▝▗ | 100ms |
| 趣味 / 品牌化 | 自定义帧 | 70-100ms |
对不确定的操作使用旋转器。对确定的操作使用进度条。仅在延迟 200ms 后显示旋转器,以避免快速操作时的闪烁。
三个层级,均为实现平滑 TUI 渲染所必需:
CSI ? 2026 h ... CSI ? 2026 l 中以实现原子性终端渲染write() 系统调用中| 情境 | 动画 | 持续时间 |
|---|---|---|
| 视图切换 | 淡入淡出或滑动 | 100-200ms |
| 选择变更 | 即时高亮 | 0ms(绝不动画) |
| 数据加载 | 旋转器或骨架屏 | 直到完成 |
| 成功反馈 | 短暂闪烁/对勾 | 1-2 秒 |
| 面板调整大小 | 立即重排 | 0ms |
| 图表数据更新 | 平滑数值过渡 | 200-500ms |
规则: 动画绝不能延迟用户输入。如果用户在过渡期间按下按键,立即取消过渡并响应。
键盘优先,鼠标可选 — 每个功能均可通过键盘访问。鼠标用于增强,但绝不替代。Shift+点击 必须绕过鼠标捕获以进行文本选择。
空间一致性 — 面板保持在固定位置。用户建立心理地图。未经用户明确操作,绝不重新排列。标签页提供稳定的地标。
渐进式披露 — 在页脚显示 5 个基本快捷键。完整帮助在 ? 后面。完整参考在文档中。下限是可达的,上限是无限的。
一切皆异步 — 绝不冻结 UI。文件操作、网络请求、扫描全部在后台运行并显示进度指示。用 Esc 取消。
语义色彩 — 色彩编码含义,而非装饰。如果移除所有颜色,界面仍应通过布局、排版和符号 可用。
上下文智能 — 按键绑定按面板更新。状态栏反映当前状态。帮助显示当前可操作的内容,而非所有内容。
分层设计 — 从单色开始(可用吗?)。添加 16 ANSI 颜色(可读吗?)。叠加真彩色(美观吗?)。每个层级必须独立成立。
根据这些按实际投诉频率排序的陷阱验证您的设计:
---|---|---
1 | 颜色在不同终端上失效 | 使用 16 ANSI 颜色作为基础。测试 3+ 个模拟器 + 浅色/深色主题。
2 | 闪烁 / 完全重绘 | 双缓冲 + 同步输出 + 批量写入。覆盖,绝不清除。
3 | 难以发现的按键绑定 | 上下文相关页脚 + ? 帮助覆盖层 + Which-Key 风格提示。
4 | 在 Windows / WSL 上损坏 | 在 Windows Terminal 上测试。避免使用超出盒绘制的高级 Unicode。
5 | Unicode 渲染不一致 | 坚持使用盒绘制 + 块元素。将表情符号限制在 Unicode 9.0。
6 | 终端多路复用器不兼容 | 在 tmux 和 zellij 内部测试。鼠标捕获绝不能破坏选择。
7 | 无无障碍支持 | 尊重 NO_COLOR,提供单色模式,绝不只依赖颜色表达含义。
8 | 操作期间阻塞 UI | 100ms 内显示反馈。使用异步 + 旋转器 + 进度条。
9 | 模态混淆 | 始终在状态栏显示当前模式。光标形状随模式改变。
10 | 过度装饰的界面元素 | 边框和颜色服务于内容,而非自我。内容本身就是界面。
发布前,验证:
NO_COLOR 环境变量Shift+点击)Ctrl+C / SIGINT 时干净退出(恢复终端状态)有关 Unicode 字符参考表和边框样式图库,请参阅 visual-catalog.md。有关真实世界 TUI 应用设计分析和灵感,请参阅 app-patterns.md。
每周安装量
158
代码仓库
GitHub 星标数
2
首次出现
2026 年 2 月 19 日
安全审计
安装于
claude-code148
gemini-cli36
amp36
github-copilot36
codex36
opencode36
Universal design patterns for building exceptional terminal user interfaces. Framework-agnostic — works with Ratatui, Ink, Textual, Bubbletea, or any TUI toolkit.
Core philosophy: TUIs earn their power through spatial consistency, keyboard fluency, and information density that respects human attention. Design for the expert's speed without abandoning the beginner's discoverability.
digraph tui_design {
rankdir=TB;
"What are you building?" [shape=diamond];
"Select layout paradigm" [shape=box];
"Design interaction model" [shape=box];
"Define visual system" [shape=box];
"Validate against anti-patterns" [shape=box];
"Ship it" [shape=doublecircle];
"What are you building?" -> "Select layout paradigm";
"Select layout paradigm" -> "Design interaction model";
"Design interaction model" -> "Define visual system";
"Define visual system" -> "Validate against anti-patterns";
"Validate against anti-patterns" -> "Ship it";
}
Choose your primary layout based on what you're building:
| App Type | Paradigm | Examples |
|---|---|---|
| File manager | Miller Columns | yazi, ranger |
| Git / DevOps tool | Persistent Multi-Panel | lazygit, lazydocker |
| System monitor | Widget Dashboard | btop, bottom, oxker |
| Data browser / K8s | Drill-Down Stack | k9s, diskonaut |
| SQL / HTTP client | IDE Three-Panel | harlequin, posting |
| Shell augmentation | Overlay / Popup | atuin, fzf |
| Log / event viewer | Header + Scrollable List | htop, tig |
All panels visible simultaneously. Focus shifts between them. Users build spatial memory — "branches are always top-left."
┌─ Status ──┬─────────── Detail ──────────┐
├─ Files ───┤ │
│ > file.rs │ diff content here... │
│ main.rs │ │
├─ Branches ┤ │
│ * main │ │
│ feat/x │ │
├─ Commits ─┤ │
│ abc1234 │ │
└───────────┴──────────────────────────────┘
[q]uit [c]ommit [p]ush [?]help
When to use: Multi-faceted tools where users need simultaneous context (git clients, container managers, monitoring). Key rule: Panels maintain fixed positions across sessions. Never rearrange without user action.
Three-pane past/present/future navigation. Parent directory (left), current (center), preview (right).
┌── Parent ──┬── Current ──┬── Preview ────────┐
│ .. │ > config/ │ port: 8080 │
│ src/ │ lib/ │ host: localhost │
│ > config/ │ main.rs │ log_level: debug │
│ tests/ │ mod.rs │ db_url: postgres://│
└────────────┴─────────────┴───────────────────┘
When to use: Hierarchical data navigation (file systems, tree structures, nested configs). Key rule: Preview pane content adapts to selection type — code gets highlighting, images render, directories show contents.
Enter descends, Esc ascends. Browser-like navigation through hierarchical data.
When to use: Deep hierarchies where showing all levels simultaneously is impractical (Kubernetes resources, database schemas). Key rule: Always show the current navigation path as a breadcrumb. Provide :resource command-mode for direct jumps.
Self-contained widget panels with independent data. All information visible at once, no navigation required.
┌─── CPU ──────────────┬─── Memory ──────────┐
│ ▁▂▃▅▇█▇▅▃▂▁▂▃▅▇ │ ████████░░ 78% │
│ core0: 45% core1: 67%│ 12.4G / 16.0G │
├─── Network ──────────┼─── Disk ────────────┤
│ ▲ 1.2 MB/s ▼ 340KB/s│ /: 67% /home: 45% │
├─── Processes ────────┴─────────────────────┤
│ PID USER CPU% MEM% CMD │
│ 1234 root 23.4 4.5 postgres │
└─────────────────────────────────────────────┘
When to use: Monitoring, real-time status, system dashboards. Key rule: Each widget is self-contained with its own title. Use braille/block characters for high-density data.
Sidebar (left), editor/main (center), detail/output (bottom). Tab bar along top.
When to use: Editing-focused tools (SQL clients, HTTP tools, config editors). Key rule: Sidebar toggles with a single key. Center panel supports tabs. Bottom panel can expand to full height.
TUI appears on demand over the shell, disappears after use.
When to use: Shell augmentations (history search, file picker, command palette). Key rule: Configurable height. Return selection to the caller. Never disrupt scrollback.
Fixed header with meters/stats, scrollable data below, function bar at bottom.
When to use: Single-list tools with metadata (process viewers, log viewers, sorted listings). Key rule: The header creates a natural "overview then detail" reading flow. Sort by the most actionable dimension by default.
Terminals resize. Your TUI must handle it gracefully.
| Strategy | When |
|---|---|
| Proportional split | Panels maintain percentage ratios on resize |
| Priority collapse | Less important panels hide first below minimum width |
| Stacking | Panels collapse to title-only bars, active one expands (zellij pattern) |
| Breakpoint modes | Switch layout entirely below a threshold (e.g., multi-panel → single panel) |
| Minimum size gate | Display "terminal too small" if below usable minimum |
Rules:
SIGWINCH gracefully.| App Complexity | Recommended Model |
|---|---|
| Single-purpose, <20 actions | Direct keybinding (every key = action) |
| Multi-view, complex | Vim-style modes + contextual footer |
| IDE-like, many features | Command palette + tabs + vim motions |
| Data browser | Drill-down + fuzzy search + : command mode |
Design keybindings in four progressive layers:
| Layer | Keys | Audience | Always show? |
|---|---|---|---|
| L0: Universal | Arrow keys, Enter, Esc, q | Everyone | Yes (footer) |
| L1: Vim motions | hjkl, /, ?, :, gg, G | Intermediate | Yes (footer) |
| L2: Actions | Single mnemonics: d(elete), c(ommit), p(ush) | Regular users | On ? help |
| L3: Power | Composed commands, macros, custom bindings | Power users | Docs only |
Keybinding conventions (lingua franca):
j/k — move down/uph/l — move left/right (or collapse/expand)/ — search? — help overlay: — command modeq — quit (or Esc to go back one level)Enter — select / confirm / drill inTab — switch focus between panelsNever bind: Ctrl+C (interrupt), Ctrl+Z (suspend), Ctrl+\ (quit signal). These belong to the terminal.
The universal pattern: press /, type query, results filter live.
n/N — next/previous matchEsc — dismiss search' prefix for exact match| Tier | Trigger | Content | Audience |
|---|---|---|---|
| Always visible | Footer bar | 3-5 essential shortcuts | Everyone |
| On demand | ? key | Full keybinding overlay for current context | Regular users |
| Documentation | --help, man page | Complete reference | Power users |
Footer format: [q]uit [/]search [?]help [Tab]focus [Enter]select
Context-sensitive footers update based on the active panel or mode. Show only what's actionable right now.
| Action Severity | Pattern |
|---|---|
| Reversible | Just do it, show brief confirmation in status bar |
| Moderate (delete file) | Inline "Press y to confirm" |
| Severe (drop database) | Modal dialog requiring resource name input |
| Irreversible batch | --dry-run flag + explicit confirmation |
Design for graceful degradation across all three tiers:
| Tier | Escape Sequence | Colors | Strategy |
|---|---|---|---|
| 16 ANSI | \033[31m | 16 (relative) | Foundation. Terminal theme controls appearance. |
| 256 Color | \033[38;5;{n}m | 256 (16 relative + 240 fixed) | Extended palette. Fixed colors may clash with themes. |
| True Color | \033[38;2;{r};{g};{b}m | 16.7M (absolute) | Full control. Requires COLORTERM=truecolor. |
Detection hierarchy:
$COLORTERM = truecolor or 24bit → true color$TERM contains 256color → 256 colors$NO_COLOR is set → disable all colorGolden rule: Your TUI must be usable in 16-color mode. True color enhances — it never creates the hierarchy.
Define colors by function, not appearance. Map semantics to actual colors through your theme:
| Slot | Purpose | Typical Dark Theme |
|---|---|---|
fg.default | Body text | Off-white (#c0caf5) |
fg.muted | Secondary text, metadata | Gray (#565f89) |
fg.emphasis | Headers, focused items | Bright white (#e0e0e0) |
bg.base | Primary background | Near-black (#1a1b26) |
bg.surface | Panel/widget backgrounds |
Never hardcode hex values in widget code. Always reference semantic slots.
Color is one tool among several. Use them in combination:
| Technique | Effect | Use For |
|---|---|---|
| Bold (SGR 1) | Increases visual weight | Headers, labels, active items |
| Dim (SGR 2) | Decreases visual weight | Metadata, timestamps, secondary info |
| Italic (SGR 3) | Semantic distinction | Comments, types, annotations |
| Underline (SGR 4) | Links, actionable items | Clickable elements, URLs |
| Reverse (SGR 7) | Swaps fg/bg | Selection highlight (always works!) |
| Strikethrough (SGR 9) | Negation | Deleted items, deprecated features |
Hierarchy recipe: 80% of content in fg.default. Headers in bold + fg.emphasis. Metadata in dim + fg.muted. Status in their semantic colors. Accents for interactive elements only.
Create depth without borders by layering background lightness:
bg.base (darkest) → bg.surface → bg.overlay (lightest)
Each step ~5-8% lighter in dark themes. The eye perceives depth from the contrast gradient. This reduces the need for box-drawing borders while maintaining clear visual zones.
Follow the Base16 pattern: define 16 named color slots, map them semantically:
Ship a dark theme by default. Detect light/dark terminal via OSC escape query or terminal-light crate. Provide at least one light variant. Respect NO_COLOR.
| Element | Characters | Resolution | Use For |
|---|---|---|---|
| Full blocks | █▉▊▋▌▍▎▏ | 8 steps/cell | Progress bars, bar charts |
| Shade blocks | ░▒▓█ | 4 densities | Heatmaps, density plots |
| Braille | ⠁⠂⠃...⣿ (U+2800-U+28FF) | 2x4 dots/cell | High-res line graphs, scatter plots |
| Sparkline | ▁▂▃▄▅▆▇█ |
| Widget | Pattern | Tips |
|---|---|---|
| Progress bar | [████████░░░░] 67% | Show percentage + ETA. Color gradient green→yellow→red by urgency. |
| Sparkline | ▁▂▃▅▇█▇▅▃▂ | Perfect for inline time-series in headers/status bars. |
| Gauge | CPU [██████████░░] 83% | Label + bar + value. Color by threshold. |
| Table | Sortable columns, zebra stripes | Align numbers right, text left. Truncate with …. |
| Context | Spinner | Interval |
|---|---|---|
| Default / modern | Braille dots ⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ | 80ms |
| Minimal | Line `- | /` |
| Heavy processing | Blocks ▖▘▝▗ | 100ms |
| Fun / branded | Custom frames | 70-100ms |
Use spinners for indeterminate operations. Progress bars for determinate. Show spinners only after 200ms delay to avoid flash on fast operations.
Three layers, all required for smooth TUI rendering:
CSI ? 2026 h ... CSI ? 2026 l for atomic terminal renderwrite() syscall| Situation | Animation | Duration |
|---|---|---|
| View transition | Fade or slide | 100-200ms |
| Selection change | Instant highlight | 0ms (never animate) |
| Data loading | Spinner or skeleton | Until complete |
| Success feedback | Brief flash/checkmark | 1-2 seconds |
| Panel resize | Immediate reflow | 0ms |
| Chart data update | Smooth value transition | 200-500ms |
Rule: Animations must never delay user input. If the user presses a key during a transition, cancel it and respond immediately.
Keyboard-first, mouse-optional — Every feature accessible via keyboard. Mouse enhances but never replaces. Shift+click must bypass mouse capture for text selection.
Spatial consistency — Panels stay in fixed positions. Users build mental maps. Never rearrange without explicit user action. Tabs provide stable landmarks.
Progressive disclosure — Show 5 essential shortcuts in the footer. Full help behind ?. Complete reference in docs. The floor is accessible, the ceiling is unlimited.
Async everything — Never freeze the UI. File operations, network requests, scans all run in the background with progress indication. Cancel with Esc.
Semantic color — Color encodes meaning, not decoration. If you removed all color, the interface should still be usable through layout, typography, and symbols.
Contextual intelligence — Keybindings update per panel. Status bars reflect current state. Help shows what's actionable right now, not everything ever.
Design in layers — Start monochrome (usable?). Add 16 ANSI colors (readable?). Layer true color (beautiful?). Each tier must stand independently.
Validate your design against these ranked pitfalls (ordered by real-world complaint frequency):
---|---|---
1 | Colors break on different terminals | Use 16 ANSI colors as foundation. Test 3+ emulators + light/dark themes.
2 | Flickering / full redraws | Double buffer + synchronized output + batched writes. Overwrite, never clear.
3 | Undiscoverable keybindings | Context-sensitive footer + ? help overlay + Which-Key-style hints.
4 | Broken on Windows / WSL | Test on Windows Terminal. Avoid advanced Unicode beyond box-drawing.
5 | Unicode rendering inconsistency | Stick to box-drawing + block elements. Restrict emoji to Unicode 9.0.
6 | Terminal multiplexer incompatibility | Test inside tmux and zellij. Mouse capture must not break selection.
7 | No accessibility support | Respect NO_COLOR, provide monochrome mode, never color-only meaning.
8 | Blocking UI during operations | Show feedback within 100ms. Use async + spinners + progress bars.
9 | Modal confusion | Always show current mode in status bar. Cursor shape changes per mode.
10 | Over-decorated chrome | Borders and colors serve content, not ego. The content IS the interface.
Before shipping, verify:
NO_COLOR environment variableShift+click)Ctrl+C / SIGINT (restores terminal state)For Unicode character reference tables and border style gallery, see visual-catalog.md. For real-world TUI app design analysis and inspiration, see app-patterns.md.
Weekly Installs
158
Repository
GitHub Stars
2
First Seen
Feb 19, 2026
Security Audits
Gen Agent Trust HubFailSocketPassSnykPass
Installed on
claude-code148
gemini-cli36
amp36
github-copilot36
codex36
opencode36
前端打磨(Polish)终极指南:提升产品细节与用户体验的系统化检查清单
41,400 周安装
联盟营销页面生成器 - 创建高转化联盟计划页面的AI工具 | 营销自动化
298 周安装
OpenCode Primitives 技能:官方文档集成与UI一致性保障工具
322 周安装
tldr-overview:快速获取项目代码概览,高效理解陌生代码库结构
228 周安装
iOS应用开发指南:XcodeGen与Swift Package Manager构建部署解决方案
231 周安装
Agentica SDK 中文指南:Python AI 智能体开发框架,支持多智能体编排与工具集成
222 周安装
Git提交助手 - 自动化代码提交与变更管理工具 | 提升开发效率
228 周安装
Space — toggle selectiong/G — jump to top/bottom| Slightly lighter (#24283b) |
bg.overlay | Popup/dialog backgrounds | Lighter still (#414868) |
bg.selection | Selected item highlight | Distinct (#364a82) |
accent.primary | Interactive elements, focus | Brand color (#7aa2f7) |
accent.secondary | Supporting interactions | Complementary (#bb9af7) |
status.error | Errors, deletions | Red (#f7768e) |
status.warning | Warnings, caution | Yellow (#e0af68) |
status.success | Success, additions | Green (#9ece6a) |
status.info | Informational | Cyan (#7dcfff) |
| 8 heights |
| Inline mini-charts |
├── , └── , │ guides |
| Indent 2-4 chars per level. Expand/collapse with Enter. |
| Diff | Green + lines, red - lines | Word-level highlighting within changed lines elevates quality. |
| Log | Colored level, timestamp, message | TRACE=dim, DEBUG=cyan, INFO=default, WARN=yellow, ERROR=red, FATAL=red+bold. |