Skip to main content

ColorDepth

Enum ColorDepth 

Source
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

Source

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

  1. If COLORTERM is set to "truecolor" or "24bit" (case-sensitive, matching the upstream toilet convention), return Self::Truecolor.
  2. 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

Source§

fn clone(&self) -> ColorDepth

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ColorDepth

Source§

impl Debug for ColorDepth

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ColorDepth

Source§

fn default() -> ColorDepth

Returns the “default value” for a type. Read more
Source§

impl Eq for ColorDepth

Source§

impl Hash for ColorDepth

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ColorDepth

Source§

fn eq(&self, other: &ColorDepth) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ColorDepth

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.