Table of Contents

Class ScreenBuffer

Namespace
Retro.Crt
Assembly
Retro.Crt.dll

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

width int
height int

Properties

Height

public int Height { get; }

Property Value

int

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

x int
y int

Property Value

Cell

Width

public int Width { get; }

Property Value

int

Methods

Clear()

Fill every cell with Empty.

public void Clear()

Clear(Cell)

Fill every cell with fill.

public void Clear(Cell fill)

Parameters

fill Cell

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

x int
y int
width int
height int
fill Cell

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)

Parameters

x int
y int
text ReadOnlySpan<char>
fg Color
bg Color
attrs CellAttrs