Skip to main content

Overview

The FrameBuffer (also called OptimizedBuffer) is OpenTUI’s low-level rendering surface. It provides direct pixel-level access to the terminal buffer, allowing you to:
  • Draw custom graphics
  • Create complex visual effects
  • Implement custom renderables
  • Optimize rendering performance
  • Work with transparency and alpha blending
Every renderable ultimately draws to a frame buffer, which is then output to the terminal.
The FrameBuffer is implemented in native code (Zig) for maximum performance, but exposed to TypeScript with a clean API.

Creating a FrameBuffer

Standalone Buffer

Create a buffer directly:

FrameBuffer Renderable

Use a renderable that wraps a buffer:

Buffered Renderables

Enable double-buffering for any renderable:

Drawing Operations

Set Individual Cells

Alpha Blending

Set cells with alpha blending:
Alpha blending only works if the buffer was created with respectAlpha: true.

Draw Text

Text with Selection

Fill Rectangle

Draw Box

Draw boxes with borders and titles:

Custom Border Characters

Clear Buffer

Compositing

Draw Another FrameBuffer

Composite one buffer onto another:

Draw TextBufferView

Render a text buffer (from the editor):

Draw EditorView

Advanced Features

Scissor Rectangles

Clip drawing to a region:
Scissor rects stack - you can push multiple regions:

Opacity Stack

Apply opacity to drawing operations:
Opacity also stacks:

Grayscale Rendering

Draw grayscale intensity data:

Supersampled Grayscale

For higher quality:

Grid Drawing

Draw table grids efficiently:

Buffer Inspection

Access Raw Data

Get Resolved Characters

Capture as Spans

Get buffer content as styled spans (useful for copying/testing):

Resizing

Resizing clears the buffer and reallocates memory.

Memory Management

Cleanup

Always destroy buffers when done:
Using a destroyed buffer will throw an error. Always check buffer._destroyed if you’re unsure.

Alpha Blending

Toggle alpha blending dynamically:

Unicode Encoding

Encode text with width information:

Practical Examples

Custom Progress Bar

Gradient Background

Custom Renderable with FrameBuffer

API Reference

Properties

Core Methods