-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.go
66 lines (59 loc) · 1.06 KB
/
color.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
package main
import (
"fmt"
)
type color uint8
const (
colorNone color = iota
colorBlack
colorRed
colorGreen
colorYellow
colorBlue
colorMagenta
colorCyan
colorWhite
colorIBlack
colorIRed
colorIGreen
colorIYellow
colorIBlue
colorIMagenta
colorICyan
colorIWhite
)
var itoaColor = map[color]string{
colorNone: "none",
colorBlack: "black",
colorRed: "red",
colorGreen: "green",
colorYellow: "yellow",
colorBlue: "blue",
colorMagenta: "magenta",
colorCyan: "cyan",
colorWhite: "white",
colorIBlack: "iblack",
colorIRed: "ired",
colorIGreen: "igreen",
colorIYellow: "iyellow",
colorIBlue: "iblue",
colorIMagenta: "imagenta",
colorICyan: "icyan",
colorIWhite: "iwhite",
}
var atoiColor = func() map[string]color {
m := map[string]color{}
for k, v := range itoaColor {
m[v] = k
}
return m
}()
func parseColor(s string) (color, error) {
if c, ok := atoiColor[s]; ok {
return c, nil
}
return colorNone, fmt.Errorf("unknown color %q", s)
}
func (c color) String() string {
return itoaColor[c]
}