Overview
TheCliRenderer 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
Creating a Renderer
UsecreateCliRenderer() to initialize the renderer:
Configuration Options
The renderer accepts aCliRendererConfig 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:Renderer States
The renderer tracks its state throughcontrolState:
Cleanup
Always destroy the renderer when done:- Terminal state (restores normal mode)
- Event listeners
- Child renderables
- Native resources
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:- Uses flexbox column layout by default
- Automatically resizes with the terminal
- Manages the global layout tree
Input Handling
Keyboard Input
Access keyboard events through thekeyInput handler:
Kitty Keyboard Protocol
Enable enhanced keyboard support:Mouse Input
Mouse events bubble up through the renderable tree:Rendering Loop
The rendering process follows these steps:- Lifecycle Pass - Run registered lifecycle callbacks
- Layout Calculation - Calculate Yoga flexbox layout from root
- Update Pass - Update renderables and collect render commands
- Render Pass - Execute render commands on the buffer