Documentation
¶
Overview ¶
Package eval provides color math and terminal palette utilities for evaluating widget contrast and theme coherence. This is non-production test tooling — it is not in the hot path.
Package eval provides a graded design report for rendered statusline output. It wires together the color math (color.go), terminal palettes (palette.go), and ANSI parser (parse.go) to score four dimensions of visual quality: contrast, coherence, hierarchy, and adaptability.
Package eval provides tools for inspecting rendered ANSI output from the statusline. Parse() decodes escape sequences into structured segments so downstream code can reason about colors and attributes without dealing with raw escape bytes.
Index ¶
- Variables
- func ContrastRatio(fg, bg RGB) float64
- func FormatReport(report Report) string
- func HueDelta(h1, h2 float64) float64
- func RGBToHSL(c RGB) (h, s, l float64)
- func RelativeLuminance(c RGB) float64
- type Color
- type ColorType
- type DimensionResult
- type Grade
- type RGB
- type Report
- type StyledSegment
- type TerminalPalette
Constants ¶
This section is empty.
Variables ¶
var CatppuccinMocha = TerminalPalette{ Name: "CatppuccinMocha", DefaultFg: RGB{0xcd, 0xd6, 0xf4}, DefaultBg: RGB{0x1e, 0x1e, 0x2e}, Colors: [16]RGB{ {0x45, 0x47, 0x5a}, {0xf3, 0x8b, 0xa8}, {0xa6, 0xe3, 0xa1}, {0xf9, 0xe2, 0xaf}, {0x89, 0xb4, 0xfa}, {0xf5, 0xc2, 0xe7}, {0x94, 0xe2, 0xd5}, {0xba, 0xc2, 0xde}, {0x58, 0x5b, 0x70}, {0xf3, 0x8b, 0xa8}, {0xa6, 0xe3, 0xa1}, {0xf9, 0xe2, 0xaf}, {0x89, 0xb4, 0xfa}, {0xf5, 0xc2, 0xe7}, {0x94, 0xe2, 0xd5}, {0xcd, 0xd6, 0xf4}, }, }
CatppuccinMocha uses the Catppuccin Mocha color scheme. Source: https://github.com/catppuccin/catppuccin
var Dracula = TerminalPalette{ Name: "Dracula", DefaultFg: RGB{0xf8, 0xf8, 0xf2}, DefaultBg: RGB{0x28, 0x2a, 0x36}, Colors: [16]RGB{ {0x21, 0x22, 0x2c}, {0xff, 0x55, 0x55}, {0x50, 0xfa, 0x7b}, {0xf1, 0xfa, 0x8c}, {0xbd, 0x93, 0xf9}, {0xff, 0x79, 0xc6}, {0x8b, 0xe9, 0xfd}, {0xf8, 0xf8, 0xf2}, {0x6a, 0x71, 0x86}, {0xff, 0x6e, 0x6e}, {0x69, 0xff, 0x94}, {0xff, 0xff, 0xa5}, {0xd6, 0xac, 0xff}, {0xff, 0x92, 0xdf}, {0xa4, 0xff, 0xff}, {0xff, 0xff, 0xff}, }, }
Dracula uses the Dracula color scheme. Source: https://github.com/dracula/dracula-theme
var GruvboxDark = TerminalPalette{ Name: "GruvboxDark", DefaultFg: RGB{0xeb, 0xdb, 0xb2}, DefaultBg: RGB{0x28, 0x28, 0x28}, Colors: [16]RGB{ {0x28, 0x28, 0x28}, {0xcc, 0x24, 0x1d}, {0x98, 0x97, 0x1a}, {0xd7, 0x99, 0x21}, {0x45, 0x85, 0x88}, {0xb1, 0x62, 0x86}, {0x68, 0x9d, 0x6a}, {0xa8, 0x99, 0x84}, {0x92, 0x83, 0x74}, {0xfb, 0x49, 0x34}, {0xb8, 0xbb, 0x26}, {0xfa, 0xbd, 0x2f}, {0x83, 0xa5, 0x98}, {0xd3, 0x86, 0x9b}, {0x8e, 0xc0, 0x7c}, {0xeb, 0xdb, 0xb2}, }, }
GruvboxDark uses the Gruvbox dark color scheme by morhetz. Source: https://github.com/morhetz/gruvbox
var Nord = TerminalPalette{ Name: "Nord", DefaultFg: RGB{0xd8, 0xde, 0xe9}, DefaultBg: RGB{0x2e, 0x34, 0x40}, Colors: [16]RGB{ {0x3b, 0x42, 0x52}, {0xbf, 0x61, 0x6a}, {0xa3, 0xbe, 0x8c}, {0xeb, 0xcb, 0x8b}, {0x81, 0xa1, 0xc1}, {0xb4, 0x8e, 0xad}, {0x88, 0xc0, 0xd0}, {0xe5, 0xe9, 0xf0}, {0x4c, 0x56, 0x6a}, {0xbf, 0x61, 0x6a}, {0xa3, 0xbe, 0x8c}, {0xeb, 0xcb, 0x8b}, {0x81, 0xa1, 0xc1}, {0xb4, 0x8e, 0xad}, {0x8f, 0xbc, 0xbb}, {0xec, 0xef, 0xf4}, }, }
Nord uses the Nord color scheme by Arctic Ice Studio. Source: https://www.nordtheme.com/
var SolarizedDark = TerminalPalette{ Name: "SolarizedDark", DefaultFg: RGB{0x83, 0x94, 0x96}, DefaultBg: RGB{0x00, 0x2b, 0x36}, Colors: [16]RGB{ {0x07, 0x36, 0x42}, {0xdc, 0x32, 0x2f}, {0x85, 0x99, 0x00}, {0xb5, 0x89, 0x00}, {0x26, 0x8b, 0xd2}, {0xd3, 0x36, 0x82}, {0x2a, 0xa1, 0x98}, {0xee, 0xe8, 0xd5}, {0x00, 0x2b, 0x36}, {0xcb, 0x4b, 0x16}, {0x58, 0x6e, 0x75}, {0x65, 0x7b, 0x83}, {0x83, 0x94, 0x96}, {0x6c, 0x71, 0xc4}, {0x93, 0xa1, 0xa1}, {0xfd, 0xf6, 0xe3}, }, }
SolarizedDark uses Ethan Schoonover's Solarized dark scheme. Source: https://ethanschoonover.com/solarized/
var SolarizedLight = TerminalPalette{ Name: "SolarizedLight", DefaultFg: RGB{0x65, 0x7b, 0x83}, DefaultBg: RGB{0xfd, 0xf6, 0xe3}, Colors: [16]RGB{ {0x07, 0x36, 0x42}, {0xdc, 0x32, 0x2f}, {0x85, 0x99, 0x00}, {0xb5, 0x89, 0x00}, {0x26, 0x8b, 0xd2}, {0xd3, 0x36, 0x82}, {0x2a, 0xa1, 0x98}, {0xee, 0xe8, 0xd5}, {0x00, 0x2b, 0x36}, {0xcb, 0x4b, 0x16}, {0x58, 0x6e, 0x75}, {0x65, 0x7b, 0x83}, {0x83, 0x94, 0x96}, {0x6c, 0x71, 0xc4}, {0x93, 0xa1, 0xa1}, {0xfd, 0xf6, 0xe3}, }, }
SolarizedLight uses Ethan Schoonover's Solarized light scheme. Source: https://ethanschoonover.com/solarized/
var TokyoNight = TerminalPalette{ Name: "TokyoNight", DefaultFg: RGB{0xc0, 0xca, 0xf5}, DefaultBg: RGB{0x1a, 0x1b, 0x26}, Colors: [16]RGB{ {0x15, 0x16, 0x22}, {0xf7, 0x76, 0x8e}, {0x9e, 0xce, 0x6a}, {0xe0, 0xaf, 0x68}, {0x7a, 0xa2, 0xf7}, {0xbb, 0x9a, 0xf7}, {0x7d, 0xcf, 0xff}, {0xa9, 0xb1, 0xd6}, {0x41, 0x44, 0x68}, {0xf7, 0x76, 0x8e}, {0x9e, 0xce, 0x6a}, {0xe0, 0xaf, 0x68}, {0x7a, 0xa2, 0xf7}, {0xbb, 0x9a, 0xf7}, {0x7d, 0xcf, 0xff}, {0xc0, 0xca, 0xf5}, }, }
TokyoNight uses the Tokyo Night color scheme by enkia. Source: https://github.com/enkia/tokyo-night-vscode-theme
var XtermDefault = TerminalPalette{ Name: "XtermDefault", DefaultFg: RGB{0xc0, 0xc0, 0xc0}, DefaultBg: RGB{0x00, 0x00, 0x00}, Colors: [16]RGB{ {0x00, 0x00, 0x00}, {0x80, 0x00, 0x00}, {0x00, 0x80, 0x00}, {0x80, 0x80, 0x00}, {0x00, 0x00, 0x80}, {0x80, 0x00, 0x80}, {0x00, 0x80, 0x80}, {0xc0, 0xc0, 0xc0}, {0x80, 0x80, 0x80}, {0xff, 0x00, 0x00}, {0x00, 0xff, 0x00}, {0xff, 0xff, 0x00}, {0x00, 0x00, 0xff}, {0xff, 0x00, 0xff}, {0x00, 0xff, 0xff}, {0xff, 0xff, 0xff}, }, }
XtermDefault uses the canonical xterm default colors. Fg: Silver (#c0c0c0), Bg: Black (#000000).
Functions ¶
func ContrastRatio ¶
ContrastRatio returns the WCAG 2.1 contrast ratio between two colors. The result is in the range [1, 21]. A ratio of 21 means maximum contrast (black on white); 1 means no contrast (identical colors).
func FormatReport ¶
FormatReport formats a Report as human-readable text suitable for logging or terminal output.
func HueDelta ¶
HueDelta returns the shortest arc distance between two hue values in degrees. The result is always in [0, 180].
func RGBToHSL ¶
RGBToHSL converts an RGB color to HSL (hue, saturation, lightness). Hue is in degrees [0, 360), saturation and lightness are in [0, 1].
func RelativeLuminance ¶
RelativeLuminance returns the WCAG 2.1 relative luminance of an RGB color. The result is in the range [0, 1], where 0 is black and 1 is white.
Types ¶
type Color ¶
type Color struct {
Type ColorType
Index int // valid for ColorANSI16 and ColorXterm256
R uint8 // valid for ColorTruecolor
G uint8 // valid for ColorTruecolor
B uint8 // valid for ColorTruecolor
}
Color holds a resolved terminal color value.
type ColorType ¶
type ColorType int
ColorType identifies which color space a Color value lives in.
const ( // ColorDefault means no explicit color was set (terminal default). ColorDefault ColorType = iota // ColorANSI16 is one of the 16 standard ANSI colors (indices 0-15). ColorANSI16 // ColorXterm256 is one of the 256 xterm palette colors (indices 0-255). ColorXterm256 // ColorTruecolor is a 24-bit RGB color. ColorTruecolor )
type DimensionResult ¶
DimensionResult holds the outcome of scoring one design dimension.
type RGB ¶
type RGB struct {
R, G, B uint8
}
RGB holds a 24-bit color as three 8-bit channels.
func Xterm256ToRGB ¶
Xterm256ToRGB returns the canonical RGB value for an xterm-256 color index. Indices outside 0-255 are clamped to the valid range.
type Report ¶
type Report struct {
Dimensions []DimensionResult
Overall Grade
}
Report aggregates all dimension results and an overall grade.
type StyledSegment ¶
StyledSegment is a run of visible text with uniform styling.
func Parse ¶
func Parse(input string) []StyledSegment
Parse walks input, extracts SGR escape sequences, and returns a slice of StyledSegment values. Adjacent segments with identical styling are merged; segments with empty text are dropped.
type TerminalPalette ¶
TerminalPalette describes a terminal color scheme. Colors[0-7] are the standard ANSI colors, Colors[8-15] are the bright variants.
func AllPalettes ¶
func AllPalettes() []TerminalPalette
AllPalettes returns all built-in terminal palettes.