Buffer

class Buffer(var width: Int, var height: Int, val maxScrollback: Int)

The core data structure representing the terminal emulator's text buffer. It manages the 2D grid of character cells, scrollback history, and cursor position.

Constructors

Link copied to clipboard
constructor(width: Int, height: Int, maxScrollback: Int)

Properties

Link copied to clipboard

The active style attributes applied to any new characters written or inserted.

Link copied to clipboard

The current 0-indexed column position of the cursor.

Link copied to clipboard

The current 0-indexed row position of the cursor on the visible screen.

Link copied to clipboard
var height: Int

The number of rows in the terminal screen.

Link copied to clipboard

The maximum number of lines preserved in history when scrolling.

Link copied to clipboard
var width: Int

The number of columns in the terminal screen.

Functions

Link copied to clipboard
fun clearAll()

Clears the visible screen AND the scrollback history.

Link copied to clipboard

Clears all visible text on the screen and resets the cursor to (0,0).

Link copied to clipboard
fun fillLine(row: Int, char: Char = ' ')

Overwrites an entire row with a specific character and the current style.

Link copied to clipboard
fun getCharAt(col: Int, row: Int): Char

Retrieves the character at a specific coordinate (negative row queries history).

Link copied to clipboard

Retrieves the scrollback history and the visible screen as a single multi-line string.

Link copied to clipboard
fun getLine(row: Int): Line

Retrieves a specific Line object from the visible screen for rendering.

Link copied to clipboard

Retrieves a specific line as a raw string (negative row queries history).

Link copied to clipboard

Retrieves the entire visible screen concatenated as a multi-line string.

Link copied to clipboard
fun getStyleAt(col: Int, row: Int): CharacterStyle

Retrieves the style attributes at a specific coordinate (negative row queries history).

Link copied to clipboard
fun insert(text: String)

Inserts text at the current cursor position. Existing characters on the line are shifted to the right. Characters pushed past the screen width are discarded.

Link copied to clipboard

Inserts an empty line at the bottom of the screen, pushing everything up and saving the top line to scrollback history.

Link copied to clipboard
fun moveCursor(dCol: Int, dRow: Int)

Moves the cursor relative to its current position, clamping to boundaries.

Link copied to clipboard
fun print(text: String)

Writes a sequence of characters to the buffer.

Link copied to clipboard
fun resize(newWidth: Int, newHeight: Int)

Dynamically resizes the terminal grid and reflows the text. Text that was soft-wrapped will unwrap if the width increases. Text will soft-wrap if the width decreases.

Link copied to clipboard
fun setCursorPosition(col: Int, row: Int)
Link copied to clipboard
fun write(char: Char)

Writes a single character to the buffer at the current cursor position, overwriting existing text and advancing the cursor.