Skip to content

Rendering Pipeline

The rendering pipeline transforms component trees into terminal output.

React calls reconciler host config methods. The reconciler maintains an internal tree of BetterTUI nodes.

On commit, dirty nodes are diffed against the previous frame. Only changed nodes produce render commands.

Render commands are batched into a single frame. This minimizes napi-rs bridge overhead.

The Rust engine runs Taffy’s flexbox layout. Only dirty subtrees are recalculated.

A cell-based frame buffer is composed. Each cell contains a character, foreground color, background color, and style attributes.

ANSI escape sequences are written to the terminal. Only changed cells are written (dirty rect optimization).

┌─ Frame N ─────────────────────────────┐
│ React render │
│ Tree diff │
│ Command batch │
│ Layout calculation │
│ Frame buffer composition │
│ Terminal output │
└────────────────────────────────────────┘
↓ (vsync @ 60fps)
┌─ Frame N+1 ───────────────────────────┐
│ ... │
└────────────────────────────────────────┘

Only regions that changed between frames are redrawn. This reduces terminal I/O and improves performance.

Frame 1: [A][B][C][D][E]
↓ (B changes)
Frame 2: [A][B'][C][D][E]
↑ only B is redrawn