Skip to main content

Overview

The CliRenderer is the core component that orchestrates your entire terminal UI. It manages:
  • Terminal output and rendering
  • Input events (keyboard and mouse)
  • The rendering loop and frame timing
  • Layout calculations
  • Focus management
Think of it as the canvas that draws your interface to the terminal.

Creating a Renderer

Use createCliRenderer() to initialize the renderer:

Configuration Options

The renderer accepts a CliRendererConfig object with these options:
By default, left-clicking auto-focuses the closest focusable renderable. Disable this with autoFocus: false for manual focus control.

Lifecycle

Rendering Modes

The renderer can operate in two modes: 1. On-Demand Mode (Default) Only re-renders when the renderable tree or layout changes:
2. Live Mode Runs a continuous loop at the specified target FPS:

Renderer States

The renderer tracks its state through controlState:

Cleanup

Always destroy the renderer when done:
This cleans up:
  • Terminal state (restores normal mode)
  • Event listeners
  • Child renderables
  • Native resources
Failing to call destroy() may leave the terminal in an altered state.

Theme Mode Detection

OpenTUI can detect the terminal’s preferred color scheme when the terminal supports DEC mode 2031:

Example: Adaptive Colors

If the terminal doesn’t support theme detection, themeMode will be null and no events will fire.

Root Renderable

Every renderer has a root renderable that represents the entire terminal viewport:
The root:
  • Uses flexbox column layout by default
  • Automatically resizes with the terminal
  • Manages the global layout tree

Input Handling

Keyboard Input

Access keyboard events through the keyInput handler:

Kitty Keyboard Protocol

Enable enhanced keyboard support:

Mouse Input

Mouse events bubble up through the renderable tree:
Mouse can be disabled:

Rendering Loop

The rendering process follows these steps:
  1. Lifecycle Pass - Run registered lifecycle callbacks
  2. Layout Calculation - Calculate Yoga flexbox layout from root
  3. Update Pass - Update renderables and collect render commands
  4. Render Pass - Execute render commands on the buffer

Frame Callbacks

Register callbacks that run every frame:

Post-Processing

Apply effects after rendering:

Viewport & Dimensions

Advanced Features

Split Screen Mode

Reserve the bottom portion of the terminal for output:

Focus Management

Debug Overlay

Toggle the performance overlay:

Clipboard (OSC 52)

Performance

Idle Detection

Wait for the renderer to become idle:

Stats Gathering

API Reference

Properties

Methods

Events