CanvasBuffer class Core Rendering
A terminal canvas buffer managing character cells and their styles.
CanvasBuffer maintains an internal 2D grid of BufferCells representing the terminal screen content, including characters, foreground and background colors, and font styles.
It supports drawing characters and strings at arbitrary positions, clearing areas or the entire buffer, and flushing changes to the terminal with proper ANSI escape codes.
The buffer tracks an original terminal cursor offset, supports fullscreen mode, and manages cursor visibility for clean rendering.
Typical usage:
- Construct with terminal width and height.
- Use drawChar or drawAt to update cells.
- Call render to flush changes to the terminal.
- Use clear or clearBufferArea to reset contents.
Constructors
- CanvasBuffer.new({required int width, required int height, bool isFullscreen = false})
-
Creates a CanvasBuffer with the specified
width
andheight
.
Properties
- cursorOriginalColumn ↔ int
-
The original horizontal cursor column in the terminal (1-based).
Columns increase from left to right.
getter/setter pair
- cursorOriginalLine ↔ int
-
The original vertical cursor line in the terminal (1-based).
Lines increase from top to bottom.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- height ↔ int
-
The height of the canvas in characters.
getter/setter pair
- isFullscreen ↔ bool
-
Whether the buffer is in fullscreen mode.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- width ↔ int
-
The width of the canvas in characters.
getter/setter pair
Methods
-
clear(
) → void - Clears the entire canvas buffer, resetting all cells to spaces with no style.
-
clearBufferArea(
Rect area) → void -
Clears a rectangular
area
within the buffer. -
drawAt(
int column, int line, String data, TextComponentStyle style) → void -
Draws a string
data
starting at position (column
,line
) with a givenstyle
. -
drawChar(
int column, int line, String char, {AnsiColorType? fg, AnsiColorType? bg, Set< FontStyle> ? styles}) → void -
Draws a single character at position (
column
,line
) with optional style. -
flushArea(
Rect area) → void -
Flushes the contents of a rectangular
area
to the terminal. -
getDrawnCanvas(
) → List< List< BufferCell> > - Returns the internal buffer grid for test inspection.
-
getRenderedString(
) → List< String> - Returns a list of strings representing the ANSI-encoded rendered output, one string per row.
-
getTerminalOffset(
) → (int, int) - Returns the original terminal cursor position as (column, line).
-
hideCursor(
) → void - Hides the terminal cursor using ANSI escape codes.
-
moveCursorTo(
int column, int line) → void -
Moves the terminal cursor to position (
column
,line
) relative to the original offset. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
render(
) → void - Renders the entire buffer content to the terminal.
-
setTerminalOffset(
int column, int line) → dynamic - Sets the original terminal cursor offset for relative rendering.
-
showCursor(
) → void - Shows the terminal cursor using ANSI escape codes.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateDimensions(
int width, int height) → void - Updates the screen buffer dimensions to accommodate the new size.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited