Guide API
Skip to main content

tvision_rs/backend/
mod.rs

1//! The platform seam: everything that touches the terminal lives behind a
2//! single trait, so the rest of the framework stays terminal-agnostic.
3//!
4//! ## Color quantization
5//!
6//! Pure color-mapping math: `RGB → xterm-256 → xterm-16 → BIOS`. All functions
7//! are const-capable and I/O-free, so a backend can downsample any color to the
8//! depth its terminal supports. They operate on raw `u8` channel values and
9//! palette indices and are decoupled from the [`Color`](crate::color::Color)
10//! enum: the [`Backend`] assembles the capability-aware policy that decides
11//! which rung of the ladder to use.
12//!
13//! Turbo Vision heritage: the functions port `RGBtoXTerm16`, `RGBtoXTerm256`,
14//! `BIOStoXTerm16` and the related helpers from `colors.cpp` / `colors.h`. The
15//! math is reproduced verbatim; only the storage is typed (`u8` channels rather
16//! than packed bytes).
17//!
18//! ## Backend trait + implementations
19//!
20//! The [`Backend`] trait is the seam between the framework and the terminal.
21//! Two implementations are provided:
22//!
23//! - [`CrosstermBackend`] — production, wraps crossterm.
24//! - [`HeadlessBackend`] + [`HeadlessHandle`] — tests, in-memory buffer.
25//!
26//! [`Renderer`] owns the back/front buffer pair and a boxed backend; it runs the
27//! draw cycle (reset → paint → diff → draw → flush → swap), painting the whole
28//! view tree each frame and relying on the diff to keep terminal output minimal.
29//!
30//! **Guide:** [Drawing & backends](../../../internals/drawing.html).
31
32mod clipboard;
33mod crossterm_backend;
34mod headless;
35mod quantize;
36mod renderer;
37mod traits;
38
39pub use crossterm_backend::{ColorDepth, CrosstermBackend};
40pub use headless::{HeadlessBackend, HeadlessHandle};
41pub use quantize::*;
42pub use renderer::Renderer;
43pub use traits::{Backend, CARET_INSERT, CARET_NORMAL};