Involved Source Files Package colorprofile provides a way to downsample ANSI escape sequence
colors and styles automatically based on output, environment variables, and
Terminfo databases.env.goenv_other.goprofile.gowriter.go
Package-Level Type Names (total 3, in which 2 are exported)
Writer represents a color profile writer that writes ANSI sequences to the
underlying writer.Forwardio.WriterProfileProfile Write writes the given text to the underlying writer. WriteString writes the given text to the underlying writer. downsample downgrades the given text to the appropriate color profile.
*Writer : internal/bisect.Writer
*Writer : io.StringWriter
*Writer : io.Writer
*Writer : crypto/tls.transcriptHash
*Writer : golang.org/x/net/http2.stringWriter
*Writer : testing.stringWriter
func NewWriter(w io.Writer, environ []string) *Writer
func handleSgr(w *Writer, p *ansi.Parser, buf *bytes.Buffer)
var charm.land/lipgloss/v2.Writer *Writer
Package-Level Functions (total 16, in which 5 are exported)
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.
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.
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.
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.
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.