#[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.
| Method | Unknown | Ansi16 | Ansi256 | TrueColor |
|---|---|---|---|---|
is_unknown() | true | false | false | false |
is_ansi16() | false | true | false | false |
is_ansi256() | false | false | true | false |
is_true_color() | false | false | false | true |
supports_ansi16() | false | true | true | true |
supports_ansi256() | false | false | true | true |
supports_true_color() | false | false | false | true |
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
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
impl ColorSupport
Sourcepub const fn is_unknown(self) -> bool
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.
Sourcepub const fn is_ansi16(self) -> bool
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.
Sourcepub const fn is_ansi256(self) -> bool
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.
Sourcepub const fn is_true_color(self) -> bool
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.
Sourcepub const fn supports_ansi16(self) -> bool
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.
Sourcepub const fn supports_ansi256(self) -> bool
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.
Sourcepub const fn supports_true_color(self) -> bool
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.