| name | opentui |
| description | Build terminal UIs with OpenTUI/React. Use when creating screens, components, handling keyboard input, managing scroll, or navigating between views. Covers JSX intrinsics, useKeyboard, scrollbox patterns, and state preservation. |
OpenTUI/React Quick Reference
OpenTUI is a React renderer for terminal UIs using Yoga layout (like React Native). NOT React DOM or Ink.
Version Info
- Current: 0.1.69 (updated), Latest: 0.1.69
- Context repo:
.context/repos/opentui (run bun run sync-context if missing)
Core Imports
import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/react";
import type { ScrollBoxRenderable, KeyEvent } from "@opentui/core";
JSX Elements (Lowercase!)
<box style={{ flexDirection: "column" }}>
<text fg="#ffffff">Hello</text>
<scrollbox ref={scrollRef} focused />
</box>
<div>, <span>, <Box>, <Text>
| Element | Purpose | Key Props |
|---|
<box> | Container/layout | style, id, onMouse |
<text> | Text content (strings only!) | fg, bg, selectable |
<scrollbox> | Scrollable container | ref, focused |
<a> | Hyperlink (OSC8) | href, fg |
<input> | Text input | focused, onInput, onSubmit |
<textarea> | Multi-line input | ref, focused, placeholder |
Critical Rules
1. Text Only Accepts Strings
<text>Hello <text fg="red">world</text></text>
<box style={{ flexDirection: "row" }}>
<text>Hello </text>
<text fg="red">world</text>
</box>
2. Always Check focused in Keyboard Handlers
useKeyboard((key) => {
if (!focused) return;
if (key.name === "j") moveDown();
});
3. Save Scroll Position Synchronously
useEffect(() => { if (!focused) savedScroll.current = scrollRef.current?.scrollTop; }, [focused]);
const handleSelect = () => {
savedScroll.current = scrollRef.current?.scrollTop;
onSelect(item);
};
Hyperlinks (New in 0.1.64+)
<text>
Visit <a href="https://example.com">example.com</a> for more
</text>
Renders clickable links in terminals supporting OSC8 (iTerm2, Kitty, etc.).
Key Names
| Key | key.name | | Key | key.name |
|---|
| Enter | "return" | | Arrows | "up", "down", "left", "right" |
| Escape | "escape" | | Letters | "a", "b", "j", "k" |
| Tab | "tab" | | Shift+Letter | "A", "B", "G" |
Scrollbox API
const scrollbox = scrollRef.current;
scrollbox.scrollTop
scrollbox.scrollHeight
scrollbox.viewport.height
scrollbox.scrollTo(pos)
scrollbox.scrollBy(delta)
scrollbox.getChildren()
Common Layout Patterns
<box style={{ flexDirection: "column", height: "100%" }}>
<box style={{ flexShrink: 0 }}>{/* Header */}</box>
<scrollbox style={{ flexGrow: 1 }}>{/* Content */}</scrollbox>
<box style={{ flexShrink: 0 }}>{/* Footer */}</box>
</box>
<box style={{ justifyContent: "flex-start", marginBottom: 0, paddingBottom: 0 }}>
React DevTools (Optional)
bun add --dev react-devtools-core@7
npx react-devtools@7
DEV=true bun run start
Detailed References
- COMPONENTS.md - JSX elements, styling, text nesting
- KEYBOARD.md - Keyboard handling, key names, focus patterns
- SCROLLBOX.md - Scrollbox API, scroll preservation, windowed lists
- LAYOUT.md - Flex layout, Yoga engine, spacing issues
- PATTERNS.md - Screen navigation, state preservation, library compatibility
xfeed Reference Files
src/app.tsx - Screen routing, navigation history
src/components/PostList.tsx - Scrollbox with preservation
src/components/PostCard.tsx - Component styling, mouse handling
src/modals/FolderPicker.tsx - Windowed list pattern
src/hooks/useListNavigation.ts - Vim-style navigation