TerminalBuffer

Full public contract for the terminal buffer.

Composes all role-specific interfaces into a single surface for host applications and host tests.

Coordinates are always zero-based when they are expressed directly as rows and columns on this API. DEC/ANSI commands that are traditionally 1-based should be translated by the parser before they reach the core.

The parser should depend only on the narrower interfaces it actually needs; this facade mainly exists for host host points and tests.

Properties

Link copied to clipboard
abstract val cursorCol: Int

Active cursor column in zero-based viewport coordinates.

Link copied to clipboard
abstract val cursorRow: Int

Active cursor row in zero-based viewport coordinates.

Link copied to clipboard
abstract val height: Int

Current viewport height in rows.

Link copied to clipboard
abstract val historySize: Int

Number of retained off-screen history lines in the active buffer.

Link copied to clipboard
abstract val iconTitle: String

Active xterm icon title.

Link copied to clipboard

The number of queued response bytes currently waiting to be read.

Link copied to clipboard
abstract val width: Int

Current viewport width in cells.

Link copied to clipboard
abstract val windowTitle: String

Active xterm window title.

Functions

Link copied to clipboard
abstract fun appendToPreviousCluster(codepoint: Int)

Appends one grapheme-continuation codepoint to the most recently written printable cell without moving the cursor.

Link copied to clipboard
abstract fun carriageReturn()

Executes a carriage return (CR, 0x0D).

Link copied to clipboard
abstract fun clearAll()

Clears all visible content and scrollback history, resets the pen, homes the cursor, clears the DECSC saved-cursor slot, and restores tab stops to the VT100 default spacing.

Link copied to clipboard
abstract fun clearAllTabStops()

Clears all tab stops (TBC 3, CSI 3 g).

Link copied to clipboard
abstract fun clearResponseBytes()

Discards all queued response bytes from this channel.

Link copied to clipboard
abstract fun clearScreen()

Clears the visible screen and homes the cursor (equivalent to ED 2 + CUP).

Link copied to clipboard
abstract fun clearTabStop()

Clears the tab stop at the current cursor column (TBC 0, CSI 0 g).

Link copied to clipboard
abstract fun cursorBackwardTab(count: Int = 1)

Moves the cursor backward by count tab stops (CBT, CSI Ps Z).

Link copied to clipboard
abstract fun cursorDown(n: Int = 1)

Moves the cursor down by n rows (CUD, CSI n B).

Link copied to clipboard
abstract fun cursorForwardTab(count: Int = 1)

Advances the cursor forward by count tab stops (CHT, CSI Ps I).

Link copied to clipboard
abstract fun cursorLeft(n: Int = 1)

Moves the cursor left by n columns (CUB, CSI n D).

Link copied to clipboard
abstract fun cursorRight(n: Int = 1)

Moves the cursor right by n columns (CUF, CSI n C).

Link copied to clipboard
abstract fun cursorUp(n: Int = 1)

Moves the cursor up by n rows (CUU, CSI n A).

Link copied to clipboard
abstract fun decaln()

Executes the DEC Screen Alignment Test (DECALN, ESC # 8).

Link copied to clipboard
abstract fun deleteCharacters(count: Int)

Deletes count characters at the cursor column, shifting the remainder of the line left and filling the vacated right cells with blanks using the active pen attribute (DCH, CSI n P). Cursor position is not changed.

Link copied to clipboard
abstract fun deleteLines(count: Int)

Deletes count lines starting at the cursor row within the active scroll region (DL, CSI n M).

Link copied to clipboard
abstract fun enterAltBuffer()

Switches to the alternate screen buffer with cursor save (CSI ? 1049 h).

Link copied to clipboard
abstract fun enterAltBufferWithoutCursorSave(clearBeforeEnter: Boolean)

Switches to the alternate screen buffer without saving the primary cursor state.

Link copied to clipboard
abstract fun eraseCharacters(count: Int)

Erases count characters starting at the cursor column without shifting the remainder of the line (ECH, CSI n X).

Link copied to clipboard
abstract fun eraseCurrentLine()

Erases the entire current line without moving the cursor (EL 2, CSI 2 K).

Link copied to clipboard
abstract fun eraseEntireScreen()

Erases the entire visible screen without moving the cursor (ED 2, CSI 2 J).

Link copied to clipboard
abstract fun eraseLineToCursor()

Erases from the start of the current line through the cursor (EL 1, CSI 1 K).

Link copied to clipboard
abstract fun eraseLineToEnd()

Erases from the cursor to the end of the current line (EL 0, CSI 0 K).

Link copied to clipboard
abstract fun eraseScreenAndHistory()

Erases all scrollback history while preserving the visible viewport (xterm/VTE ED 3, CSI 3 J).

Link copied to clipboard
abstract fun eraseScreenToCursor()

Erases from the start of the visible screen through the cursor (ED 1, CSI 1 J).

Link copied to clipboard
abstract fun eraseScreenToEnd()

Erases from the cursor to the end of the visible screen (ED 0, CSI 0 J).

Link copied to clipboard
abstract fun executeDeccolm(newWidth: Int)

Executes DECCOLM (CSI ? 3 h / CSI ? 3 l) as a core-owned macro command.

Link copied to clipboard
abstract fun exitAltBuffer()

Returns to the primary screen buffer with cursor restore (CSI ? 1049 l).

Link copied to clipboard

Returns to the primary screen buffer without restoring a saved cursor.

Link copied to clipboard
abstract fun getAllAsString(): String

Returns scrollback history followed by the visible screen as a newline-joined string, oldest line first.

Link copied to clipboard
abstract fun getAttrAt(col: Int, row: Int): CellAttributes?

Returns the attributes at a screen position as an unpacked Attributes object.

Link copied to clipboard
abstract fun getCodepointAt(col: Int, row: Int): Int

Returns the display/base codepoint at [col, row].

Link copied to clipboard
open override fun getInputModeBits(): Long

Returns one atomic packed snapshot for input encoders.

Link copied to clipboard
abstract fun getLine(row: Int): TerminalLine

Returns the visible line at row, or a shared void line when row is out of bounds.

Link copied to clipboard
abstract fun getLineAsString(row: Int): String

Returns the content of a visible row as a string, trimming trailing blank cells while preserving intentional space characters.

Link copied to clipboard
abstract fun getModeBitsSnapshot(): Long

Returns one atomic packed snapshot of durable mode state.

Link copied to clipboard

Returns an immutable snapshot of the current durable mode flags.

Link copied to clipboard
abstract fun getPackedAttrAt(col: Int, row: Int): Long

Returns the primary packed cell attribute word at [col, row].

Link copied to clipboard
abstract fun getPackedExtendedAttrAt(col: Int, row: Int): Long

Returns the extended packed cell attribute word at [col, row].

Link copied to clipboard
abstract fun getScreenAsString(): String

Returns the visible screen as a newline-joined string, top to bottom.

Link copied to clipboard
abstract fun horizontalTab()

Advances the cursor to the next tab stop (HT, 0x09).

Link copied to clipboard
abstract fun insertBlankCharacters(count: Int)

Inserts count blank cells at the cursor column, shifting existing cells right (ICH, CSI n @). Cells pushed past the right margin are discarded.

Link copied to clipboard
abstract fun insertLines(count: Int)

Inserts count blank lines at the cursor row within the active scroll region (IL, CSI n L).

Link copied to clipboard
abstract fun newLine()

Executes a line feed (LF, 0x0A).

Link copied to clipboard
abstract fun popKittyKeyboardFlags(count: Int)

Pops the Kitty keyboard flags from the stack up to count times.

Link copied to clipboard
abstract fun positionCursor(col: Int, row: Int)

Moves the cursor to an absolute position (CUP / HVP, CSI row ; col H).

Link copied to clipboard
abstract fun pushKittyKeyboardFlags(flags: Int)

Pushes the current Kitty keyboard progressive-enhancement flags to the stack, and sets the new active flags.

Link copied to clipboard
abstract fun queryDynamicColor(target: Int)

Enqueues the color query response for a dynamic target (10, 11, or 12).

Link copied to clipboard
abstract fun queryPaletteColor(index: Int)

Enqueues the color query response for a specific 256-color palette index.

Link copied to clipboard
abstract fun queryStatusString(query: String)

Enqueues the response for a DCS DECRQSS request.

Link copied to clipboard
abstract fun queryTerminfo(rawPayload: String)

Enqueues the response for a DCS XTGETTCAP request.

Link copied to clipboard
abstract fun readResponseBytes(dst: ByteArray, offset: Int = 0, length: Int = dst.size - offset): Int

Reads up to length queued response bytes into dst.

Link copied to clipboard
abstract fun requestDeviceAttributes(kind: Int, parameter: Int)

Enqueues a device attributes (DA) report response.

Link copied to clipboard
abstract fun requestDeviceStatusReport(mode: Int, decPrivate: Boolean)

Enqueues a device status report (DSR) response.

Link copied to clipboard
abstract fun requestWindowReport(mode: Int)

Enqueues a window report response.

Link copied to clipboard
abstract fun reset()

Performs a full terminal reset (RIS, ESC c).

Link copied to clipboard
abstract fun resetCursor()

Resets the cursor to the home position (col=0, row=0).

Link copied to clipboard
abstract fun resetPen()

Resets the active pen to the terminal default attributes (SGR 0, CSI 0 m).

Link copied to clipboard
abstract fun resetScrollRegion()

Resets the scroll region to the full viewport and homes the cursor.

Link copied to clipboard
abstract fun resize(newWidth: Int, newHeight: Int, oldScrollbackOffset: Int = 0): Pair<Int, Int>

Resizes the terminal to newWidth x newHeight.

Link copied to clipboard
abstract fun restoreCursor()

Restores the core-owned state saved by saveCursor (DECRC, ESC 8).

Link copied to clipboard
abstract fun reverseLineFeed()

Executes Reverse Index (RI, ESC M).

Link copied to clipboard
abstract fun saveCursor()

Saves the core-owned cursor state (DECSC, ESC 7).

Link copied to clipboard
abstract fun scrollDown()

Scrolls the active scroll region down by one line (SD, CSI 1 T).

Link copied to clipboard
abstract fun scrollUp()

Scrolls the active scroll region up by one line (SU, CSI 1 S).

Link copied to clipboard

Selectively erases the entire current line without moving the cursor (DECSEL 2).

Link copied to clipboard

Selectively erases the entire visible screen without moving the cursor (DECSED 2).

Link copied to clipboard

Selectively erases from the start of the current line through the cursor (DECSEL 1).

Link copied to clipboard

Selectively erases from the cursor to the end of the current line (DECSEL 0).

Link copied to clipboard

Selectively erases from the start of the visible screen through the cursor (DECSED 1).

Link copied to clipboard

Selectively erases from the cursor through the end of the visible screen (DECSED 0).

Link copied to clipboard
abstract fun setApplicationCursorKeys(enabled: Boolean)

Toggles application cursor key mode (DECCKM, CSI ? 1 h / CSI ? 1 l).

Link copied to clipboard
abstract fun setApplicationKeypad(enabled: Boolean)

Toggles application keypad mode (DECNKM).

Link copied to clipboard
abstract fun setAutoWrap(enabled: Boolean)

Enables or disables DECAWM auto-wrap (CSI ? 7 h / CSI ? 7 l).

Link copied to clipboard
abstract fun setBellIsUrgent(enabled: Boolean)

Toggles urgent bell mode (?1042).

Link copied to clipboard
abstract fun setBracketedPasteEnabled(enabled: Boolean)

Enables or disables bracketed paste reporting (CSI ? 2004 h / CSI ? 2004 l).

Link copied to clipboard
abstract fun setCursorBlinking(enabled: Boolean)

Toggles cursor blink presentation state.

Link copied to clipboard

Sets the cursor shape/style.

Link copied to clipboard
abstract fun setCursorVisible(enabled: Boolean)

Toggles cursor visibility presentation state (DECTCEM, CSI ? 25 h / CSI ? 25 l).

Link copied to clipboard

Sets the default cursor shape/style restored on reset.

Link copied to clipboard
abstract fun setDynamicColor(target: Int, color: Int)

Updates a dynamic target color (foreground, background, or cursor color).

Link copied to clipboard
abstract fun setFocusReportingEnabled(enabled: Boolean)

Enables or disables focus in/out reporting (CSI ? 1004 h / CSI ? 1004 l).

Link copied to clipboard
abstract fun setFormatOtherKeysMode(mode: Int)

Sets the format-other-keys wire format used when modify-other-keys applies.

Link copied to clipboard
abstract fun setHyperlinkId(hyperlinkId: Int)

Sets the active OSC 8 hyperlink id stamped onto future printed cells.

Link copied to clipboard
abstract fun setIconTitle(title: String)

Sets the xterm icon title.

Link copied to clipboard
abstract fun setInsertMode(enabled: Boolean)

Enables or disables Insert Replace Mode (IRM, CSI 4 h / CSI 4 l).

Link copied to clipboard
abstract fun setKittyKeyboardFlags(flags: Int)

Sets active Kitty keyboard progressive-enhancement flags.

Link copied to clipboard
abstract fun setLeftRightMarginMode(enabled: Boolean)

Enables or disables left/right margin mode (DECLRMM, CSI ? 69 h / CSI ? 69 l).

Link copied to clipboard
abstract fun setLeftRightMargins(left: Int, right: Int)

Sets the active horizontal margins (DECSLRM, CSI left ; right s).

Link copied to clipboard
abstract fun setModifyOtherKeysMode(mode: Int)

Sets the modify-other-keys reporting level.

Link copied to clipboard

Sets the active mouse report encoding mode used by terminal-to-host reporting.

Link copied to clipboard

Sets the active mouse tracking mode used by terminal-to-host reporting.

Link copied to clipboard
abstract fun setNewLineMode(enabled: Boolean)

Enables or disables New Line Mode (LNM, CSI 20 h / CSI 20 l).

Link copied to clipboard
abstract fun setOriginMode(enabled: Boolean)

Enables or disables Origin Mode (DECOM, CSI ? 6 h / CSI ? 6 l).

Link copied to clipboard
abstract fun setPaletteColor(index: Int, color: Int)

Updates an individual color index in the active 256-color palette.

Link copied to clipboard
abstract fun setPenAttributes(fg: Int, bg: Int, bold: Boolean = false, faint: Boolean = false, italic: Boolean = false, underlineStyle: UnderlineStyle = UnderlineStyle.NONE, strikethrough: Boolean = false, overline: Boolean = false, blink: Boolean = false, inverse: Boolean = false, conceal: Boolean = false, underlineColor: Int = 0)

Sets the active pen attributes used by all subsequent write and erase operations.

Link copied to clipboard
abstract fun setPenColors(foreground: CellColor, background: CellColor, underlineColor: CellColor = CellColor.DEFAULT, bold: Boolean = false, faint: Boolean = false, italic: Boolean = false, underlineStyle: UnderlineStyle = UnderlineStyle.NONE, strikethrough: Boolean = false, overline: Boolean = false, blink: Boolean = false, inverse: Boolean = false, conceal: Boolean = false)

Sets the active pen attributes using explicit default, indexed, or RGB colors.

Link copied to clipboard
abstract fun setPopOnBell(enabled: Boolean)

Toggles pop on bell mode (?1043).

Link copied to clipboard
abstract fun setReverseVideo(enabled: Boolean)

Toggles reverse-video presentation state (DECSCNM, CSI ? 5 h / CSI ? 5 l).

Link copied to clipboard
abstract fun setScrollRegion(top: Int, bottom: Int)

Sets the active vertical scroll region (DECSTBM, CSI top ; bottom r).

Link copied to clipboard
abstract fun setSelectiveEraseProtection(enabled: Boolean)

Enables or disables selective-erase protection on future printed cells (DECSCA).

Link copied to clipboard
abstract fun setSynchronizedOutput(enabled: Boolean)

Toggles synchronized output mode (DECSET/DECRST ?2026).

Link copied to clipboard
abstract fun setTabStop()

Sets a tab stop at the current cursor column (HTS, ESC H).

Link copied to clipboard
abstract fun setThemePalette(palette: TerminalColorPalette)

Sets the theme-configured color palette for the terminal session.

Link copied to clipboard
abstract fun setTreatAmbiguousAsWide(enabled: Boolean)

Controls how East Asian Ambiguous codepoints are measured for future writes.

Link copied to clipboard
abstract fun setWindowMinimized(minimized: Boolean)

Updates the recorded window minimization state.

Link copied to clipboard
abstract fun setWindowSizePixels(width: Int, height: Int)

Updates the recorded window size in pixels.

Link copied to clipboard
abstract fun setWindowTitle(title: String)

Sets the xterm window title.

Link copied to clipboard
abstract fun softReset()

Performs a soft terminal reset (DECSTR, CSI ! p).

Link copied to clipboard
abstract fun writeCluster(codepoints: IntArray, length: Int = codepoints.size)

Writes one pre-segmented grapheme cluster to the grid.

Link copied to clipboard
abstract fun writeCodepoint(codepoint: Int)

Writes one Unicode scalar value at the cursor position using the active pen attributes, then advances the cursor.

Link copied to clipboard
abstract fun writeText(text: String)

Writes text literally to the buffer using the active pen attributes.