Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Profile ¶
type Profile byte
Profile is a color profile: NoTTY, Ascii, ANSI, ANSI256, or TrueColor.
func Detect ¶
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 gest 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.
func Env ¶
Env returns the color profile based on the terminal 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 gest 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.
func Terminfo ¶ added in v0.1.10
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.
func Tmux ¶ added in v0.1.10
Tmux returns the color profile based on `tmux info` output. Tmux supports overriding the terminal's color capabilities, so this function will return the color profile based on the tmux configuration.
type Writer ¶
Writer represents a color profile writer that writes ANSI sequences to the underlying writer.
func NewWriter ¶
NewWriter creates a new color profile writer that downgrades color sequences based on the detected color profile.
If environ is nil, it will use os.Environ() to get the environment variables.
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.