termcolor

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(s Style, text string, enabled bool) string

func Enabled

func Enabled(mode ColorMode, stdout *os.File) bool

Enabled reports whether colors should be emitted for the provided mode. ModeAlways and ModeNever return constant results, while ModeAuto delegates to the TTY check on stdout (stderr is not considered).

func EnvMap

func EnvMap(values []string) map[string]string

Types

type ColorMode

type ColorMode int
const (
	ModeAuto ColorMode = iota
	ModeAlways
	ModeNever
)

func DetectMode

func DetectMode(stdout *os.File, env map[string]string) ColorMode

DetectMode determines the effective color mode for auto-detection.

Priority order (first match wins):

  1. TERM=dumb suppresses colors entirely.
  2. NO_COLOR disables colors.
  3. CLICOLOR=0 disables colors.
  4. CLICOLOR_FORCE / FORCE_COLOR with any non-zero value force-enable colors.
  5. Otherwise colors are emitted only when stdout is a TTY.

func ParseMode

func ParseMode(v string) (ColorMode, error)

func (ColorMode) String

func (m ColorMode) String() string

type Profile

type Profile int
const (
	ProfileBasic8 Profile = iota
	ProfileANSI256
	ProfileTrueColor
)

func DetectProfile

func DetectProfile(env map[string]string) Profile

DetectProfile inspects COLORTERM/TERM to determine the best-fit color profile. truecolor/24-bit environments get TrueColor, *256color terminals get ANSI256, TERM=dumb and any other terminal names fall back to the basic 8-color profile.

type Scheme

type Scheme int
const (
	SchemeUnknown Scheme = iota
	SchemeDark
	SchemeLight
)

func DetectScheme

func DetectScheme(env map[string]string) Scheme

type Style

type Style struct {
	Bold      bool
	Underline bool
	Dim       bool
	FGBasic   *int
	FG256     *int
	FGTrue    *[3]uint8
}

func AgeStyle

func AgeStyle(age int, profile Profile, maxAge float64) Style

func HeaderStyle

func HeaderStyle() Style

func TypeStyle

func TypeStyle(kind string, scheme Scheme, profile Profile) Style

Jump to

Keyboard shortcuts

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