colors

package
v1.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 4 Imported by: 0

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

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

func For(w io.Writer) Palette

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) Current added in v1.4.3

func (p Palette) Current(a ...any) string

Current formats the "(current)" marker in green.

func (Palette) DiffAdded added in v1.4.3

func (p Palette) DiffAdded(a ...any) string

DiffAdded formats added lines (+) in green.

func (Palette) DiffHeader added in v1.4.3

func (p Palette) DiffHeader(a ...any) string

DiffHeader formats diff header lines (---/+++) in cyan.

func (Palette) DiffHunk added in v1.4.3

func (p Palette) DiffHunk(a ...any) string

DiffHunk formats diff hunk markers (@@) in cyan.

func (Palette) DiffRemoved added in v1.4.3

func (p Palette) DiffRemoved(a ...any) string

DiffRemoved formats removed lines (-) in red.

func (Palette) Enabled added in v1.4.3

func (p Palette) Enabled() bool

Enabled reports whether this palette emits ANSI color.

func (Palette) Error added in v1.4.3

func (p Palette) Error(a ...any) string

Error formats text in red for error messages.

func (Palette) Failed added in v1.4.3

func (p Palette) Failed(a ...any) string

Failed formats "Failed" text in red.

func (Palette) FieldLabel added in v1.4.3

func (p Palette) FieldLabel(a ...any) string

FieldLabel formats field labels (e.g., "Date:", "Value:") in cyan.

func (Palette) Info added in v1.4.3

func (p Palette) Info(a ...any) string

Info formats text in cyan for informational messages.

func (Palette) OpAdd added in v1.4.3

func (p Palette) OpAdd(a ...any) string

OpAdd formats the add operation indicator (A) in green.

func (Palette) OpDelete added in v1.4.3

func (p Palette) OpDelete(a ...any) string

OpDelete formats the delete operation indicator (D) in red.

func (Palette) OpModify added in v1.4.3

func (p Palette) OpModify(a ...any) string

OpModify formats the modify operation indicator (M) in green.

func (Palette) Success added in v1.4.3

func (p Palette) Success(a ...any) string

Success formats text in green for success messages.

func (Palette) Version added in v1.4.3

func (p Palette) Version(a ...any) string

Version formats version numbers in yellow.

func (Palette) Warning added in v1.4.3

func (p Palette) Warning(a ...any) string

Warning formats text in yellow for warning messages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL