Skip to main content

OptimizedBuffer

The OptimizedBuffer class (also known as FrameBuffer) provides low-level access to terminal rendering. It manages a grid of cells, each containing a character, foreground color, background color, and text attributes.

Creating Buffers

function
Create a new framebuffer
number
required
Width in terminal cells
number
required
Height in terminal cells
'unicode' | 'wcwidth' | 'no_zwj'
required
Character width calculation method
boolean
Whether to respect alpha channel when compositing. Default: false
string
Optional identifier for debugging

Properties

number
Buffer width in cells
number
Buffer height in cells
WidthMethod
Character width calculation method used by this buffer
boolean
Whether alpha blending is enabled
Pointer
Native pointer to the underlying buffer (for advanced use)
object
Direct access to raw buffer data

Drawing Methods

function
Clear the entire buffer with a background color
RGBA
Background color. Default: RGBA.fromValues(0, 0, 0, 1)
function
Set a single cell with no alpha blending
number
required
X coordinate (column)
number
required
Y coordinate (row)
string
required
Character to display (first codepoint used)
RGBA
required
Foreground color
RGBA
required
Background color
number
Text attributes (bold, italic, underline, etc.). Default: 0
function
Set a single cell with alpha blending
Same parameters as setCell, but blends colors using alpha channel.
function
Draw text at a position with optional selection
string
required
Text to draw
number
required
Starting X coordinate
number
required
Starting Y coordinate
RGBA
required
Foreground color
RGBA
Background color
number
Text attributes. Default: 0
object
Optional selection range to highlight
function
Draw a single character by codepoint
number
required
Unicode codepoint
function
Fill a rectangular area with a background color
function
Draw a bordered box with optional title
'single' | 'double' | 'rounded' | 'thick' | 'dashed'
Border style preset
boolean | BorderSides[]
required
Which sides to draw: true for all sides, or array like ["top", "left"]
'left' | 'center' | 'right'
Title text alignment. Default: "left"
function
Draw a grid with custom column/row offsets

Compositing

function
Composite another framebuffer onto this one
number
required
Destination X coordinate
number
required
Destination Y coordinate
OptimizedBuffer
required
Source buffer to composite
number
Source region X offset
number
Source region Y offset
number
Source region width
number
Source region height
function
Draw a TextBufferView
function
Draw an EditorView

Image Rendering

function
Draw pixel data with supersampling
function
Draw grayscale intensity data
function
Draw grayscale data with supersampling for smoother rendering

Clipping and Opacity

function
Push a clipping rectangle onto the stack
function
Pop the top clipping rectangle from the stack
function
Remove all clipping rectangles
function
Push an opacity value onto the stack (multiplies with existing opacity)
number
required
Opacity value between 0.0 and 1.0
function
Pop the top opacity value from the stack
function
Get the current effective opacity
function
Clear the opacity stack

Utilities

function
Resize the buffer (clears content)
function
Enable or disable alpha blending
function
Get the buffer’s native identifier
function
Get the resolved character data as UTF-8 bytes
boolean
Whether to add newlines between rows. Default: false
function
Extract buffer content as styled text spans
Returns an array of lines, each containing spans with text, colors, and attributes.
function
Destroy the buffer and free native resources

Example