pub enum Profile {
Disabled,
Ascii,
Ansi,
Ansi256,
TrueColor,
}Expand description
Terminal color capability profile.
Profiles are ordered by increasing capability:
Disabled < Ascii < Ansi < Ansi256 < TrueColor. Use this ordering when
clamping or choosing the maximum capability discovered from multiple
sources.
Variants§
Disabled
No styling output at all.
Used for non-TTY output and terminals that should not receive escape
sequences. Color conversion returns None; callers that convert whole
styles generally drop colors, attributes, underline state, and links.
Ascii
ASCII/no-color profile where text decoration is still allowed.
Color conversion returns None, but higher-level style conversion may
preserve non-color SGR attributes such as bold or underline.
Ansi
Standard 16-color ANSI palette.
Color conversion returns the nearest named Color
using weighted RGB distance against the xterm palette entries 0..=15.
Ansi256
xterm 256-color palette.
Color conversion returns the nearest
Color::Indexed, choosing between the 6×6×6
color cube and grayscale ramp by weighted RGB distance.
TrueColor
24-bit true color.
Color conversion returns the original Color unchanged.
Implementations§
Source§impl Profile
impl Profile
Sourcepub fn convert(self, color: Color) -> Option<Color>
pub fn convert(self, color: Color) -> Option<Color>
Downsample a color to fit this profile.
Returns Some(color) when this profile supports color output and
None for Profile::Disabled or Profile::Ascii. TrueColor
preserves the original value; Ansi256 and Ansi resolve the input to
RGB and quantize to the nearest supported palette.
Sourcepub fn detect() -> Self
pub fn detect() -> Self
Detect the color profile from the current process environment.
This assumes the output stream is a TTY. For explicit TTY state or
deterministic tests, use Profile::detect_from.
Sourcepub fn detect_from(env: &Env, is_tty: bool) -> Self
pub fn detect_from(env: &Env, is_tty: bool) -> Self
Detect the color profile from an explicit environment snapshot.
is_tty should be true if the output stream is a terminal. A false
value clamps to Profile::Disabled unless TTY_FORCE makes the
stream act like a TTY or CLICOLOR_FORCE forces color. TERM=dumb and,
on non-Windows platforms, an empty TERM start as disabled before other
forcing/upgrading rules are applied.