https://github.com/tomnomnom/xtermcolor
Golang package and command to convert color.Colour to the nearest xterm/bash/shell color
https://github.com/tomnomnom/xtermcolor
Last synced: about 2 months ago
JSON representation
Golang package and command to convert color.Colour to the nearest xterm/bash/shell color
- Host: GitHub
- URL: https://github.com/tomnomnom/xtermcolor
- Owner: tomnomnom
- License: mit
- Created: 2014-08-13T15:38:01.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-28T12:47:13.000Z (about 9 years ago)
- Last Synced: 2025-03-18T07:51:37.313Z (about 2 months ago)
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 25
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.mkd
- Changelog: CHANGELOG.mkd
- Contributing: CONTRIBUTING.mkd
- License: LICENSE
Awesome Lists containing this project
README
# XtermColor
Find the closest xterm color to anything implementing [color.Color](https://golang.org/pkg/image/color/#Color).
Provides a [color.Palette](https://golang.org/pkg/image/color/#Palette) as `xtermcolor.Colors` so you can use `.Convert` and `.Index`,
but 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.[](https://travis-ci.org/tomnomnom/xtermcolor)
Full documentation can be found on [GoDoc](https://godoc.org/github.com/tomnomnom/xtermcolor).
Basic usage (examples/basic.go):
```go
package mainimport (
"fmt"
"image/color""github.com/tomnomnom/xtermcolor"
)func main() {
fmt.Println(xtermcolor.Colors.Convert(color.RGBA{128, 64, 32, 255}))fmt.Println(xtermcolor.FromColor(color.RGBA{120, 210, 120, 255}))
fmt.Println(xtermcolor.FromInt(0xCC66FFFF))
code, err := xtermcolor.FromHexStr("#FEFEFE")
if err != nil {
fmt.Println(err)
}
fmt.Println(code)
}
``````
▶ go run examples/basic.go
{135 95 0 255}
114
171
15
```## xtermcolor command
There's also an `xtermcolor` command you can install by running:
```
▶ go get github.com/tomnomnom/xtermcolor/cmd/xtermcolor
```Or you can download a binary from the [releases page](https://github.com/tomnomnom/xtermcolor/releases).
The command returns the color code for a 24 bit hex number:
```
▶ xtermcolor cc66ff
171
```...or for seperate 8 bit red, green and blue components:
```
▶ xtermcolor 210 128 0
172
```