Buffer class

High-level wrapper for OpenTUI's optimized buffer operations.

The Buffer class provides a convenient Dart interface for all OpenTUI drawing operations, including text rendering, shape drawing, and advanced compositing. Buffers represent 2D grids of terminal cells, each containing a character, foreground color, background color, and text attributes.

Lifecycle: Buffer instances obtained from Renderer.nextBuffer are only valid until the next call to Renderer.render(). After render, the buffer is invalidated and all operations will throw StateError.

Use Buffer when:

  • Building terminal-based user interfaces
  • Creating text-mode games and graphics
  • Implementing off-screen rendering for complex layouts
  • Building layered rendering systems with multiple buffers

Example:

final buffer = renderer.getNextBuffer();

// Clear to dark background
buffer.clear(Color.fromHex('#1A202C'));

// Draw a bordered panel
buffer.drawBox(5, 2, 30, 15,
    BoxOptions(sides: BorderSides.all(), title: 'Settings'),
    Color.cyan, Color.darkGray);

// Add content text
buffer.drawText('Welcome to OpenTUI!', 10, 5, Color.white);

// Create a progress bar
buffer.fillRect(10, 8, 20, 1, Color.green);

Constructors

Buffer(Pointer<OptimizedBufferHandle> _ptr, OpenTuiBindings _bindings)
Creates a Buffer.

Properties

hashCode int
The hash code for this object.
no setterinherited
height int
Height of the buffer in terminal rows.
no setter
isInvalidated bool
Whether this buffer has been invalidated.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
width int
Width of the buffer in terminal columns.
no setter

Methods

clear(Color bg) → void
Clears the entire buffer to a uniform background color.
clipped({required int clipX, required int clipY, required int clipWidth, required int clipHeight}) Buffer
Returns a Buffer view that silently drops draw calls outside the rectangle (clipX, clipY, clipWidth, clipHeight). The view shares the underlying FFI buffer and validity state; invalidating the parent also invalidates every clipped view. Used by scrolling/clipping containers (e.g. ScrollBox).
drawBox(int x, int y, int width, int height, BoxOptions options, Color borderColor, Color backgroundColor) → void
Draws a bordered box with extensive customization options.
drawFrameBuffer(Buffer sourceBuffer, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY) → void
Draw another buffer onto this buffer (compositing).
drawText(String text, int x, int y, Color fg, {Color? bg, int attributes = 0}) → void
Draws text at the specified position with styling options.
drawTextBuffer(TextBuffer textBuffer, int x, int y, {int? clipX, int? clipY, int? clipWidth, int? clipHeight}) → void
Draw a TextBuffer to this buffer.
fillRect(int x, int y, int width, int height, Color color) → void
Fills a rectangular region with solid background color.
getDirectAccess() DirectBufferAccess
Get direct access to internal arrays for performance-critical operations.
invalidate() → void
Invalidate this buffer (and every view created from it via clipped). Called by Renderer after render, resize, or dispose.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resize(int newWidth, int newHeight) → void
Resizes the buffer to newWidth by newHeight terminal cells.
setCell(int x, int y, String char, Color fg, Color bg, int attributes) → void
Sets a single cell at (x, y) using alpha blending.
setCellWithAlphaBlending(int x, int y, String char, Color fg, Color bg, int attributes) → void
Sets a cell at (x, y) with full alpha-blending support.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited