Documentation
¶
Overview ¶
Package colors provides per-destination colored output for the CLI.
Coloring is decided per destination writer rather than from a process-global: fatih/color's package-global NoColor is set once from whether os.Stdout is a TTY, which is wrong for anything written to os.Stderr (or any other writer). Every colored string therefore goes through a Palette bound to the writer it will be written to, so its color tracks that writer's own TTY-ness and stays correct under redirection like `suve … 2>err.log` or `suve … | cat` (#341).
Index ¶
- type Palette
- func (p Palette) Current(a ...any) string
- func (p Palette) DiffAdded(a ...any) string
- func (p Palette) DiffHeader(a ...any) string
- func (p Palette) DiffHunk(a ...any) string
- func (p Palette) DiffRemoved(a ...any) string
- func (p Palette) Enabled() bool
- func (p Palette) Error(a ...any) string
- func (p Palette) Failed(a ...any) string
- func (p Palette) FieldLabel(a ...any) string
- func (p Palette) Info(a ...any) string
- func (p Palette) OpAdd(a ...any) string
- func (p Palette) OpDelete(a ...any) string
- func (p Palette) OpModify(a ...any) string
- func (p Palette) Success(a ...any) string
- func (p Palette) Version(a ...any) string
- func (p Palette) Warning(a ...any) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Palette ¶ added in v1.4.3
type Palette struct {
// contains filtered or unexported fields
}
Palette renders colored text for a single destination writer. Obtain one with For(w) and use its methods to color strings destined for w.
func For ¶ added in v1.4.3
For returns a Palette whose coloring is enabled only when NO_COLOR is unset and w is a terminal. Deciding this per writer (rather than from the os.Stdout-derived process-global) is what keeps each stream's color correct.
func (Palette) DiffHeader ¶ added in v1.4.3
DiffHeader formats diff header lines (---/+++) in cyan.
func (Palette) DiffRemoved ¶ added in v1.4.3
DiffRemoved formats removed lines (-) in red.
func (Palette) FieldLabel ¶ added in v1.4.3
FieldLabel formats field labels (e.g., "Date:", "Value:") in cyan.
func (Palette) OpDelete ¶ added in v1.4.3
OpDelete formats the delete operation indicator (D) in red.
func (Palette) OpModify ¶ added in v1.4.3
OpModify formats the modify operation indicator (M) in green.