Buffer class

One screen of a Terminal: the main buffer (with scrollback) or the alternate buffer used by full-screen programs.

A buffer reads its screen from libghostty-vt: lines are snapshots made on first access and reused until the terminal changes. Only the terminal's active screen can be read: while the other screen is active (Terminal.isUsingAltBuffer), this buffer reads as viewHeight blank lines with the cursor at 0, 0, and its mutators throw StateError.

The mutators (setCursor, clear, eraseDisplay, insertLines, …) write the equivalent escape sequence to the terminal, so they follow libghostty-vt's rules (scroll margins, origin mode). Like the Terminal methods of the same names, they throw StateError while the program's output has stopped in the middle of an escape sequence.

Constructors

Buffer(TerminalState terminal, {required int maxLines, required bool isAltBuffer, Set<int>? wordSeparators})
Creates the main or alternate (isAltBuffer) buffer of terminal.

Properties

absoluteCursorY → int
Vertical position of the cursor relative to the top of the buffer, starting from 0.
no setter
absoluteMarginBottom → int
Absolute index of the last line in the scroll region.
no setter
absoluteMarginTop → int
Absolute index of the first line in the scroll region.
no setter
currentLine → BufferLine
The line at the current cursor position.
no setter
cursorX → int
Horizontal position of the cursor relative to the top-left cornor of the screen, starting from 0.
no setter
cursorY → int
Vertical position of the cursor relative to the top-left cornor of the screen, starting from 0.
no setter
hashCode → int
The hash code for this object.
no setterinherited
height → int
Total number of lines in the buffer. Always equal or greater than viewHeight.
no setter
isAltBuffer → bool
Whether this is the alternate buffer.
final
isInVerticalMargin → bool
Whether the cursor is inside the scroll region (the whole screen, as far as this buffer can tell; see marginTop).
no setter
lines → IndexAwareCircularBuffer<BufferLine>
lines of the buffer. the length of lines should always be equal or greater than viewHeight.
latefinal
marginBottom → int
Index of the last line in the scroll region. Always viewHeight - 1: libghostty-vt 1.0.0 does not expose the scroll margins (DECSTBM).
no setter
marginTop → int
Index of the first line in the scroll region. Always 0: libghostty-vt 1.0.0 does not expose the scroll margins (DECSTBM).
no setter
maxLines → int
The most lines (scrollback plus screen) the terminal keeps.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scrollBack → int
The number of lines above the viewport.
no setter
terminal → TerminalState
The terminal this buffer belongs to.
final
viewHeight → int
Height of the viewport in rows. Also the index of the last line.
no setter
viewWidth → int
Width of the viewport in columns. Also the index of the last column.
no setter
wordSeparators → Set<int>?
Characters that break selection when calling getWordBoundary. If null, defaults to defaultWordSeparators.
final

Methods

backspace() → void
Moves the cursor one cell left (BS).
clear() → void
Clears the viewport and scrollback buffer. Then fill with empty lines.
clearScrollback() → void
Remove all lines above the top of the viewport.
createAnchor(int x, int y) → CellAnchor
Create a new CellAnchor at the specified x and y coordinates.
createAnchorFromCursor() → CellAnchor
Creates a new CellAnchor at the cursor.
createAnchorFromOffset(CellOffset offset) → CellAnchor
Create a new CellAnchor at the specified x and y coordinates.
cursorGoForward() → void
Moves the cursor one cell right (CUF), stopping at the last column.
deleteChars(int count) → void
Deletes count cells at the cursor, shifting the rest left (DCH).
deleteLines(int count) → void
Remove count lines starting at the current cursor position. Lines below the removed lines are shifted up. This only affects the scrollable region. Lines outside the scrollable region are not affected.
eraseChars(int count) → void
Erases count cells starting at the cursor position.
eraseDisplay() → void
Erases the whole viewport.
eraseDisplayFromCursor() → void
Erases the viewport from the cursor position to the end of the buffer, including the cursor position.
eraseDisplayToCursor() → void
Erases the viewport from the top-left corner to the cursor, including the cursor.
eraseLine() → void
Erases the line at the current cursor position.
eraseLineFromCursor() → void
Erases the line from the cursor to the end of the line, including the cursor position.
eraseLineToCursor() → void
Erases the line from the start of the line to the cursor, including the cursor.
getText([BufferRange? range]) → String
Get the plain text content of the buffer including the scrollback. Accepts an optional range to get a specific part of the buffer.
getWordBoundary(CellOffset position) → BufferRangeLine?
The word around position, from its first cell (inclusive) to the cell after its last (exclusive), or null on a separator.
index() → void
https://vt100.net/docs/vt100-ug/chapter3.html#IND IND – Index
insertBlankChars(int count) → void
Inserts count blank cells at the cursor (ICH).
insertLines(int count) → void
Inserts count blank lines at the cursor, inside the scroll region (IL).
lineFeed() → void
Moves the cursor down one line, scrolling at the bottom margin (LF); also to the first column in line feed mode.
moveCursor(int offsetX, int offsetY) → void
Moves the cursor by offsetX columns and offsetY rows.
moveCursorX(int offset) → void
Moves the cursor offset columns right (left if negative).
moveCursorY(int offset) → void
Moves the cursor offset rows down (up if negative).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resetVerticalMargins() → void
Resets the scroll region to the whole screen.
restoreCursor() → void
Restore cursor position, charmap and text attributes.
reverseIndex() → void
https://terminalguide.namepad.de/seq/a_esc_cm/
saveCursor() → void
Save cursor position, charmap and text attributes.
scrollDown(int lines) → void
Scrolls the scroll region down by lines lines (SD).
scrollUp(int lines) → void
Scrolls the scroll region up by lines lines (SU).
setCursor(int cursorX, int cursorY) → void
Moves the cursor to column cursorX, row cursorY of the screen (of the scroll region in origin mode).
setCursorX(int cursorX) → void
Moves the cursor to column cursorX.
setCursorY(int cursorY) → void
Moves the cursor to row cursorY of the screen.
setVerticalMargins(int top, int bottom) → void
Sets the vertical scrolling margin to top and bottom. Both values must be between 0 and viewHeight - 1.
toString() → String
Returns a debug representation of the buffer.
override
write(String text) → void
Writes text at the cursor as printable characters: control characters in it are dropped, so no escape sequence is interpreted.
writeChar(int codePoint) → void
Writes the character codePoint at the cursor; a control character is dropped.

Operators

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

Static Properties

defaultWordSeparators → Set<int>
The characters getWordBoundary stops at when wordSeparators is not set.
final