Skip to main content

ColorSupport

Enum ColorSupport 

Source
#[non_exhaustive]
pub enum ColorSupport { Unknown, Ansi16, Ansi256, TrueColor, }
Expand description

Color encodings a terminal is inferred to support, not a measured capability.

Unknown means there is not enough evidence. It does not mean that color is unsupported, so each application should choose its own default. The enum is non-exhaustive.

User preferences such as NO_COLOR and whether output is a TTY do not affect this value.

§Exact and minimum checks

Use a supports_* method to decide whether a color encoding can be used. Each is true for its level and every higher one. Use an is_* method only to ask which variant was inferred, as each matches exactly one.

MethodUnknownAnsi16Ansi256TrueColor
is_unknown()truefalsefalsefalse
is_ansi16()falsetruefalsefalse
is_ansi256()falsefalsetruefalse
is_true_color()falsefalsefalsetrue
supports_ansi16()falsetruetruetrue
supports_ansi256()falsefalsetruetrue
supports_true_color()falsefalsefalsetrue

For Unknown, false from a supports_* method means that support was not inferred, not that it is absent. Check is_unknown first to apply a different default.

use detect_terminal::ColorSupport;

// A truecolor terminal can use the 256-color palette, but that is not its inferred variant.
assert!(ColorSupport::TrueColor.supports_ansi256());
assert!(!ColorSupport::TrueColor.is_ansi256());

// Nothing is inferred for an unknown terminal.
assert!(!ColorSupport::Unknown.supports_ansi16());
assert!(ColorSupport::Unknown.is_unknown());

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Unknown

The available hints do not establish color support.

§

Ansi16

The 16 ANSI colors. No current rule selects this variant.

§

Ansi256

The 256-color indexed palette, without reliable RGB support.

§

TrueColor

24-bit RGB colors are accepted, though tmux can convert them for its outer terminal.

Implementations§

Source§

impl ColorSupport

Source

pub const fn is_unknown(self) -> bool

Returns whether there is not enough evidence to infer color support.

This does not mean that color is unsupported.

Source

pub const fn is_ansi16(self) -> bool

Returns whether the inferred support is exactly the 16 ANSI colors.

False for variants with more colors; use supports_ansi16 to include them. No current detection rule selects Ansi16.

Source

pub const fn is_ansi256(self) -> bool

Returns whether the inferred support is exactly the 256-color palette.

False for TrueColor; use supports_ansi256 to include it.

Source

pub const fn is_true_color(self) -> bool

Returns whether 24-bit RGB colors are inferred to be accepted.

False for Unknown, where the terminal might still accept RGB.

Source

pub const fn supports_ansi16(self) -> bool

Returns whether at least the 16 ANSI colors are inferred to be supported.

False for Unknown, where the terminal might still support them.

Source

pub const fn supports_ansi256(self) -> bool

Returns whether at least the 256-color palette is inferred to be supported.

False for Unknown, where the terminal might still support it.

Source

pub const fn supports_true_color(self) -> bool

Returns whether 24-bit RGB colors are inferred to be accepted.

Currently equivalent to is_true_color, as no variant has more colors. False for Unknown, where the terminal might still accept RGB.

Trait Implementations§

Source§

impl Clone for ColorSupport

Source§

fn clone(&self) -> Self

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 ColorSupport

Source§

impl Debug for ColorSupport

Source§

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

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

impl Display for ColorSupport

Source§

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

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

impl Eq for ColorSupport

Source§

impl Hash for ColorSupport

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 ColorSupport

Source§

fn eq(&self, other: &Self) -> 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 ColorSupport

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.