Skip to main content
OpenTUI React is a custom React reconciler that lets you build terminal user interfaces using familiar React patterns, hooks, and components.

Installation

Quick start with create-tui:

TypeScript Configuration

Configure your tsconfig.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.
Parameters:
  • renderer - A CliRenderer instance created with createCliRenderer()
Returns: An object with:
  • render(node) - Renders a React element
  • unmount() - 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:
Parameters:
  • handler - Callback receiving a KeyEvent object
  • options? - 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:
Returns: { width: number, height: number }

useTimeline

Create and manage animations using OpenTUI’s timeline system:
Parameters:
  • options? - Optional TimelineOptions:
    • 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 callback
    • onPause?: () => void - Pause callback
Returns: Timeline instance with methods:
  • add(target, properties, startTime) - Add animation
  • play() - Start timeline
  • pause() - Pause timeline
  • restart() - 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

These elements must be used inside a <text> component:
  • <span> - Inline styled text
  • <strong>, <b> - Bold text
  • <em>, <i> - Italic text
  • <u> - Underlined text
  • <br> - Line break
  • <a> - Link with href attribute
See the Components section for detailed documentation on each component.

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:
  1. Install the optional peer dependency:
  1. Start the standalone DevTools:
  1. Run your app with the DEV environment variable:
After the app starts, you’ll see the component tree in React DevTools. You can inspect and modify props in real-time.
When DevTools is connected, the WebSocket connection may prevent your process from exiting naturally. Use process.exit() or close DevTools to terminate the process.