pub enum ColorChoice {
Auto,
Always,
Never,
}Expand description
How to resolve whether to emit ANSI color codes. Parsed from
--color=<auto|always|never>.
On Auto, ColorChoice::resolve consults the
CLICOLOR_FORCE env var (which anstream does NOT check on
its own) and pre-resolves to Always when it’s set to
anything other than "0". The resulting choice is then
handed to anstream::AutoStream, which honors NO_COLOR and
the TTY check on the remaining Auto cases.
Always / Never are explicit user overrides and bypass the
env-var resolution entirely — useful when piping into a pager
that understands ANSI, or when capturing output for a
snapshot test.
Precedence summary:
--color | env | result |
|---|---|---|
always | (any) | colors on |
never | (any) | colors off |
auto | CLICOLOR_FORCE=1 | colors on |
auto | NO_COLOR=… (any value) | colors off |
auto | TTY | colors on |
auto | non-TTY | colors off |
CLICOLOR_FORCE=0 (or unset) is treated as “no force”; only
1 (or any non-"0" value) forces colors on.
Variants§
Implementations§
Source§impl ColorChoice
impl ColorChoice
Sourcepub fn resolve(self) -> Self
pub fn resolve(self) -> Self
Pre-resolve Auto against the CLICOLOR_FORCE env var
before handing off to anstream. Auto + CLICOLOR_FORCE
→ Always; everything else returns self unchanged.
anstream::ColorChoice::Auto already honors NO_COLOR
and the TTY check, so we don’t intercept those — the
only env-var contract anstream doesn’t cover is
CLICOLOR_FORCE, which this method adds.
Sourcepub fn to_anstream(self) -> ColorChoice
pub fn to_anstream(self) -> ColorChoice
Map to anstream’s own enum so AutoStream::new accepts
it directly. Callers should normally call
ColorChoice::resolve first to pre-apply the
CLICOLOR_FORCE precedence.
Trait Implementations§
Source§impl Clone for ColorChoice
impl Clone for ColorChoice
Source§fn clone(&self) -> ColorChoice
fn clone(&self) -> ColorChoice
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ColorChoice
Source§impl Debug for ColorChoice
impl Debug for ColorChoice
Source§impl Default for ColorChoice
impl Default for ColorChoice
Source§fn default() -> ColorChoice
fn default() -> ColorChoice
impl Eq for ColorChoice
Source§impl FromStr for ColorChoice
impl FromStr for ColorChoice
Source§impl PartialEq for ColorChoice
impl PartialEq for ColorChoice
Source§fn eq(&self, other: &ColorChoice) -> bool
fn eq(&self, other: &ColorChoice) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for ColorChoice
Auto Trait Implementations§
impl Freeze for ColorChoice
impl RefUnwindSafe for ColorChoice
impl Send for ColorChoice
impl Sync for ColorChoice
impl Unpin for ColorChoice
impl UnsafeUnpin for ColorChoice
impl UnwindSafe for ColorChoice
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> 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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more