-
Notifications
You must be signed in to change notification settings - Fork 0
/
brand.go
89 lines (76 loc) · 1.58 KB
/
brand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Package brand provides Go Brand colors.
package brand
import (
"fmt"
"sort"
"github.com/lucasb-eyer/go-colorful"
)
// Brand colors in hex.
const (
GopherBlue = "#00ADD8"
LightBlue = "#5DC9E2"
Aqua = "#00A29C"
Black = "#000000"
Fuchsia = "#CE3262"
Yellow = "#FDDD00"
Turquoise = "#00758D"
Slate = "#555759"
Purple = "#402B56"
CoolGray = "#DBD9D6"
)
// Status colors.
const (
Pass = "#36B37E"
Fail = "#FF5630"
Warn = "#FFAB00"
)
// Colors is a map of named colors.
var Colors = map[string]string{
"gopher-blue": GopherBlue,
"light-blue": LightBlue,
"aqua": Aqua,
"black": Black,
"fuchsia": Fuchsia,
"yellow": Yellow,
"turquoise": Turquoise,
"slate": Slate,
"purple": Purple,
"cool-gray": CoolGray,
"pass": Pass,
"fail": Fail,
"warn": Warn,
}
// ColorNames is the list of color names.
var ColorNames []string
func init() {
for name := range Colors {
ColorNames = append(ColorNames, name)
}
sort.Strings(ColorNames)
}
// Color looks up a named color.
func Color(name string) (string, error) {
hex, ok := Colors[name]
if !ok {
return "", fmt.Errorf("unknown color %q", name)
}
return hex, nil
}
// Lighten returns the named color lightened by the given proportion (in range 0-1).
func Lighten(name string, p float64) (string, error) {
hx, err := Color(name)
if err != nil {
return "", err
}
c := hex(hx)
h, s, l := c.Hsl()
l = (1-p)*l + p
return colorful.Hsl(h, s, l).Hex(), nil
}
func hex(h string) colorful.Color {
c, err := colorful.Hex(h)
if err != nil {
panic(err)
}
return c
}