Colorprofile
Profile is a color profile: NoTTY, Ascii, ANSI, ANSI256, or TrueColor.
Constants
Ascii is an alias for the ASCII profile for backwards compatibility.
Class methods
Detect returns the color profile based on the terminal output, and environment variables. This respects NO_COLOR, CLICOLOR, and CLICOLOR_FORCE environment variables.
The rules as follows:
- TERM=dumb is always treated as NoTTY unless CLICOLOR_FORCE=1 is set.
- If COLORTERM=truecolor, and the profile is not NoTTY, it gets upgraded to TrueColor.
- Using any 256 color terminal (e.g. TERM=xterm-256color) will set the profile to ANSI256.
- Using any color terminal (e.g. TERM=xterm-color) will set the profile to ANSI.
- Using CLICOLOR=1 without TERM defined should be treated as ANSI if the output is a terminal.
- NO_COLOR takes precedence over CLICOLOR/CLICOLOR_FORCE, and will disable colors but not text decoration, i.e. bold, italic, faint, etc.
See https://no-color.org/ and https://bixense.com/clicolors/ for more information.
Env returns the color profile based on the terminal environment variables. This respects NO_COLOR, CLICOLOR, and CLICOLOR_FORCE environment variables.
new_environ returns a new environment map from a slice of environment variables.
NewWriter creates a new color profile writer that downgrades color sequences based on the detected color profile.
If environ is nil, it will use environment variables from ENV.
It queries the given writer to determine if it supports ANSI escape codes. If it does, along with the given environment variables, it will determine the appropriate color profile to use for color formatting.
This respects the NO_COLOR, CLICOLOR, and CLICOLOR_FORCE environment variables.
Terminfo returns the color profile based on the terminal's terminfo database. This relies on the Tc and RGB capabilities to determine if the terminal supports TrueColor. If term is empty or "dumb", it returns NoTTY.