pub enum Capability {
None,
Palette16,
Palette256,
TrueColor,
}Expand description
Terminal color capability detected from the environment. Truecolor
is preferred when available; None strips all color and keeps only
decorations.
Variants are ordered richest→poorest so cap >= Capability::Palette256
reads “at least 256 colors.” Downgrade logic can branch on ordering
rather than re-matching the ladder each time.
Variants§
Implementations§
Source§impl Capability
impl Capability
Sourcepub fn detect() -> Self
pub fn detect() -> Self
Detect honoring NO_COLOR (per no-color.org). Kept for callers
that want a single-shot detect without threading the env through
a precedence chain.
Sourcepub fn from_terminal() -> Self
pub fn from_terminal() -> Self
Raw terminal capability from supports-color, ignoring
NO_COLOR. The color-policy precedence chain uses this so a
--force-color flag can outrank the env var. Returns None
when stdout isn’t a TTY so color = "auto" stays plain-text
under pipes and redirects.
Sourcepub fn from_env_vars(colorterm: Option<&str>, term: Option<&str>) -> Self
pub fn from_env_vars(colorterm: Option<&str>, term: Option<&str>) -> Self
Env-only capability probe from the COLORTERM and TERM
values carried on CliEnv. Used by the force-color path to
recover a tier when supports-color gives up (e.g. piped
stdout under Claude Code). Never reads the live process env;
callers must snapshot into CliEnv::from_process first so
tests and embedders stay hermetic.
Returns None for TERM=dumb, empty TERM, or no TERM at
all.
Sourcepub fn force_from(tty: Self, env: Self) -> Self
pub fn force_from(tty: Self, env: Self) -> Self
Combine a TTY probe (from supports-color) and an env probe
(from COLORTERM / TERM) into a capability under force-color
intent. Picks the richer of the two, flooring at Palette16
so an explicit color = "always" / --force-color / FORCE_COLOR
never collapses to no-color. The Palette16 floor overrides
TERM=dumb — the user explicitly asked for color, so a dumb
terminal signal loses.
Trait Implementations§
Source§impl Clone for Capability
impl Clone for Capability
Source§fn clone(&self) -> Capability
fn clone(&self) -> Capability
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 Capability
impl Debug for Capability
Source§impl Ord for Capability
impl Ord for Capability
Source§fn cmp(&self, other: &Capability) -> Ordering
fn cmp(&self, other: &Capability) -> Ordering
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for Capability
impl PartialEq for Capability
Source§fn eq(&self, other: &Capability) -> bool
fn eq(&self, other: &Capability) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialOrd for Capability
impl PartialOrd for Capability
impl Copy for Capability
impl Eq for Capability
impl StructuralPartialEq for Capability
Auto Trait Implementations§
impl Freeze for Capability
impl RefUnwindSafe for Capability
impl Send for Capability
impl Sync for Capability
impl Unpin for Capability
impl UnsafeUnpin for Capability
impl UnwindSafe for Capability
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.