📚 chroma16 - Awesome Go Library for Command Line

Go Gopher mascot for chroma16

Generate a harmonious 16-color terminal palette from a single seed color or string

🏷️ Command Line
📂 Advanced Console UIs
0 stars
View on GitHub 🔗

Detailed Description of chroma16

chroma16

codecov Go Reference Go ≥1.21 License: MIT Go Report Card

Generate a complete, harmonious 16-color terminal palette from a single seed value — a hex color or any string.


Install

go get github.com/arceus-7/chroma16

Quick Start

import "github.com/arceus-7/chroma16"

palette, err := chroma16.From("#FF6B35")
if err != nil {
    log.Fatal(err)
}
palette.Preview() // prints a color swatch to your terminal

Builder API

palette, err := chroma16.New().
    Seed("#2E86AB").
    Mood(chroma16.Cool).
    Contrast(chroma16.High).
    Build()
if err != nil {
    log.Fatal(err)
}

// Get all 16 hex colors
hexColors := palette.Hex()

// Apply to terminal session with ANSI OSC 4 sequences
for _, seq := range palette.ANSI() {
    fmt.Print(seq)
}

Examples

Three runnable examples live in the examples/ directory:

ProgramRunWhat it shows
examples/basicgo run ./examples/basicFrom() with hex and string seeds
examples/buildergo run ./examples/builderEvery Mood × Contrast combo via the Builder
examples/outputsgo run ./examples/outputsAll output formats: Hex, RGB, ANSI, At(), Preview()
examples/namedgo run ./examples/namedUsing standard CSS named colors
examples/exportgo run ./examples/exportGenerate configs for Alacritty, Kitty, Windows Terminal, and Xresources
examples/jsongo run ./examples/jsonMarshalling and unmarshalling palettes to/from JSON
examples/lipglossgo run -tags lipgloss ./examples/lipglossDeep integration with charmbracelet/lipgloss styles

The 16 Slots

Colors are indexed to match the standard 16-color terminal palette:

IndexNameIndexName
0Black8Bright Black
1Red9Bright Red
2Green10Bright Green
3Yellow11Bright Yellow
4Blue12Bright Blue
5Magenta13Bright Magenta
6Cyan14Bright Cyan
7White15Bright White

Seed Input

Seed typeBehaviour
"#FF6B35"Parsed as a hex color
"FF6B35"Same — leading # is optional
"ocean"Deterministically hashed via FNV-1a
""Hashed (FNV-1a of empty string) — valid, stable
"#GGGGGG"Returns an error (invalid hex characters)

Note: Named colors like "red" are hashed, not looked up by name. Named color lookup is planned for v0.2.


Moods

ConstantEffect
chroma16.NeutralDefault — balanced hues
chroma16.WarmShift toward reds and oranges
chroma16.CoolShift toward blues and cyans
chroma16.DarkLower brightness throughout
chroma16.PastelDesaturated, soft, muted tones
chroma16.NeonHigh saturation, vivid and energetic

Contrast

ConstantEffect
chroma16.MediumDefault — balanced luminance range
chroma16.HighWider luminance spread
chroma16.LowNarrower, softer luminance range

API Reference

Functions

FunctionReturnsDescription
From(seed string)Palette, errorOne-liner palette from a seed
New()*BuilderCreate a Builder for a customized palette
Blend(p1, p2, t)PaletteInterpolate two palettes (t is 0 to 1)
FromJSON(data)Palette, errorRestore a palette from JSON bytes

Palette Methods

MethodReturnsDescription
Hex()[]string16 hex strings in #RRGGBB format
ANSI()[]string16 XTerm OSC 4 escape sequences
RGB()[][3]uint816 raw [R, G, B] triples
At(i int)string, errorHex string for slot i; error if i outside [0,15]
Preview()Prints a color swatch to stdout
Complement()PaletteReturns a new palette with opposite hues
Analogous(d)PaletteReturns a new palette with hues shifted by d degrees
ToAlacritty()stringReturns an Alacritty TOML colors block
ToKitty()stringReturns a Kitty .conf text block
ToWindowsTerminal(n)stringReturns a JSON block for Windows Terminal
ToXresources()stringReturns an Xresources colors block
MarshalJSON()[]byte, errSerializes palette to JSON
ToLipglossTheme()LipglossThemeAvailable when built with -tags lipgloss

Builder Methods

MethodReturnsDescription
Seed(seed string)*BuilderSet the seed value
Mood(m Mood)*BuilderSet the palette mood
Contrast(c Contrast)*BuilderSet the contrast level
Build()Palette, errorGenerate the final palette

Color Generation Algorithm

chroma16 converts the seed to HSL, then places 8 hue relationships (complement, primary, triadic, analogous) across the 16 slots. Normal colors (0–7) use lower lightness; bright colors (8–15) use higher lightness. Mood adjusts the hue shift, saturation multiplier, and lightness offset. Contrast widens or narrows the lightness spread between the two groups.

All math is pure Go standard library — zero transitive dependencies.


License

MIT © 2026 Arceus-7