opentui
Terminal UI library written in Zig with TypeScript bindings. Trigger: When building TUIs, terminal interfaces, or using OpenTUI with React/Solid.
- License 许可
- Apache-2.0
- 最近更新
- 2026-08-26
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- opentui
- license
- Apache-2.0
- metadata
- { "author": "gentleman-programming", "version": "1.0" }
- description
- Terminal UI library written in Zig with TypeScript bindings. Trigger: When building TUIs, terminal interfaces, or using OpenTUI with React/Solid.
02 资源文件 30
- 参考文档.skill-meta.json431 B
- 脚本assets/01-example.rs23 B
- 参考文档README.md431 B
- 参考文档references/01-intro.md33 B
- 参考文档references/02-advanced.md38 B
- 参考文档references/animation/REFERENCE.md8.4 KB
- 参考文档references/components/code-diff.md13.1 KB
- 参考文档references/components/containers.md7.4 KB
- 参考文档references/components/inputs.md10.1 KB
- 参考文档references/components/REFERENCE.md4.0 KB
- 参考文档references/components/text-display.md7.1 KB
- 参考文档references/core/api.md14.2 KB
- 参考文档references/core/configuration.md4.5 KB
- 参考文档references/core/gotchas.md7.6 KB
- 参考文档references/core/patterns.md8.6 KB
- 参考文档references/core/REFERENCE.md4.2 KB
- 参考文档references/keyboard/REFERENCE.md13.9 KB
- 参考文档references/layout/patterns.md8.3 KB
- 参考文档references/layout/REFERENCE.md6.0 KB
- 参考文档references/react/api.md8.7 KB
- 参考文档references/react/configuration.md5.9 KB
- 参考文档references/react/gotchas.md8.3 KB
- 参考文档references/react/patterns.md9.7 KB
- 参考文档references/react/REFERENCE.md4.4 KB
- 参考文档references/solid/api.md10.7 KB
- 参考文档references/solid/configuration.md5.7 KB
- 参考文档references/solid/gotchas.md7.8 KB
- 参考文档references/solid/patterns.md10.9 KB
- 参考文档references/solid/REFERENCE.md5.0 KB
- 参考文档references/testing/REFERENCE.md12.5 KB
03 SKILL.md 正文
When to Use
- Building terminal user interfaces (TUIs) in TypeScript
- Creating CLI tools with rich UI (like htop, lazygit)
- TUI dashboards, editors, or interactive terminal apps
- Using React or SolidJS for terminal UIs
- Any terminal-based application with mouse/keyboard interaction
Installation
# TypeScript/JavaScript
bun install @opentui/core
# Or with npm
npm install @opentui/core
Quick Start
import { createCliRenderer, Text } from "@opentui/core"
const renderer = await createCliRenderer()
renderer.root.add(
Text({
content: "Hello, OpenTUI!",
fg: "#00FF00",
})
)
Core Components
Text
import { Text } from "@opentui/core"
Text({
content: "Hello World",
fg: "#00FF00", // foreground color
bg: "#000000", // background color
bold: true, // bold text
italic: true, // italic text
underline: true, // underline
})
Box (Container)
import { Box, Text } from "@opentui/core"
Box({
width: 100, // or "100%", "auto"
height: "100%",
flexDirection: "row", // "column" | "row"
gap: 2, // gap between children
padding: 4,
margin: 2,
backgroundColor: "#1a1b26",
borderStyle: "round", // "round" | "single" | "double"
},
Text({ content: "Content" })
)
Input
import { Input } from "@opentui/core"
const input = Input({
placeholder: "Type something...",
width: 30,
value: "",
onChange: (value) => console.log(value),
})
input.focus()
Select
import { Select } from "@opentui/core"
Select({
options: [
{ label: "Option 1", value: "1" },
{ label: "Option 2", value: "2" },
],
defaultValue: "1",
onChange: (value) => console.log(value),
})
ScrollBox
import { ScrollBox, Text } from "@opentui/core"
ScrollBox({
width: 50,
height: 20,
showScrollbar: true,
},
Text({ content: "Long content..." })
)
Code (with syntax highlighting)
import { Code } from "@opentui/core"
Code({
code: `function hello() {
console.log("Hello");
}`,
language: "typescript", // or "javascript", "rust", "python", etc.
width: "100%",
height: "100%",
})
Diff
import { Diff } from "@opentui/core"
Diff({
oldCode: "const a = 1;",
newCode: "const a = 2;",
language: "typescript",
})
Layout System (Flexbox)
import { Box } from "@opentui/core"
// Row layout with sidebar
Box(
{
width: "100%",
height: "100%",
flexDirection: "row",
gap: 2
},
Box(
{ flexGrow: 1, backgroundColor: "#1a1b26" },
Text({ content: "Sidebar" })
),
Box(
{ flexGrow: 3, backgroundColor: "#24283b" },
Text({ content: "Main" })
)
)
// Center content
Box({
width: "100%",
height: "100%",
display: "flex",
justifyContent: "center",
alignItems: "center",
}, Text({ content: "Centered" }))
Keyboard Handling
import { Box, Input } from "@opentui/core"
// Global keyboard handler
Box({
width: "100%",
height: "100%",
onKeyDown: (key) => {
if (key === "q") {
// Quit
}
if (key === "ctrl-c") {
// Handle Ctrl+C
}
},
})
Focus Management
import { Input, Button } from "@opentui/core"
// Tab navigation between elements
const input = Input({ placeholder: "Name" })
const button = Button({ label: "Submit" })
// Focus next on Enter
input.onKeyDown = (key) => {
if (key === "Enter") {
button.focus()
}
}
React Integration
import { createRenderer } from "@opentui/react"
function App() {
return (
<Box width="100%" height="100%">
<Text>Hello React!</Text>
</Box>
)
}
const renderer = createRenderer(<App />)
renderer.mount()
SolidJS Integration
import { createRenderer } from "@opentui/solid"
function App() {
return (
<Box width="100%" height="100%">
<Text>Hello Solid!</Text>
</Box>
)
}
const renderer = createRenderer(<App />)
renderer.mount()
Animations
import { Timeline, Text } from "@opentui/core"
const timeline = new Timeline()
timeline.add(
Text({ content: "Fade in" }),
{ opacity: { from: 0, to: 1 }, duration: 300 }
)
timeline.play()
CLI Commands
# Create new TUI app
bun create tui
# Run examples
cd packages/core
bun run src/examples/index.ts
# Install system dependencies (Linux/macOS)
curl -fsSL https://raw.githubusercontent.com/anomalyco/opentui/main/packages/core/src/examples/install.sh | sh
Environment Variables
| Variable | Description | Default |
|---|---|---|
OPENTUI_LOG |
Log level | info |
OPENTUI_THEME |
Color theme | default |
OPENTUI_FONT |
Font family | monospace |
Resources
See references/ for detailed guides and code examples in assets/.
External Resources
- [Official Documentation]
Packages
| Package | Description |
|---|---|
@opentui/core |
TypeScript bindings, imperative API |
@opentui/react |
React reconciler |
@opentui/solid |
SolidJS reconciler |
Comparison: OpenTUI vs Ratatui
| Feature | OpenTUI | Ratatui |
|---|---|---|
| Language | Zig (native) | Rust |
| TS Bindings | ✅ First-class | ❌ No |
| React/Solid | ✅ Built-in | ❌ No |
| Flexbox Layout | ✅ Yoga | ❌ Manual |
| Tree-sitter | ✅ Built-in | ❌ No |
| Animation API | ✅ Timeline | ❌ Basic |
| Learning Curve | Lower | Higher |
04 同仓库更多 Skills
zustand-5
Zustand 5 state management patterns. Trigger: When managing React state with Zustand.
zod-4
Zod 4 schema validation patterns. Trigger: When using Zod for validation - breaking changes from v3.
x-bookmark-quote-posts
Workflow para revisar bookmarks de X/Twitter y convertirlos en drafts de quote posts. Accede a la sección de bookmarks vía browser headless, extrae posts recientes, y genera drafts con voz personal del usuario. No publica ni muta X — solo genera contenido para revisión. Trigger: X bookmarks, Twitter bookmarks, quote posts, bookmark automation, crear quote posts, revisar bookmarks, growth content X.
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
writing-plans
Use when you have a spec or requirements for a multi-step task, before touching code
work-unit-commits
Plan commits as reviewable work units. Trigger: implementation, commit splitting, chained PRs, or keeping tests and docs with code.