Expand description
The platform seam: everything that touches the terminal lives behind a single trait, so the rest of the framework stays terminal-agnostic.
§Color quantization
Pure color-mapping math: RGB → xterm-256 → xterm-16 → BIOS. All functions
are const-capable and I/O-free, so a backend can downsample any color to the
depth its terminal supports. They operate on raw u8 channel values and
palette indices and are decoupled from the Color
enum: the Backend assembles the capability-aware policy that decides
which rung of the ladder to use.
Turbo Vision heritage: the functions port RGBtoXTerm16, RGBtoXTerm256,
BIOStoXTerm16 and the related helpers from colors.cpp / colors.h. The
math is reproduced verbatim; only the storage is typed (u8 channels rather
than packed bytes).
§Backend trait + implementations
The Backend trait is the seam between the framework and the terminal.
Two implementations are provided:
CrosstermBackend— production, wraps crossterm.HeadlessBackend+HeadlessHandle— tests, in-memory buffer.
Renderer owns the back/front buffer pair and a boxed backend; it runs the
draw cycle (reset → paint → diff → draw → flush → swap), painting the whole
view tree each frame and relying on the diff to keep terminal output minimal.
Guide: Drawing & backends.
Structs§
- Crossterm
Backend - Production backend backed by crossterm.
- Headless
Backend - In-memory backend for deterministic tests.
- Headless
Handle - A cloneable window into a
HeadlessBackend’s screen and event queue. - Renderer
- Owns the back/front buffer pair and a boxed
Backend.
Enums§
- Color
Depth - Terminal color capability level.
Constants§
- CARET_
INSERT - Caret size for the block (overwrite-mode) caret: the whole cell. See
Backend::set_caret_size. - CARET_
NORMAL - Caret size for the normal (insert-mode) caret, 1% of the cell. A terminal
backend shows it as the terminal’s own caret shape. See
Backend::set_caret_size. - XTER
M256_ TO_ RGB - LUT: xterm-256 index → packed
0xRRGGBB. - XTER
M256_ TO_ XTER M16 - LUT: xterm-256 index → nearest xterm-16 index.
Traits§
- Backend
- Platform seam between the framework and the terminal.
Functions§
- bios_
to_ xterm16 - Swap the red and blue bits of a 4-bit BIOS colour index.
- rgb_
to_ bios - Convert an RGB triplet directly to a BIOS colour index (0..=15).
- rgb_
to_ xterm16 - Convert an RGB triplet to the nearest xterm-16 / BIOS-style index (0..=15).
- rgb_
to_ xterm256 - Map an RGB triplet to the nearest xterm-256 index in the range 16..=255.
- xterm16_
to_ bios - Convert an xterm-16 index to a BIOS colour index.
- xterm256_
to_ rgb - Look up the RGB value for an xterm-256 index, as
(red, green, blue). - xterm256_
to_ xterm16 - Look up the nearest xterm-16 index for an xterm-256 index.