1# XtermColor 2 3Find the closest xterm color to anything implementing [color.Color](https://golang.org/pkg/image/color/#Color). 4 5Provides a [color.Palette](https://golang.org/pkg/image/color/#Palette) as `xtermcolor.Colors` so you can use `.Convert` and `.Index`, 6but also provides convenience functions to get the index as a `uint8` from a `color.Color`, a 32 bit integer, or a 24 bit hex string. 7 8[![Build Status](https://travis-ci.org/tomnomnom/xtermcolor.svg?branch=master)](https://travis-ci.org/tomnomnom/xtermcolor) 9 10 11Full documentation can be found on [GoDoc](https://godoc.org/github.com/tomnomnom/xtermcolor). 12 13Basic usage (examples/basic.go): 14 15```go 16package main 17 18import ( 19 "fmt" 20 "image/color" 21 22 "github.com/tomnomnom/xtermcolor" 23) 24 25func main() { 26 fmt.Println(xtermcolor.Colors.Convert(color.RGBA{128, 64, 32, 255})) 27 28 fmt.Println(xtermcolor.FromColor(color.RGBA{120, 210, 120, 255})) 29 30 fmt.Println(xtermcolor.FromInt(0xCC66FFFF)) 31 32 code, err := xtermcolor.FromHexStr("#FEFEFE") 33 if err != nil { 34 fmt.Println(err) 35 } 36 fmt.Println(code) 37} 38``` 39 40``` 41▶ go run examples/basic.go 42{135 95 0 255} 43114 44171 4515 46``` 47 48## xtermcolor command 49 50There's also an `xtermcolor` command you can install by running: 51 52``` 53▶ go get github.com/tomnomnom/xtermcolor/cmd/xtermcolor 54``` 55 56Or you can download a binary from the [releases page](https://github.com/tomnomnom/xtermcolor/releases). 57 58The command returns the color code for a 24 bit hex number: 59 60``` 61▶ xtermcolor cc66ff 62171 63``` 64 65...or for seperate 8 bit red, green and blue components: 66 67``` 68▶ xtermcolor 210 128 0 69172 70``` 71