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.Configuration options for the renderer
Returns a fully initialized renderer instance
Example
Configuration Options
CliRendererConfig
Configuration interface for renderer initialization.Custom stdin stream (defaults to
process.stdin)Custom stdout stream (defaults to
process.stdout)Enable remote terminal mode
Enable testing mode (skips terminal setup)
Exit the process when Ctrl+C is pressed
Custom list of signals that trigger exit
Environment variables to forward to the renderer
Debounce delay for resize events (in milliseconds)
Target frames per second for rendering
Maximum frames per second (caps render rate)
Interval for taking memory snapshots (in milliseconds)
Use threading for render operations (disabled on Linux)
Collect rendering statistics
Maximum number of stat samples to keep
Configuration for the console overlay
Post-processing functions to apply after rendering
Enable mouse movement events
Enable mouse input
Automatically focus elements on mouse click
Use alternate screen buffer
Enable console overlay
Split screen mode height (experimental)
Kitty keyboard protocol options
Background color for the renderer
Automatically open console on uncaught errors
Input handlers to prepend to the handler chain
Callback invoked when the renderer is destroyed
Kitty Keyboard Protocol
KittyKeyboardOptions
Configuration for the Kitty keyboard protocol, which provides enhanced key event handling.Disambiguate escape codes (fixes ESC timing, alt+key ambiguity, ctrl+c as event)
Report alternate keys (numpad, shifted, base layout) for cross-keyboard shortcuts
Report event types (press/repeat/release)
Report all keys as escape codes
Report text associated with key events
CliRenderer Class
Properties
The root renderable element (container for all UI elements)
Current renderer width in terminal cells
Current renderer height in terminal cells
Full terminal width (may differ from
width in split mode)Full terminal height (may differ from
height in split mode)Console overlay instance for logging and debugging
Key input handler for keyboard events
Whether the renderer is currently in a running state
Whether the renderer has been destroyed
Whether mouse input is enabled (can be set to toggle)
Whether console overlay is enabled (can be set to toggle)
Terminal capabilities detected from the terminal
Terminal pixel resolution (if available)
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).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.Color value (hex string, RGBA object, or RGBA instance)
setCursorPosition()
Set the cursor position.X coordinate (column)
Y coordinate (row)
Whether the cursor should be visible
setCursorStyle()
Set the cursor style.Cursor style options
setCursorColor()
Set the cursor color.RGBA color instance
setTerminalTitle()
Set the terminal window title.Terminal title text
toggleDebugOverlay()
Toggle the debug overlay (shows FPS, memory, etc.).configureDebugOverlay()
Configure the debug overlay.Enable or disable the overlay
Corner to display the overlay
addPostProcessFn()
Add a post-processing function to run after each render.Post-processing function
removePostProcessFn()
Remove a previously added post-processing function.addInputHandler()
Add an input handler to process raw terminal input sequences.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.Async callback function
copyToClipboardOSC52()
Copy text to the system clipboard using OSC 52 escape sequence.Text to copy
Clipboard target (clipboard, primary, or secondary)
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.Event type: ‘down’, ‘up’, ‘move’, ‘drag’, ‘scroll’, ‘over’, ‘out’, ‘drop’, ‘drag-end’
Mouse button: 0 (left), 1 (middle), 2 (right), 4 (wheel up), 5 (wheel down)
X coordinate in terminal cells
Y coordinate in terminal cells
The renderable that was clicked
Modifier keys pressed during the event
Scroll information (for scroll events)