pub enum ColorDepth {
Truecolor,
Color256,
Color16,
}Expand description
Color depth rung used by the SGR emitters and the Figlet render path.
Ordering: Truecolor > Color256 > Color16. ColorDepth::detect returns
the highest rung the current terminal advertises. resolve_depth
downgrades a requested rung to the detected rung when the terminal
cannot honor it, emitting a fixed warning unless suppressed.
Variants§
Truecolor
24-bit truecolor (\x1b[38;2;R;G;Bm). Advertised by COLORTERM=truecolor
or COLORTERM=24bit. Highest rung.
Color256
256-color indexed palette (\x1b[38;5;Nm). Middle rung.
Color16
16-color ANSI named palette (\x1b[30m..37m, \x1b[90m..97m). Lowest
rung; always available on any ANSI-compatible terminal.
Implementations§
Source§impl ColorDepth
impl ColorDepth
Sourcepub fn detect() -> Self
pub fn detect() -> Self
Detect the highest color depth the current terminal advertises.
§Cache contract (FR-031)
This function is intended to be called once at builder time
(FigletBuilder::build); the result is cached on the crate::Figlet
renderer for its lifetime. The render path NEVER calls detect —
invalidation is caller-driven only via crate::Figlet::set_color_depth.
Calling detect is O(1) + one syscall (isatty) + one env-var read.
Detection rules (per spec Edge Cases + FR-010):
- If
COLORTERMis set to"truecolor"or"24bit"(case-sensitive, matching the upstream toilet convention), returnSelf::Truecolor. - Otherwise return
Self::Color16— the safe lowest-common-denominator rung that any ANSI-compatible terminal honors.
256-color is NOT auto-detected because no portable environment variable
reliably signals 256-color support — TERM=xterm-256color is a hint but
not a contract. Callers who want 256-color SHOULD pass it explicitly via
resolve_depth.
The isatty probe is performed only when std::io::IsTerminal is
available; non-TTY stdout (e.g., piped to a file) returns Self::Color16
regardless of COLORTERM so redirected output is not polluted with
24-bit escapes that the consuming program won’t strip.
Trait Implementations§
Source§impl Clone for ColorDepth
impl Clone for ColorDepth
Source§fn clone(&self) -> ColorDepth
fn clone(&self) -> ColorDepth
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ColorDepth
impl Debug for ColorDepth
Source§impl Default for ColorDepth
impl Default for ColorDepth
Source§fn default() -> ColorDepth
fn default() -> ColorDepth
Source§impl Hash for ColorDepth
impl Hash for ColorDepth
Source§impl PartialEq for ColorDepth
impl PartialEq for ColorDepth
Source§fn eq(&self, other: &ColorDepth) -> bool
fn eq(&self, other: &ColorDepth) -> bool
self and other values to be equal, and is used by ==.