• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

xtermcolor-b78803f00a7e/H28-Apr-2016-

.gitignoreH A D25-Aug-202061

.travis.ymlH A D25-Aug-202082

CHANGELOG.mkdH A D25-Aug-2020277

CONTRIBUTING.mkdH A D25-Aug-2020312

LICENSEH A D25-Aug-20201 KiB

README.mkdH A D25-Aug-20201.5 KiB

colors.goH A D25-Aug-202012.2 KiB

README.mkd

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