Color-mode
ColorMode is the public enum that controls when ANSI color rendering is enabled for text formatting. It is a direct alias to the formatter enum used by both text_formatter(...) and TextFormatterConfig::new(...).
Interface
pub type ColorMode = @utils.ColorModeoutput
ColorMode- Public formatter color-policy enum with the variantsNever,Auto, andAlways.
Explanation
Detailed rules explaining key parameters and behaviors
- This is a type alias, not a wrapper or a separate formatter mode.
ColorMode::Neverdisables ANSI color output.ColorMode::Alwaysalways enables ANSI color rendering.ColorMode::Autocurrently follows the built-inNO_COLORenvironment check.- The same enum is used by runtime formatters and serializable formatter config objects.
How to Use
Here are some specific examples provided.
When Need Plain Text Without ANSI Codes
When logs should stay uncolored even if the terminal supports color:
let formatter = text_formatter(color_mode=ColorMode::Never)In this example, rendered text keeps the formatter output readable without ANSI escape sequences.
When Need Forced Terminal Colors
When tests or demos should always emit colored output:
let formatter = text_formatter(color_mode=ColorMode::Always)In this example, ANSI color rendering is enabled regardless of NO_COLOR.
Error Case
e.g.:
ColorModeitself does not have a runtime failure mode.ColorMode::Autois policy-based, so the final visible result still depends on environment state such asNO_COLOR.
Notes
Use
color_mode_label(...)when you need a stable string form for diagnostics or tests.This enum controls whether color is used, while
ColorSupportcontrols how rich the color encoding can be.