Class ScreenBuffer
A double-buffer-friendly cell grid: a fixed-size 2D array of Cell with helpers for clearing, writing strings, and filling rectangles. Pair with Render(ScreenBuffer?, ScreenBuffer, TextWriter) to flush a frame to a terminal as minimal ANSI.
public sealed class ScreenBuffer
- Inheritance
-
ScreenBuffer
- Inherited Members
Remarks
One cell == one terminal column; v1 does not model wide / surrogate glyphs.
Mutation is direct — there is no transactional commit. Build the next frame in one buffer, render diff against the previous frame, then swap. Allocation cost is one Cell array per buffer; reuse buffers across frames instead of re-allocating.
Constructors
ScreenBuffer(int, int)
public ScreenBuffer(int width, int height)
Parameters
Properties
Height
public int Height { get; }
Property Value
this[int, int]
Read or write a single cell. Throws on out-of-bounds — callers that want clipping should use PutString(int, int, ReadOnlySpan<char>, Color, Color, CellAttrs) / FillRect(int, int, int, int, Cell).
public Cell this[int x, int y] { get; set; }
Parameters
Property Value
Width
public int Width { get; }
Property Value
Methods
Clear()
Fill every cell with Empty.
public void Clear()
Clear(Cell)
Fill every cell with fill.
public void Clear(Cell fill)
Parameters
fillCell
FillRect(int, int, int, int, Cell)
Fill a rectangle with fill. Clips against the
buffer bounds; a fully off-screen rect is a no-op.
public void FillRect(int x, int y, int width, int height, Cell fill)
Parameters
PutString(int, int, ReadOnlySpan<char>, Color, Color, CellAttrs)
Write text starting at (x, y), one cell
per char, painted with fg /
bg / attrs. Clips at the
right edge and skips entirely if the row is off-screen — silent
because string writes are the geometry hot path and exceptions
turn every render loop into a try/catch.
public void PutString(int x, int y, ReadOnlySpan<char> text, Color fg, Color bg, CellAttrs attrs = CellAttrs.None)