color

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package color handles terminal color capability detection and color conversion. Detection is auto-derived from environment variables and can be overridden via the config color_level field.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveColorName

func ResolveColorName(colorName string) string

ResolveColorName converts a CSS/ANSI color name to the numeric string equivalent expected by lipgloss.Color(). Hex strings ("#rrggbb") and numeric strings ("2", "114") pass through unchanged. Unrecognised names also pass through, which lets lipgloss handle them (it returns noColor for unknown values, which is the same behaviour as before this function existed).

This is the canonical resolver for all color strings in the config system. Both the widget and render packages call this before passing config color values to lipgloss.Color().

Types

type Level

type Level int

Level represents the color depth supported by the terminal.

const (
	// LevelBasic supports the 16 standard ANSI colors (30-37, 90-97).
	LevelBasic Level = iota
	// Level256 supports 256-color mode via ANSI escape sequences.
	Level256
	// LevelTruecolor supports 24-bit RGB color.
	LevelTruecolor
)

func DetectLevel

func DetectLevel() Level

DetectLevel returns the color level from the environment. Detection order:

  1. COLORTERM=truecolor or 24bit → LevelTruecolor
  2. TERM is a known truecolor terminal → LevelTruecolor
  3. TERM_PROGRAM is a known truecolor application → LevelTruecolor
  4. TERM contains "256color" → Level256
  5. Default → LevelBasic

The caller is responsible for applying any config override before calling this function (see ParseLevel / LevelFromConfig).

func LevelFromConfig

func LevelFromConfig(override string) Level

LevelFromConfig resolves the effective Level given a config override string. When override is "auto" or empty, DetectLevel is called. Otherwise ParseLevel is attempted; unrecognised values fall back to DetectLevel.

func ParseLevel

func ParseLevel(s string) (Level, bool)

ParseLevel converts a config string to a Level. Accepted values: "truecolor", "256", "basic". Unknown values return LevelBasic and false.

func (Level) ColorProfile

func (l Level) ColorProfile() colorprofile.Profile

ColorProfile converts a Level to the corresponding colorprofile.Profile so callers can apply the level to lipgloss's global writer without importing colorprofile directly.

func (Level) String

func (l Level) String() string

String returns the canonical name for a Level.

Jump to

Keyboard shortcuts

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