Tai Groot 0a34b761cb test: improve coverage to 98.2%, add staticcheck to CI
- Fix comment typos (Intensty → Intensity)
- Add tests for createStringerPalette modes (background fill, smart mode)
- Add tests for ColorString variants, BytesToColor determinism
- Add tests for GetBackgroundColor mid-tone edge case
- Add tests for GenerateOKLCHPalette negative/large inputs
- Add Go 1.25 to CI matrix for compatibility testing
- Add staticcheck lint step to CI
- Fix goimports formatting in hash_test.go
2026-03-26 06:03:47 +00:00
2022-10-10 01:28:39 -07:00
2022-09-25 21:56:04 -07:00

colorhash

Deterministic color assignment from arbitrary input. Feed it a string or byte stream and get back a consistent color every time.

Features

  • Deterministic — same input always produces the same color
  • Pluggable palettes — bring your own ColorSet or use simplecolorpalettes
  • Multiple output formatscolor.Color, ANSI escape codes, true-color terminal strings
  • String and byte input — hash strings directly or stream bytes via io.Reader

Install

go get github.com/taigrr/colorhash

Usage

Hash a string to a color

import (
    "github.com/taigrr/colorhash"
    "github.com/taigrr/simplecolorpalettes/palettes/html"
)

palette := html.GetPalette() // or any ColorSet
c := colorhash.StringToColor(palette, "username")
// c is a deterministic color.Color

ANSI terminal colors

fmt.Println(colorhash.Red("error message"))
fmt.Println(colorhash.Green("success"))
fmt.Println(colorhash.BIYellow("bold high-intensity yellow"))

Automatic color from a palette

sp := colorhash.CreateStringerPalette(false, false, palette)
colored := sp.GetString("username") // wraps "username" in its assigned color

License

0BSD

Description
No description provided
Readme 0BSD 71 KiB
Languages
Go 100%