Installation
Quick start with create-tui:
TypeScript Configuration
Configure yourtsconfig.json for optimal TypeScript support:
tsconfig.json
Basic Usage
Create and render a simple React application:index.tsx
Rendering
createRoot
Creates a root for rendering a React tree with a CLI renderer.renderer- ACliRendererinstance created withcreateCliRenderer()
render(node)- Renders a React elementunmount()- Unmounts the React tree
createPortal
Render children into a different part of the component tree:Core Hooks
useRenderer
Access the OpenTUI renderer instance:useKeyboard
Handle keyboard input with press and release events:handler- Callback receiving aKeyEventobjectoptions?- Optional configuration:release?: boolean- Include key release events (default:false)
By default, only press events are received (including repeats with
repeated: true). Set options.release = true to also receive release events.useOnResize
Handle terminal resize events:useTerminalDimensions
Get current terminal dimensions with automatic updates:{ width: number, height: number }
useTimeline
Create and manage animations using OpenTUI’s timeline system:options?- OptionalTimelineOptions:duration?: number- Animation duration in ms (default: 1000)loop?: boolean- Whether to loop (default: false)autoplay?: boolean- Auto-start timeline (default: true)onComplete?: () => void- Completion callbackonPause?: () => void- Pause callback
Timeline instance with methods:
add(target, properties, startTime)- Add animationplay()- Start timelinepause()- Pause timelinerestart()- Restart from beginning
Components
OpenTUI React provides intrinsic JSX elements that map to OpenTUI renderables:Layout & Display
<text>- Display styled text<box>- Container with borders and layout<scrollbox>- Scrollable container<ascii-font>- ASCII art text renderer
Input Components
<input>- Single-line text input<textarea>- Multi-line text input<select>- Dropdown selection<tab-select>- Tab-based selection
Code & Diff
<code>- Syntax-highlighted code blocks<line-number>- Line-numbered code with diff/diagnostics<diff>- Unified or split diff viewer
Text Modifiers
<span>- Inline styled text<strong>,<b>- Bold text<em>,<i>- Italic text<u>- Underlined text<br>- Line break<a>- Link withhrefattribute
Examples
Login Form
Animated System Monitor
Extending Components
Create custom components by extending OpenTUI’s base renderables:React DevTools
OpenTUI React supports React DevTools for debugging:- Install the optional peer dependency:
- Start the standalone DevTools:
- Run your app with the
DEVenvironment variable: