/** * Cell-buffer rendering primitives. * * This stores terminal cells in compact parallel arrays and keeps ANSI styles * as small numeric IDs via StyleRegistry. */ import { type AnsiCode } from "../types/ansi.js"; export interface CellBufferSize { width: number; height: number; } export declare class StyleRegistry { private readonly keyToId; private readonly idToStyles; constructor(); static keyFor(styles: readonly AnsiCode[] | null | undefined): string; getId(styles: readonly AnsiCode[] | null | undefined): number; getStyles(id: number): readonly AnsiCode[]; } export declare class CellBuffer { width: number; height: number; readonly styleRegistry: StyleRegistry; /** * Per-cell visible glyph. Continuation cells store empty string. */ chars: string[]; /** * Per-cell display width: 1 or 2 on leading cells, 0 on continuation cells. */ widths: Uint8Array; /** * Per-cell style id. Continuation cells keep the leading style id. */ styleIds: Uint32Array; /** * Marks whether a cell was explicitly written in the current frame. */ touched: Uint8Array; /** * Marks whether trailing spaces on a touched cell should be preserved. */ preserveTrailingSpace: Uint8Array; /** * Marks whether a row has been touched by any write operation. * Used to optimize isRowEqual/diffing. */ rowTouched: Uint8Array; constructor(size?: CellBufferSize, styleRegistry?: StyleRegistry); resize(width: number, height: number): void; clear(styleId?: number): void; /** * Converts `(x, y)` coordinates to a linear index in parallel arrays. */ index(x: number, y: number): number; setCell(x: number, y: number, ch: string, charWidth: number, styleId: number, preserveTrailing?: boolean): void; fill(x: number, y: number, length: number, char: string, charWidth: number, styleId: number): void; isRowEqual(other: CellBuffer, row: number): boolean; isEqual(other: CellBuffer): boolean; /** * Computes the visible right edge for a row. * * This keeps transformer-produced trailing spaces when `preserveTrailingSpace` * is set, while trimming untouched or default trailing cells. */ getRowRightEdge(row: number): number; /** * Closes active styles and opens next styles when style id changes. */ appendStyleTransition(out: string[], activeStyleId: number, nextStyleId: number): number; /** * Closes any currently active style sequence. */ appendCloseActiveStyle(out: string[], activeStyleId: number): number; /** * Serializes a contiguous range of cells from one row, preserving ANSI style * transitions and wide-character boundaries. */ appendStyledRange(row: number, start: number, end: number, out: string[], activeStyleId: number, cursorX: number): { cursorX: number; activeStyleId: number; }; /** * Serializes one row into ANSI text, trimming only non-visible tail cells. */ serializeRow(row: number): string; /** * Serializes the entire buffer into a multi-line ANSI string. */ toString(): string; }