opentui
Original:🇺🇸 English
Translated
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.
1installs
Sourceainergiz/xfeed
Added on
NPX Install
npx skill4agent add ainergiz/xfeed opentuiTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →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: (run
.context/repos/opentuiif missing)bun run sync-context
Core Imports
typescript
import { useKeyboard, useRenderer, useTerminalDimensions } from "@opentui/react";
import type { ScrollBoxRenderable, KeyEvent } from "@opentui/core";JSX Elements (Lowercase!)
tsx
// CORRECT - OpenTUI intrinsics
<box style={{ flexDirection: "column" }}>
<text fg="#ffffff">Hello</text>
<scrollbox ref={scrollRef} focused />
</box>
// WRONG - Not OpenTUI
<div>, <span>, <Box>, <Text>| Element | Purpose | Key Props |
|---|---|---|
| Container/layout | |
| Text content (strings only!) | |
| Scrollable container | |
| Hyperlink (OSC8) | |
| Text input | |
| Multi-line input | |
Critical Rules
1. Text Only Accepts Strings
tsx
// WRONG - Cannot nest elements in <text>
<text>Hello <text fg="red">world</text></text>
// CORRECT - Use row box for inline styling
<box style={{ flexDirection: "row" }}>
<text>Hello </text>
<text fg="red">world</text>
</box>2. Always Check focused
in Keyboard Handlers
focusedtsx
useKeyboard((key) => {
if (!focused) return; // MUST check first!
if (key.name === "j") moveDown();
});3. Save Scroll Position Synchronously
tsx
// WRONG - useEffect runs after render, scroll already reset
useEffect(() => { if (!focused) savedScroll.current = scrollRef.current?.scrollTop; }, [focused]);
// CORRECT - Save before state change
const handleSelect = () => {
savedScroll.current = scrollRef.current?.scrollTop; // Save first!
onSelect(item);
};Hyperlinks (New in 0.1.64+)
tsx
<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 | | |
|---|---|---|---|---|
| Enter | | Arrows | | |
| Escape | | Letters | | |
| Tab | | Shift+Letter | |
Scrollbox API
typescript
const scrollbox = scrollRef.current;
scrollbox.scrollTop // Current position
scrollbox.scrollHeight // Total content height
scrollbox.viewport.height // Visible area
scrollbox.scrollTo(pos) // Absolute scroll
scrollbox.scrollBy(delta) // Relative scroll
scrollbox.getChildren() // Find elements by IDCommon Layout Patterns
tsx
// Full-height with fixed header/footer
<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>
// Prevent unwanted spacing (Yoga quirk)
<box style={{ justifyContent: "flex-start", marginBottom: 0, paddingBottom: 0 }}>React DevTools (Optional)
bash
bun add --dev react-devtools-core@7
npx react-devtools@7 # Start standalone devtools
DEV=true bun run start # Run app with devtools enabledDetailed 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
- - Screen routing, navigation history
src/app.tsx - - Scrollbox with preservation
src/components/PostList.tsx - - Component styling, mouse handling
src/components/PostCard.tsx - - Windowed list pattern
src/modals/FolderPicker.tsx - - Vim-style navigation
src/hooks/useListNavigation.ts