Guide API
Skip to main content

Module backend

Module backend 

Source
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:

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§

CrosstermBackend
Production backend backed by crossterm.
HeadlessBackend
In-memory backend for deterministic tests.
HeadlessHandle
A cloneable window into a HeadlessBackend’s screen and event queue.
Renderer
Owns the back/front buffer pair and a boxed Backend.

Enums§

ColorDepth
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.
XTERM256_TO_RGB
LUT: xterm-256 index → packed 0xRRGGBB.
XTERM256_TO_XTERM16
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.