-
Notifications
You must be signed in to change notification settings - Fork 1
/
color.go
155 lines (141 loc) · 3.94 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package ansicode
import "image/color"
var _ color.Color = RGBColor{}
// IndexedColor is a color that can be represented by an index.
type IndexedColor struct {
idx byte
}
// RGBColor is a color that can be represented by RGB values.
type RGBColor struct {
R, G, B uint8
}
// NamedColor is a color that can be referenced by name.
type NamedColor int
// NamedColor values.
const (
NamedColorBlack NamedColor = 0
NamedColorRed NamedColor = 1
NamedColorGreen NamedColor = 2
NamedColorYellow NamedColor = 3
NamedColorBlue NamedColor = 4
NamedColorMagenta NamedColor = 5
NamedColorCyan NamedColor = 6
NamedColorWhite NamedColor = 7
NamedColorBrightBlack NamedColor = 8
NamedColorBrightRed NamedColor = 9
NamedColorBrightGreen NamedColor = 10
NamedColorBrightYellow NamedColor = 11
NamedColorBrightBlue NamedColor = 12
NamedColorBrightMagenta NamedColor = 13
NamedColorBrightCyan NamedColor = 14
NamedColorBrightWhite NamedColor = 15
NamedColorCubeStart NamedColor = 16
NamedColorCubeEnd NamedColor = 232
NamedColorGrayscaleStart NamedColor = 233
NamedColorGrayscaleEnd NamedColor = 255
NamedColorForeground NamedColor = 256
NamedColorBackground NamedColor = 257
NamedColorCursor NamedColor = 258
NamedColorDimBlack NamedColor = 259
NamedColorDimRed NamedColor = 260
NamedColorDimGreen NamedColor = 261
NamedColorDimYellow NamedColor = 262
NamedColorDimBlue NamedColor = 263
NamedColorDimMagenta NamedColor = 264
NamedColorDimCyan NamedColor = 265
NamedColorDimWhite NamedColor = 266
NamedColorBrightForeground NamedColor = 267
NamedColorDimForeground NamedColor = 268
)
// ToBright returns the bright version of the color.
func (c NamedColor) ToBright() NamedColor {
switch c {
case NamedColorForeground:
return NamedColorBrightForeground
case NamedColorBlack:
return NamedColorBrightBlack
case NamedColorRed:
return NamedColorBrightRed
case NamedColorGreen:
return NamedColorBrightGreen
case NamedColorYellow:
return NamedColorBrightYellow
case NamedColorBlue:
return NamedColorBrightBlue
case NamedColorMagenta:
return NamedColorBrightMagenta
case NamedColorCyan:
return NamedColorBrightCyan
case NamedColorWhite:
return NamedColorBrightWhite
case NamedColorDimForeground:
return NamedColorForeground
case NamedColorDimBlack:
return NamedColorBlack
case NamedColorDimRed:
return NamedColorRed
case NamedColorDimGreen:
return NamedColorGreen
case NamedColorDimYellow:
return NamedColorYellow
case NamedColorDimBlue:
return NamedColorBlue
case NamedColorDimMagenta:
return NamedColorMagenta
case NamedColorDimCyan:
return NamedColorCyan
case NamedColorDimWhite:
return NamedColorWhite
default:
return c
}
}
// ToDim returns the dim version of the color.
func (c NamedColor) ToDim() NamedColor {
switch c {
case NamedColorBlack:
return NamedColorDimBlack
case NamedColorRed:
return NamedColorDimRed
case NamedColorGreen:
return NamedColorDimGreen
case NamedColorYellow:
return NamedColorDimYellow
case NamedColorBlue:
return NamedColorDimBlue
case NamedColorMagenta:
return NamedColorDimMagenta
case NamedColorCyan:
return NamedColorDimCyan
case NamedColorWhite:
return NamedColorDimWhite
case NamedColorForeground:
return NamedColorDimForeground
case NamedColorBrightBlack:
return NamedColorBlack
case NamedColorBrightRed:
return NamedColorRed
case NamedColorBrightGreen:
return NamedColorGreen
case NamedColorBrightYellow:
return NamedColorYellow
case NamedColorBrightBlue:
return NamedColorBlue
case NamedColorBrightMagenta:
return NamedColorMagenta
case NamedColorBrightCyan:
return NamedColorCyan
case NamedColorBrightWhite:
return NamedColorWhite
default:
return c
}
}
// RGBA returns the RGBA value of the color.
func (c RGBColor) RGBA() (r, g, b, a uint32) {
r = uint32(c.R) * 0x101
g = uint32(c.G) * 0x101
b = uint32(c.B) * 0x101
a = 0xffff
return
}