Color-support
ColorSupport is the public enum that controls how much color precision a text formatter should use when ANSI color output is enabled. It is a direct alias to the formatter enum used by both runtime formatters and serializable formatter config.
Interface
pub type ColorSupport = @utils.ColorSupportoutput
ColorSupport- Public formatter color-capability enum with the variantsBasicandTrueColor.
Explanation
Detailed rules explaining key parameters and behaviors
- This is a type alias, not a wrapper or a separate rendering engine.
ColorSupport::Basicprefers named/basic ANSI color codes.ColorSupport::TrueColorallows 24-bit color codes when the style input uses values such as hex colors.- This setting only matters when color output is enabled through
ColorMode. - The same enum is used by
text_formatter(...)andTextFormatterConfig::new(...).
How to Use
Here are some specific examples provided.
When Need Conservative Basic ANSI Colors
When output should stay within the smaller named ANSI color set:
let formatter = text_formatter(
color_mode=ColorMode::Always,
color_support=ColorSupport::Basic,
)In this example, style rendering prefers the basic color vocabulary instead of 24-bit codes.
When Need Hex-style Richer Color Rendering
When custom style tags should preserve truecolor output where possible:
let formatter = text_formatter(
color_mode=ColorMode::Always,
color_support=ColorSupport::TrueColor,
)In this example, formatter styles can emit richer ANSI color codes for hex-based styles.
Error Case
e.g.:
ColorSupportitself does not have a runtime failure mode.If
ColorMode::Neverdisables ANSI color output, changingColorSupportdoes not produce a visible effect.
Notes
Use
color_support_label(...)when you need a stable string form.This enum controls color precision, not whether color rendering is enabled at all.