Overview
TheCliRenderer class is the core of OpenTUI’s rendering system. It manages the render loop, handles terminal I/O, processes user input, and provides the rendering context for all UI elements.
Creating a Renderer
createCliRenderer()
Creates and initializes a new CLI renderer instance.CliRendererConfig
Configuration options for the renderer
Promise<CliRenderer>
Returns a fully initialized renderer instance
Example
Configuration Options
CliRendererConfig
Configuration interface for renderer initialization.NodeJS.ReadStream
Custom stdin stream (defaults to
process.stdin)NodeJS.WriteStream
Custom stdout stream (defaults to
process.stdout)boolean
Enable remote terminal mode
boolean
Enable testing mode (skips terminal setup)
boolean
default:true
Exit the process when Ctrl+C is pressed
NodeJS.Signals[]
Custom list of signals that trigger exit
string[]
Environment variables to forward to the renderer
number
default:100
Debounce delay for resize events (in milliseconds)
number
default:30
Target frames per second for rendering
number
default:60
Maximum frames per second (caps render rate)
number
Interval for taking memory snapshots (in milliseconds)
boolean
default:true
Use threading for render operations (disabled on Linux)
boolean
Collect rendering statistics
number
default:300
Maximum number of stat samples to keep
ConsoleOptions
Configuration for the console overlay
((buffer: OptimizedBuffer, deltaTime: number) => void)[]
Post-processing functions to apply after rendering
boolean
default:true
Enable mouse movement events
boolean
default:true
Enable mouse input
boolean
default:true
Automatically focus elements on mouse click
boolean
default:true
Use alternate screen buffer
boolean
default:true
Enable console overlay
number
Split screen mode height (experimental)
KittyKeyboardOptions | null
Kitty keyboard protocol options
ColorInput
Background color for the renderer
boolean
Automatically open console on uncaught errors
((sequence: string) => boolean)[]
Input handlers to prepend to the handler chain
() => void
Callback invoked when the renderer is destroyed
Kitty Keyboard Protocol
KittyKeyboardOptions
Configuration for the Kitty keyboard protocol, which provides enhanced key event handling.boolean
default:true
Disambiguate escape codes (fixes ESC timing, alt+key ambiguity, ctrl+c as event)
boolean
default:true
Report alternate keys (numpad, shifted, base layout) for cross-keyboard shortcuts
boolean
default:false
Report event types (press/repeat/release)
boolean
default:false
Report all keys as escape codes
boolean
default:false
Report text associated with key events
CliRenderer Class
Properties
RootRenderable
The root renderable element (container for all UI elements)
number
Current renderer width in terminal cells
number
Current renderer height in terminal cells
number
Full terminal width (may differ from
width in split mode)number
Full terminal height (may differ from
height in split mode)TerminalConsole
Console overlay instance for logging and debugging
KeyHandler
Key input handler for keyboard events
boolean
Whether the renderer is currently in a running state
boolean
Whether the renderer has been destroyed
boolean
Whether mouse input is enabled (can be set to toggle)
boolean
Whether console overlay is enabled (can be set to toggle)
any | null
Terminal capabilities detected from the terminal
PixelResolution | null
Terminal pixel resolution (if available)
ThemeMode | null
Terminal theme mode (light/dark)
Methods
requestRender()
Request a render pass. The renderer will schedule a render based on the current FPS settings.requestLive()
Request continuous rendering (starts the render loop).dropLive()
Stop continuous rendering (stops the render loop).start()
Explicitly start the renderer.pause()
Pause the renderer (can be resumed).suspend()
Suspend the renderer (similar to pause but different state).resume()
Resume the renderer after pause/suspend.idle()
Wait for the renderer to become idle (no pending renders).Promise<void>
Resolves when the renderer is idle
destroy()
Clean up and destroy the renderer. This should be called when shutting down.setBackgroundColor()
Set the background color for the renderer.ColorInput
Color value (hex string, RGBA object, or RGBA instance)
setCursorPosition()
Set the cursor position.number
X coordinate (column)
number
Y coordinate (row)
boolean
default:true
Whether the cursor should be visible
setCursorStyle()
Set the cursor style.CursorStyleOptions
Cursor style options
setCursorColor()
Set the cursor color.RGBA
RGBA color instance
setTerminalTitle()
Set the terminal window title.string
Terminal title text
toggleDebugOverlay()
Toggle the debug overlay (shows FPS, memory, etc.).configureDebugOverlay()
Configure the debug overlay.boolean
Enable or disable the overlay
DebugOverlayCorner
Corner to display the overlay
addPostProcessFn()
Add a post-processing function to run after each render.(buffer: OptimizedBuffer, deltaTime: number) => void
Post-processing function
removePostProcessFn()
Remove a previously added post-processing function.addInputHandler()
Add an input handler to process raw terminal input sequences.(sequence: string) => boolean
Handler function that returns true if the sequence was handled
removeInputHandler()
Remove a previously added input handler.setFrameCallback()
Set a callback to run on each frame.(deltaTime: number) => Promise<void>
Async callback function
copyToClipboardOSC52()
Copy text to the system clipboard using OSC 52 escape sequence.string
Text to copy
ClipboardTarget
Clipboard target (clipboard, primary, or secondary)
boolean
Whether the copy operation succeeded
Events
resize
Emitted when the terminal is resized.destroy
Emitted when the renderer is destroyed.focus
Emitted when the terminal gains focus.blur
Emitted when the terminal loses focus.theme_mode
Emitted when the terminal theme mode changes.Mouse Events
MouseEvent
Represents a mouse event in the terminal.MouseEventType
Event type: ‘down’, ‘up’, ‘move’, ‘drag’, ‘scroll’, ‘over’, ‘out’, ‘drop’, ‘drag-end’
number
Mouse button: 0 (left), 1 (middle), 2 (right), 4 (wheel up), 5 (wheel down)
number
X coordinate in terminal cells
number
Y coordinate in terminal cells
Renderable | null
The renderable that was clicked
{ shift: boolean; alt: boolean; ctrl: boolean }
Modifier keys pressed during the event
ScrollInfo | undefined
Scroll information (for scroll events)