@@ -15,32 +15,34 @@ func (l Label) String() string {
15
15
return string (l )
16
16
}
17
17
18
+ type LabelColor color.RGBA
19
+
18
20
// RGBA from a Label computed in a deterministic way
19
- func (l Label ) RGBA () color. RGBA {
21
+ func (l Label ) Color () LabelColor {
20
22
id := 0
21
23
hash := sha1 .Sum ([]byte (l ))
22
24
23
25
// colors from: https://material-ui.com/style/color/
24
- colors := []color. RGBA {
25
- color. RGBA {R : 244 , G : 67 , B : 54 , A : 255 }, // red
26
- color. RGBA {R : 233 , G : 30 , B : 99 , A : 255 }, // pink
27
- color. RGBA {R : 156 , G : 39 , B : 176 , A : 255 }, // purple
28
- color. RGBA {R : 103 , G : 58 , B : 183 , A : 255 }, // deepPurple
29
- color. RGBA {R : 63 , G : 81 , B : 181 , A : 255 }, // indigo
30
- color. RGBA {R : 33 , G : 150 , B : 243 , A : 255 }, // blue
31
- color. RGBA {R : 3 , G : 169 , B : 244 , A : 255 }, // lightBlue
32
- color. RGBA {R : 0 , G : 188 , B : 212 , A : 255 }, // cyan
33
- color. RGBA {R : 0 , G : 150 , B : 136 , A : 255 }, // teal
34
- color. RGBA {R : 76 , G : 175 , B : 80 , A : 255 }, // green
35
- color. RGBA {R : 139 , G : 195 , B : 74 , A : 255 }, // lightGreen
36
- color. RGBA {R : 205 , G : 220 , B : 57 , A : 255 }, // lime
37
- color. RGBA {R : 255 , G : 235 , B : 59 , A : 255 }, // yellow
38
- color. RGBA {R : 255 , G : 193 , B : 7 , A : 255 }, // amber
39
- color. RGBA {R : 255 , G : 152 , B : 0 , A : 255 }, // orange
40
- color. RGBA {R : 255 , G : 87 , B : 34 , A : 255 }, // deepOrange
41
- color. RGBA {R : 121 , G : 85 , B : 72 , A : 255 }, // brown
42
- color. RGBA {R : 158 , G : 158 , B : 158 , A : 255 }, // grey
43
- color. RGBA {R : 96 , G : 125 , B : 139 , A : 255 }, // blueGrey
26
+ colors := []LabelColor {
27
+ LabelColor {R : 244 , G : 67 , B : 54 , A : 255 }, // red
28
+ LabelColor {R : 233 , G : 30 , B : 99 , A : 255 }, // pink
29
+ LabelColor {R : 156 , G : 39 , B : 176 , A : 255 }, // purple
30
+ LabelColor {R : 103 , G : 58 , B : 183 , A : 255 }, // deepPurple
31
+ LabelColor {R : 63 , G : 81 , B : 181 , A : 255 }, // indigo
32
+ LabelColor {R : 33 , G : 150 , B : 243 , A : 255 }, // blue
33
+ LabelColor {R : 3 , G : 169 , B : 244 , A : 255 }, // lightBlue
34
+ LabelColor {R : 0 , G : 188 , B : 212 , A : 255 }, // cyan
35
+ LabelColor {R : 0 , G : 150 , B : 136 , A : 255 }, // teal
36
+ LabelColor {R : 76 , G : 175 , B : 80 , A : 255 }, // green
37
+ LabelColor {R : 139 , G : 195 , B : 74 , A : 255 }, // lightGreen
38
+ LabelColor {R : 205 , G : 220 , B : 57 , A : 255 }, // lime
39
+ LabelColor {R : 255 , G : 235 , B : 59 , A : 255 }, // yellow
40
+ LabelColor {R : 255 , G : 193 , B : 7 , A : 255 }, // amber
41
+ LabelColor {R : 255 , G : 152 , B : 0 , A : 255 }, // orange
42
+ LabelColor {R : 255 , G : 87 , B : 34 , A : 255 }, // deepOrange
43
+ LabelColor {R : 121 , G : 85 , B : 72 , A : 255 }, // brown
44
+ LabelColor {R : 158 , G : 158 , B : 158 , A : 255 }, // grey
45
+ LabelColor {R : 96 , G : 125 , B : 139 , A : 255 }, // blueGrey
44
46
}
45
47
46
48
for _ , char := range hash {
@@ -50,15 +52,26 @@ func (l Label) RGBA() color.RGBA {
50
52
return colors [id ]
51
53
}
52
54
53
- func (l Label ) Term256 () int {
54
- rgba := l .RGBA ()
55
- red := int (rgba .R ) * 6 / 256
56
- green := int (rgba .G ) * 6 / 256
57
- blue := int (rgba .B ) * 6 / 256
55
+ func (lc LabelColor ) RGBA () color.RGBA {
56
+ return color .RGBA (lc )
57
+ }
58
+
59
+ type Term256 int
60
+
61
+ func (lc LabelColor ) Term256 () Term256 {
62
+ red := Term256 (lc .R ) * 6 / 256
63
+ green := Term256 (lc .G ) * 6 / 256
64
+ blue := Term256 (lc .B ) * 6 / 256
58
65
59
- color256 := red * 36 + green * 6 + blue + 16
66
+ return red * 36 + green * 6 + blue + 16
67
+ }
68
+
69
+ func (t Term256 ) Escape () string {
70
+ return fmt .Sprintf ("\x1b [38;5;%dm" , t )
71
+ }
60
72
61
- return color256
73
+ func (t Term256 ) Unescape () string {
74
+ return "\x1b [0m"
62
75
}
63
76
64
77
func (l Label ) Validate () error {
0 commit comments