Overview
TheOptimizedBuffer class provides a high-performance, double-buffered rendering system for terminal UIs. It manages character cells, colors, attributes, and supports advanced features like scissor rects, opacity, and various drawing primitives.
Creating a Buffer
OptimizedBuffer.create()
Create a new optimized buffer.Width in terminal cells
Height in terminal cells
Character width calculation method
Whether to respect alpha channel in colors
Optional identifier for debugging
The created buffer instance
Example
Properties
Buffer width in cells (read-only)
Buffer height in cells (read-only)
Character width calculation method (read-only)
Whether alpha blending is enabled
Buffer identifier
Basic Drawing Methods
clear()
Clear the entire buffer with a background color.Background color
Example
setCell()
Set a single cell’s character, colors, and attributes.X coordinate (column)
Y coordinate (row)
Character to display (single character or grapheme cluster)
Foreground color
Background color
Text attributes (bold, italic, underline, etc.)
setCellWithAlphaBlending()
Set a cell with alpha blending.setCell(), but colors are blended with existing colors based on alpha values.
drawText()
Draw text at a position.Text to draw
X coordinate (starting column)
Y coordinate (row)
Foreground color
Background color (optional)
Text attributes
Optional selection range to highlight
Example
fillRect()
Fill a rectangular area with a color.X coordinate
Y coordinate
Rectangle width
Rectangle height
Fill color
drawBox()
Draw a bordered box with optional title.X coordinate
Y coordinate
Box width
Box height
Border style preset
Which borders to draw (true = all sides)
Border color
Background color
Whether to fill the box interior
Optional title text
Title alignment
Example
Advanced Drawing
drawFrameBuffer()
Draw another buffer onto this buffer (compositing).Destination X coordinate
Destination Y coordinate
Source buffer to draw
Optional source X (for partial copy)
Optional source Y
Optional source width
Optional source height
drawGrid()
Draw a grid with borders.Border characters (9 elements: TL, T, TR, L, C, R, BL, B, BR)
Border foreground color
Border background color
Array of column X positions
Array of row Y positions
Draw inner grid lines
Draw outer border
Clipping and Opacity
pushScissorRect()
Push a clipping rectangle (subsequent draws are clipped to this region).X coordinate
Y coordinate
Rectangle width
Rectangle height
popScissorRect()
Remove the most recent scissor rectangle.clearScissorRects()
Remove all scissor rectangles.pushOpacity()
Push an opacity level (0 = transparent, 1 = opaque). Opacity levels are multiplied.Opacity value (0-1)
popOpacity()
Remove the most recent opacity level.getCurrentOpacity()
Get the current composite opacity.Current opacity value
clearOpacity()
Remove all opacity levels.Buffer Management
resize()
Resize the buffer.New width
New height
destroy()
Destroy the buffer and free resources.setRespectAlpha()
Enable or disable alpha blending.Whether to respect alpha channel
Advanced Features
getSpanLines()
Get buffer content as structured spans (for text extraction, testing).Array of lines with styled spans
CapturedLine Structure
getRealCharBytes()
Get the raw character data as UTF-8 bytes.Whether to add line breaks between rows
UTF-8 encoded character data
Raw Buffer Access
buffers
Access raw buffer arrays (advanced use only).Character codepoints (with flags)
Foreground colors (RGBA, 4 floats per cell)
Background colors (RGBA, 4 floats per cell)
Text attributes (bold, italic, etc.)