Class ScreenRenderer
Diff renderer: emits the minimal stream of ANSI sequences that turns a previous frame into a current frame on the terminal. Pair with ScreenBuffer to drive flicker-free game loops or TUI redraws.
public static class ScreenRenderer
- Inheritance
-
ScreenRenderer
- Inherited Members
Remarks
On the very first frame (or whenever the dimensions differ between frames) Render(ScreenBuffer?, ScreenBuffer, TextWriter) repaints every cell. Subsequent frames only emit cells that actually changed plus the cursor moves to reach them — a typical incremental update on a 80×25 buffer is a few hundred bytes.
The renderer parks the cursor at (1, 1) and emits a final
SGR RESET when at least one cell was painted, so callers don't
inherit the last cell's pen state. No-op when nothing changed.
The whole frame is built into a process-static StringBuilder
and flushed to the sink in a single Write. On Windows
Console.Out takes a per-call lock; batching cuts what would
otherwise be tens of thousands of calls per high-churn frame down to
one. Render is not re-entrant — that's fine, callers serialize on
their own frame loop.
Methods
Render(ScreenBuffer?, ScreenBuffer, TextWriter)
Render the diff between previous and
current into sink. Pass
null for previous on the very first
frame to force a full repaint.
public static void Render(ScreenBuffer? previous, ScreenBuffer current, TextWriter sink)
Parameters
previousScreenBuffercurrentScreenBuffersinkTextWriter