Expand description
Deterministic textual rendering of a Buffer for golden snapshot tests.
This is the verification backbone of the framework: every widget test diffs
its HeadlessBackend screen against a golden string produced here. The
format is therefore frozen here, once — not improvised per test.
§Format
snapshot renders three layers plus cursor metadata, with no
timestamps (so goldens are stable):
size: 10x3
cursor: 5,0
text:
|Hello |
|World |
| |
attr:
|aaaaa.....|
|bbbbb.....|
|..........|
legend:
. default
a fg=BIOS(15) bg=BIOS(1)
b fg=RGB(255,0,0) bg=default +bold- text layer — the on-screen glyphs, one framed line per row. Each line
is bounded by
|so trailing spaces stay visible in the golden file (the leading/trailing|are frame delimiters, identified by position, not content — note box-drawing uses U+2502│, distinct from ASCII|). - attr layer — one key char per display column, aligned beneath the
text.
.is always the default style; other styles are keyeda..z,A..Z,0..9in row-major first-appearance order. - legend — key → style description (
fg=… bg=… [+mod…]),.first, then the rest in assignment order. - cursor —
x,ywhen shown, orhidden.
§Wide glyphs
A double-width grapheme occupies a wide lead cell plus a trail cell in
the buffer. In the snapshot the lead contributes its 2-column glyph to the
text layer and its key twice to the attr layer; the trail cell is
absorbed (contributes nothing). So both layers are exactly width display
columns wide and stay aligned.
§Turbo Vision heritage
tvision-rs extension: no Turbo Vision counterpart. It serializes the screen grid to a stable golden string so the framework can be verified with snapshot tests rather than a live terminal (deviation D11).
Functions§
- snapshot
- Render
buffer(and thecursorstate) to the canonical golden-snapshot string documented on this module.
Type Aliases§
- Snapshot
Cursor - The cursor state for a snapshot:
Some((x, y))when visible at that cell,Nonewhen hidden.