Quickstart
Build a small counter controlled by the arrow keys. The finished app uses layout, text, keyboard input, live updates, and explicit cleanup.
Prerequisite
This guide uses Bun to run TypeScript source. See Runtime and platform support for other runtime and platform requirements.
Create an empty project and add OpenTUI:
mkdir my-tui && cd my-tui
bun init -y
bun add @opentui/coreCreate the app
Create index.ts:
createCliRenderer() takes control of the terminal and returns a CliRenderer. Its root property is the root of the
component tree. BoxRenderable and TextRenderable are imperative tree nodes. The event handler updates the counter's
content property directly.
The renderer emits parsed keyboard events through keyInput. The handler changes counter.content, which schedules a
new frame.
Run it
bun index.tsPress the Left and Right arrow keys. The count updates in place.
The application creates and owns the renderer. It must call renderer.destroy() on every shutdown path to release
resources and restore the terminal. This example calls it when you press q. exitOnCtrlC: true handles the Ctrl+C
path.
Continue
Return to the OpenTUI introduction for the documentation map.
React bindings apply the shared model through React.
Solid bindings apply the shared model through Solid.
Components compares component availability across Core, React, and Solid.
Renderables covers imperative tree creation and mutation.
Lifecycle and cleanup covers shutdown paths and resource ownership.