Debian Codegraph @

color/color.go

raw symbols SCIP
1 // Copyright 2025 The TCell Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package color
16
17 import (
18 "fmt"
19 ic "image/color"
20 "strconv"
21 )
22
23 // Color represents a color. The low numeric values are the same as used
24 // by ECMA-48, and beyond that XTerm.
25 //
26 // For Color names we use the W3C approved color names.
27 //
28 // Note that on various terminals colors may be approximated however, or
29 // not supported at all. If no suitable representation for a color is known,
30 // the library will simply not set any color, deferring to whatever default
31 // attributes the terminal uses.
32 type Color uint32
33
34 const (
35 // Default is used to leave the Color unchanged from whatever
36 // system or terminal default may exist. It's also the zero value.
37 Default Color = 0
38
39 // IsValid is used to indicate the color value is actually
40 // valid (initialized). This is useful to permit the zero value
41 // to be treated as the default. This should not be used
42 // directly by applications. Use the IsValid method on Color instead.
43 IsValid Color = 1 << 31
44
45 // IsRGB is used to indicate that the numeric value is not
46 // a known color constant, but rather an RGB value. The lower
47 // order 3 bytes are RGB. This should not be used directly,
48 // instead use the Color.IsRGB method.
49 IsRGB Color = 1 << 30
50
51 // IsSpecial is a flag used to indicate that the values have
52 // special meaning, and live outside of the color space(s).
53 // This should not be used directly by applications.
54 IsSpecial Color = 1 << 29
55 )
56
57 // Note that the order of these options is important -- it follows the
58 // definitions used by ECMA and XTerm. Hence any further named colors
59 // must begin at a value not less than 256.
60 const (
61 Black = XTerm0
62 Maroon = XTerm1
63 Green = XTerm2
64 Olive = XTerm3
65 Navy = XTerm4
66 Purple = XTerm5
67 Teal = XTerm6
68 Silver = XTerm7
69 Gray = XTerm8
70 Red = XTerm9
71 Lime = XTerm10
72 Yellow = XTerm11
73 Blue = XTerm12
74 Fuchsia = XTerm13
75 Aqua = XTerm14
76 White = XTerm15
77 )
78
79 const (
80 XTerm0 = IsValid + iota
81 XTerm1
82 XTerm2
83 XTerm3
84 XTerm4
85 XTerm5
86 XTerm6
87 XTerm7
88 XTerm8
89 XTerm9
90 XTerm10
91 XTerm11
92 XTerm12
93 XTerm13
94 XTerm14
95 XTerm15
96 XTerm16
97 XTerm17
98 XTerm18
99 XTerm19
100 XTerm20
101 XTerm21
102 XTerm22
103 XTerm23
104 XTerm24
105 XTerm25
106 XTerm26
107 XTerm27
108 XTerm28
109 XTerm29
110 XTerm30
111 XTerm31
112 XTerm32
113 XTerm33
114 XTerm34
115 XTerm35
116 XTerm36
117 XTerm37
118 XTerm38
119 XTerm39
120 XTerm40
121 XTerm41
122 XTerm42
123 XTerm43
124 XTerm44
125 XTerm45
126 XTerm46
127 XTerm47
128 XTerm48
129 XTerm49
130 XTerm50
131 XTerm51
132 XTerm52
133 XTerm53
134 XTerm54
135 XTerm55
136 XTerm56
137 XTerm57
138 XTerm58
139 XTerm59
140 XTerm60
141 XTerm61
142 XTerm62
143 XTerm63
144 XTerm64
145 XTerm65
146 XTerm66
147 XTerm67
148 XTerm68
149 XTerm69
150 XTerm70
151 XTerm71
152 XTerm72
153 XTerm73
154 XTerm74
155 XTerm75
156 XTerm76
157 XTerm77
158 XTerm78
159 XTerm79
160 XTerm80
161 XTerm81
162 XTerm82
163 XTerm83
164 XTerm84
165 XTerm85
166 XTerm86
167 XTerm87
168 XTerm88
169 XTerm89
170 XTerm90
171 XTerm91
172 XTerm92
173 XTerm93
174 XTerm94
175 XTerm95
176 XTerm96
177 XTerm97
178 XTerm98
179 XTerm99
180 XTerm100
181 XTerm101
182 XTerm102
183 XTerm103
184 XTerm104
185 XTerm105
186 XTerm106
187 XTerm107
188 XTerm108
189 XTerm109
190 XTerm110
191 XTerm111
192 XTerm112
193 XTerm113
194 XTerm114
195 XTerm115
196 XTerm116
197 XTerm117
198 XTerm118
199 XTerm119
200 XTerm120
201 XTerm121
202 XTerm122
203 XTerm123
204 XTerm124
205 XTerm125
206 XTerm126
207 XTerm127
208 XTerm128
209 XTerm129
210 XTerm130
211 XTerm131
212 XTerm132
213 XTerm133
214 XTerm134
215 XTerm135
216 XTerm136
217 XTerm137
218 XTerm138
219 XTerm139
220 XTerm140
221 XTerm141
222 XTerm142
223 XTerm143
224 XTerm144
225 XTerm145
226 XTerm146
227 XTerm147
228 XTerm148
229 XTerm149
230 XTerm150
231 XTerm151
232 XTerm152
233 XTerm153
234 XTerm154
235 XTerm155
236 XTerm156
237 XTerm157
238 XTerm158
239 XTerm159
240 XTerm160
241 XTerm161
242 XTerm162
243 XTerm163
244 XTerm164
245 XTerm165
246 XTerm166
247 XTerm167
248 XTerm168
249 XTerm169
250 XTerm170
251 XTerm171
252 XTerm172
253 XTerm173
254 XTerm174
255 XTerm175
256 XTerm176
257 XTerm177
258 XTerm178
259 XTerm179
260 XTerm180
261 XTerm181
262 XTerm182
263 XTerm183
264 XTerm184
265 XTerm185
266 XTerm186
267 XTerm187
268 XTerm188
269 XTerm189
270 XTerm190
271 XTerm191
272 XTerm192
273 XTerm193
274 XTerm194
275 XTerm195
276 XTerm196
277 XTerm197
278 XTerm198
279 XTerm199
280 XTerm200
281 XTerm201
282 XTerm202
283 XTerm203
284 XTerm204
285 XTerm205
286 XTerm206
287 XTerm207
288 XTerm208
289 XTerm209
290 XTerm210
291 XTerm211
292 XTerm212
293 XTerm213
294 XTerm214
295 XTerm215
296 XTerm216
297 XTerm217
298 XTerm218
299 XTerm219
300 XTerm220
301 XTerm221
302 XTerm222
303 XTerm223
304 XTerm224
305 XTerm225
306 XTerm226
307 XTerm227
308 XTerm228
309 XTerm229
310 XTerm230
311 XTerm231
312 XTerm232
313 XTerm233
314 XTerm234
315 XTerm235
316 XTerm236
317 XTerm237
318 XTerm238
319 XTerm239
320 XTerm240
321 XTerm241
322 XTerm242
323 XTerm243
324 XTerm244
325 XTerm245
326 XTerm246
327 XTerm247
328 XTerm248
329 XTerm249
330 XTerm250
331 XTerm251
332 XTerm252
333 XTerm253
334 XTerm254
335 XTerm255
336 AliceBlue = IsRGB | IsValid | 0xF0F8FF
337 AntiqueWhite = IsRGB | IsValid | 0xFAEBD7
338 AquaMarine = IsRGB | IsValid | 0x7FFFD4
339 Azure = IsRGB | IsValid | 0xF0FFFF
340 Beige = IsRGB | IsValid | 0xF5F5DC
341 Bisque = IsRGB | IsValid | 0xFFE4C4
342 BlanchedAlmond = IsRGB | IsValid | 0xFFEBCD
343 BlueViolet = IsRGB | IsValid | 0x8A2BE2
344 Brown = IsRGB | IsValid | 0xA52A2A
345 BurlyWood = IsRGB | IsValid | 0xDEB887
346 CadetBlue = IsRGB | IsValid | 0x5F9EA0
347 Chartreuse = IsRGB | IsValid | 0x7FFF00
348 Chocolate = IsRGB | IsValid | 0xD2691E
349 Coral = IsRGB | IsValid | 0xFF7F50
350 CornflowerBlue = IsRGB | IsValid | 0x6495ED
351 Cornsilk = IsRGB | IsValid | 0xFFF8DC
352 Crimson = IsRGB | IsValid | 0xDC143C
353 DarkBlue = IsRGB | IsValid | 0x00008B
354 DarkCyan = IsRGB | IsValid | 0x008B8B
355 DarkGoldenrod = IsRGB | IsValid | 0xB8860B
356 DarkGray = IsRGB | IsValid | 0xA9A9A9
357 DarkGreen = IsRGB | IsValid | 0x006400
358 DarkKhaki = IsRGB | IsValid | 0xBDB76B
359 DarkMagenta = IsRGB | IsValid | 0x8B008B
360 DarkOliveGreen = IsRGB | IsValid | 0x556B2F
361 DarkOrange = IsRGB | IsValid | 0xFF8C00
362 DarkOrchid = IsRGB | IsValid | 0x9932CC
363 DarkRed = IsRGB | IsValid | 0x8B0000
364 DarkSalmon = IsRGB | IsValid | 0xE9967A
365 DarkSeaGreen = IsRGB | IsValid | 0x8FBC8F
366 DarkSlateBlue = IsRGB | IsValid | 0x483D8B
367 DarkSlateGray = IsRGB | IsValid | 0x2F4F4F
368 DarkTurquoise = IsRGB | IsValid | 0x00CED1
369 DarkViolet = IsRGB | IsValid | 0x9400D3
370 DeepPink = IsRGB | IsValid | 0xFF1493
371 DeepSkyBlue = IsRGB | IsValid | 0x00BFFF
372 DimGray = IsRGB | IsValid | 0x696969
373 DodgerBlue = IsRGB | IsValid | 0x1E90FF
374 FireBrick = IsRGB | IsValid | 0xB22222
375 FloralWhite = IsRGB | IsValid | 0xFFFAF0
376 ForestGreen = IsRGB | IsValid | 0x228B22
377 Gainsboro = IsRGB | IsValid | 0xDCDCDC
378 GhostWhite = IsRGB | IsValid | 0xF8F8FF
379 Gold = IsRGB | IsValid | 0xFFD700
380 Goldenrod = IsRGB | IsValid | 0xDAA520
381 GreenYellow = IsRGB | IsValid | 0xADFF2F
382 Honeydew = IsRGB | IsValid | 0xF0FFF0
383 HotPink = IsRGB | IsValid | 0xFF69B4
384 IndianRed = IsRGB | IsValid | 0xCD5C5C
385 Indigo = IsRGB | IsValid | 0x4B0082
386 Ivory = IsRGB | IsValid | 0xFFFFF0
387 Khaki = IsRGB | IsValid | 0xF0E68C
388 Lavender = IsRGB | IsValid | 0xE6E6FA
389 LavenderBlush = IsRGB | IsValid | 0xFFF0F5
390 LawnGreen = IsRGB | IsValid | 0x7CFC00
391 LemonChiffon = IsRGB | IsValid | 0xFFFACD
392 LightBlue = IsRGB | IsValid | 0xADD8E6
393 LightCoral = IsRGB | IsValid | 0xF08080
394 LightCyan = IsRGB | IsValid | 0xE0FFFF
395 LightGoldenrodYellow = IsRGB | IsValid | 0xFAFAD2
396 LightGray = IsRGB | IsValid | 0xD3D3D3
397 LightGreen = IsRGB | IsValid | 0x90EE90
398 LightPink = IsRGB | IsValid | 0xFFB6C1
399 LightSalmon = IsRGB | IsValid | 0xFFA07A
400 LightSeaGreen = IsRGB | IsValid | 0x20B2AA
401 LightSkyBlue = IsRGB | IsValid | 0x87CEFA
402 LightSlateGray = IsRGB | IsValid | 0x778899
403 LightSteelBlue = IsRGB | IsValid | 0xB0C4DE
404 LightYellow = IsRGB | IsValid | 0xFFFFE0
405 LimeGreen = IsRGB | IsValid | 0x32CD32
406 Linen = IsRGB | IsValid | 0xFAF0E6
407 MediumAquamarine = IsRGB | IsValid | 0x66CDAA
408 MediumBlue = IsRGB | IsValid | 0x0000CD
409 MediumOrchid = IsRGB | IsValid | 0xBA55D3
410 MediumPurple = IsRGB | IsValid | 0x9370DB
411 MediumSeaGreen = IsRGB | IsValid | 0x3CB371
412 MediumSlateBlue = IsRGB | IsValid | 0x7B68EE
413 MediumSpringGreen = IsRGB | IsValid | 0x00FA9A
414 MediumTurquoise = IsRGB | IsValid | 0x48D1CC
415 MediumVioletRed = IsRGB | IsValid | 0xC71585
416 MidnightBlue = IsRGB | IsValid | 0x191970
417 MintCream = IsRGB | IsValid | 0xF5FFFA
418 MistyRose = IsRGB | IsValid | 0xFFE4E1
419 Moccasin = IsRGB | IsValid | 0xFFE4B5
420 NavajoWhite = IsRGB | IsValid | 0xFFDEAD
421 OldLace = IsRGB | IsValid | 0xFDF5E6
422 OliveDrab = IsRGB | IsValid | 0x6B8E23
423 Orange = IsRGB | IsValid | 0xFFA500
424 OrangeRed = IsRGB | IsValid | 0xFF4500
425 Orchid = IsRGB | IsValid | 0xDA70D6
426 PaleGoldenrod = IsRGB | IsValid | 0xEEE8AA
427 PaleGreen = IsRGB | IsValid | 0x98FB98
428 PaleTurquoise = IsRGB | IsValid | 0xAFEEEE
429 PaleVioletRed = IsRGB | IsValid | 0xDB7093
430 PapayaWhip = IsRGB | IsValid | 0xFFEFD5
431 PeachPuff = IsRGB | IsValid | 0xFFDAB9
432 Peru = IsRGB | IsValid | 0xCD853F
433 Pink = IsRGB | IsValid | 0xFFC0CB
434 Plum = IsRGB | IsValid | 0xDDA0DD
435 PowderBlue = IsRGB | IsValid | 0xB0E0E6
436 RebeccaPurple = IsRGB | IsValid | 0x663399
437 RosyBrown = IsRGB | IsValid | 0xBC8F8F
438 RoyalBlue = IsRGB | IsValid | 0x4169E1
439 SaddleBrown = IsRGB | IsValid | 0x8B4513
440 Salmon = IsRGB | IsValid | 0xFA8072
441 SandyBrown = IsRGB | IsValid | 0xF4A460
442 SeaGreen = IsRGB | IsValid | 0x2E8B57
443 Seashell = IsRGB | IsValid | 0xFFF5EE
444 Sienna = IsRGB | IsValid | 0xA0522D
445 Skyblue = IsRGB | IsValid | 0x87CEEB
446 SlateBlue = IsRGB | IsValid | 0x6A5ACD
447 SlateGray = IsRGB | IsValid | 0x708090
448 Snow = IsRGB | IsValid | 0xFFFAFA
449 SpringGreen = IsRGB | IsValid | 0x00FF7F
450 SteelBlue = IsRGB | IsValid | 0x4682B4
451 Tan = IsRGB | IsValid | 0xD2B48C
452 Thistle = IsRGB | IsValid | 0xD8BFD8
453 Tomato = IsRGB | IsValid | 0xFF6347
454 Turquoise = IsRGB | IsValid | 0x40E0D0
455 Violet = IsRGB | IsValid | 0xEE82EE
456 Wheat = IsRGB | IsValid | 0xF5DEB3
457 WhiteSmoke = IsRGB | IsValid | 0xF5F5F5
458 YellowGreen = IsRGB | IsValid | 0x9ACD32
459 )
460
461 // These are aliases for the color gray, because some of us spell
462 // it as grey.
463 const (
464 Grey = Gray
465 DimGrey = DimGray
466 DarkGrey = DarkGray
467 DarkSlateGrey = DarkSlateGray
468 LightGrey = LightGray
469 LightSlateGrey = LightSlateGray
470 SlateGrey = SlateGray
471 )
472
473 // ColorValues maps color constants to their RGB values.
474 var ColorValues = map[Color]int32{
475 Black: 0x000000,
476 Maroon: 0x800000,
477 Green: 0x008000,
478 Olive: 0x808000,
479 Navy: 0x000080,
480 Purple: 0x800080,
481 Teal: 0x008080,
482 Silver: 0xC0C0C0,
483 Gray: 0x808080,
484 Red: 0xFF0000,
485 Lime: 0x00FF00,
486 Yellow: 0xFFFF00,
487 Blue: 0x0000FF,
488 Fuchsia: 0xFF00FF,
489 Aqua: 0x00FFFF,
490 White: 0xFFFFFF,
491 XTerm16: 0x000000, // black
492 XTerm17: 0x00005F,
493 XTerm18: 0x000087,
494 XTerm19: 0x0000AF,
495 XTerm20: 0x0000D7,
496 XTerm21: 0x0000FF, // blue
497 XTerm22: 0x005F00,
498 XTerm23: 0x005F5F,
499 XTerm24: 0x005F87,
500 XTerm25: 0x005FAF,
501 XTerm26: 0x005FD7,
502 XTerm27: 0x005FFF,
503 XTerm28: 0x008700,
504 XTerm29: 0x00875F,
505 XTerm30: 0x008787,
506 XTerm31: 0x0087Af,
507 XTerm32: 0x0087D7,
508 XTerm33: 0x0087FF,
509 XTerm34: 0x00AF00,
510 XTerm35: 0x00AF5F,
511 XTerm36: 0x00AF87,
512 XTerm37: 0x00AFAF,
513 XTerm38: 0x00AFD7,
514 XTerm39: 0x00AFFF,
515 XTerm40: 0x00D700,
516 XTerm41: 0x00D75F,
517 XTerm42: 0x00D787,
518 XTerm43: 0x00D7AF,
519 XTerm44: 0x00D7D7,
520 XTerm45: 0x00D7FF,
521 XTerm46: 0x00FF00, // lime
522 XTerm47: 0x00FF5F,
523 XTerm48: 0x00FF87,
524 XTerm49: 0x00FFAF,
525 XTerm50: 0x00FFd7,
526 XTerm51: 0x00FFFF, // aqua
527 XTerm52: 0x5F0000,
528 XTerm53: 0x5F005F,
529 XTerm54: 0x5F0087,
530 XTerm55: 0x5F00AF,
531 XTerm56: 0x5F00D7,
532 XTerm57: 0x5F00FF,
533 XTerm58: 0x5F5F00,
534 XTerm59: 0x5F5F5F,
535 XTerm60: 0x5F5F87,
536 XTerm61: 0x5F5FAF,
537 XTerm62: 0x5F5FD7,
538 XTerm63: 0x5F5FFF,
539 XTerm64: 0x5F8700,
540 XTerm65: 0x5F875F,
541 XTerm66: 0x5F8787,
542 XTerm67: 0x5F87AF,
543 XTerm68: 0x5F87D7,
544 XTerm69: 0x5F87FF,
545 XTerm70: 0x5FAF00,
546 XTerm71: 0x5FAF5F,
547 XTerm72: 0x5FAF87,
548 XTerm73: 0x5FAFAF,
549 XTerm74: 0x5FAFD7,
550 XTerm75: 0x5FAFFF,
551 XTerm76: 0x5FD700,
552 XTerm77: 0x5FD75F,
553 XTerm78: 0x5FD787,
554 XTerm79: 0x5FD7AF,
555 XTerm80: 0x5FD7D7,
556 XTerm81: 0x5FD7FF,
557 XTerm82: 0x5FFF00,
558 XTerm83: 0x5FFF5F,
559 XTerm84: 0x5FFF87,
560 XTerm85: 0x5FFFAF,
561 XTerm86: 0x5FFFD7,
562 XTerm87: 0x5FFFFF,
563 XTerm88: 0x870000,
564 XTerm89: 0x87005F,
565 XTerm90: 0x870087,
566 XTerm91: 0x8700AF,
567 XTerm92: 0x8700D7,
568 XTerm93: 0x8700FF,
569 XTerm94: 0x875F00,
570 XTerm95: 0x875F5F,
571 XTerm96: 0x875F87,
572 XTerm97: 0x875FAF,
573 XTerm98: 0x875FD7,
574 XTerm99: 0x875FFF,
575 XTerm100: 0x878700,
576 XTerm101: 0x87875F,
577 XTerm102: 0x878787,
578 XTerm103: 0x8787AF,
579 XTerm104: 0x8787D7,
580 XTerm105: 0x8787FF,
581 XTerm106: 0x87AF00,
582 XTerm107: 0x87AF5F,
583 XTerm108: 0x87AF87,
584 XTerm109: 0x87AFAF,
585 XTerm110: 0x87AFD7,
586 XTerm111: 0x87AFFF,
587 XTerm112: 0x87D700,
588 XTerm113: 0x87D75F,
589 XTerm114: 0x87D787,
590 XTerm115: 0x87D7AF,
591 XTerm116: 0x87D7D7,
592 XTerm117: 0x87D7FF,
593 XTerm118: 0x87FF00,
594 XTerm119: 0x87FF5F,
595 XTerm120: 0x87FF87,
596 XTerm121: 0x87FFAF,
597 XTerm122: 0x87FFD7,
598 XTerm123: 0x87FFFF,
599 XTerm124: 0xAF0000,
600 XTerm125: 0xAF005F,
601 XTerm126: 0xAF0087,
602 XTerm127: 0xAF00AF,
603 XTerm128: 0xAF00D7,
604 XTerm129: 0xAF00FF,
605 XTerm130: 0xAF5F00,
606 XTerm131: 0xAF5F5F,
607 XTerm132: 0xAF5F87,
608 XTerm133: 0xAF5FAF,
609 XTerm134: 0xAF5FD7,
610 XTerm135: 0xAF5FFF,
611 XTerm136: 0xAF8700,
612 XTerm137: 0xAF875F,
613 XTerm138: 0xAF8787,
614 XTerm139: 0xAF87AF,
615 XTerm140: 0xAF87D7,
616 XTerm141: 0xAF87FF,
617 XTerm142: 0xAFAF00,
618 XTerm143: 0xAFAF5F,
619 XTerm144: 0xAFAF87,
620 XTerm145: 0xAFAFAF,
621 XTerm146: 0xAFAFD7,
622 XTerm147: 0xAFAFFF,
623 XTerm148: 0xAFD700,
624 XTerm149: 0xAFD75F,
625 XTerm150: 0xAFD787,
626 XTerm151: 0xAFD7AF,
627 XTerm152: 0xAFD7D7,
628 XTerm153: 0xAFD7FF,
629 XTerm154: 0xAFFF00,
630 XTerm155: 0xAFFF5F,
631 XTerm156: 0xAFFF87,
632 XTerm157: 0xAFFFAF,
633 XTerm158: 0xAFFFD7,
634 XTerm159: 0xAFFFFF,
635 XTerm160: 0xD70000,
636 XTerm161: 0xD7005F,
637 XTerm162: 0xD70087,
638 XTerm163: 0xD700AF,
639 XTerm164: 0xD700D7,
640 XTerm165: 0xD700FF,
641 XTerm166: 0xD75F00,
642 XTerm167: 0xD75F5F,
643 XTerm168: 0xD75F87,
644 XTerm169: 0xD75FAF,
645 XTerm170: 0xD75FD7,
646 XTerm171: 0xD75FFF,
647 XTerm172: 0xD78700,
648 XTerm173: 0xD7875F,
649 XTerm174: 0xD78787,
650 XTerm175: 0xD787AF,
651 XTerm176: 0xD787D7,
652 XTerm177: 0xD787FF,
653 XTerm178: 0xD7AF00,
654 XTerm179: 0xD7AF5F,
655 XTerm180: 0xD7AF87,
656 XTerm181: 0xD7AFAF,
657 XTerm182: 0xD7AFD7,
658 XTerm183: 0xD7AFFF,
659 XTerm184: 0xD7D700,
660 XTerm185: 0xD7D75F,
661 XTerm186: 0xD7D787,
662 XTerm187: 0xD7D7AF,
663 XTerm188: 0xD7D7D7,
664 XTerm189: 0xD7D7FF,
665 XTerm190: 0xD7FF00,
666 XTerm191: 0xD7FF5F,
667 XTerm192: 0xD7FF87,
668 XTerm193: 0xD7FFAF,
669 XTerm194: 0xD7FFD7,
670 XTerm195: 0xD7FFFF,
671 XTerm196: 0xFF0000, // red
672 XTerm197: 0xFF005F,
673 XTerm198: 0xFF0087,
674 XTerm199: 0xFF00AF,
675 XTerm200: 0xFF00D7,
676 XTerm201: 0xFF00FF, // fuchsia
677 XTerm202: 0xFF5F00,
678 XTerm203: 0xFF5F5F,
679 XTerm204: 0xFF5F87,
680 XTerm205: 0xFF5FAF,
681 XTerm206: 0xFF5FD7,
682 XTerm207: 0xFF5FFF,
683 XTerm208: 0xFF8700,
684 XTerm209: 0xFF875F,
685 XTerm210: 0xFF8787,
686 XTerm211: 0xFF87AF,
687 XTerm212: 0xFF87D7,
688 XTerm213: 0xFF87FF,
689 XTerm214: 0xFFAF00,
690 XTerm215: 0xFFAF5F,
691 XTerm216: 0xFFAF87,
692 XTerm217: 0xFFAFAF,
693 XTerm218: 0xFFAFD7,
694 XTerm219: 0xFFAFFF,
695 XTerm220: 0xFFD700,
696 XTerm221: 0xFFD75F,
697 XTerm222: 0xFFD787,
698 XTerm223: 0xFFD7AF,
699 XTerm224: 0xFFD7D7,
700 XTerm225: 0xFFD7FF,
701 XTerm226: 0xFFFF00, // yellow
702 XTerm227: 0xFFFF5F,
703 XTerm228: 0xFFFF87,
704 XTerm229: 0xFFFFAF,
705 XTerm230: 0xFFFFD7,
706 XTerm231: 0xFFFFFF, // white
707 XTerm232: 0x080808,
708 XTerm233: 0x121212,
709 XTerm234: 0x1C1C1C,
710 XTerm235: 0x262626,
711 XTerm236: 0x303030,
712 XTerm237: 0x3A3A3A,
713 XTerm238: 0x444444,
714 XTerm239: 0x4E4E4E,
715 XTerm240: 0x585858,
716 XTerm241: 0x626262,
717 XTerm242: 0x6C6C6C,
718 XTerm243: 0x767676,
719 XTerm244: 0x808080, // grey
720 XTerm245: 0x8A8A8A,
721 XTerm246: 0x949494,
722 XTerm247: 0x9E9E9E,
723 XTerm248: 0xA8A8A8,
724 XTerm249: 0xB2B2B2,
725 XTerm250: 0xBCBCBC,
726 XTerm251: 0xC6C6C6,
727 XTerm252: 0xD0D0D0,
728 XTerm253: 0xDADADA,
729 XTerm254: 0xE4E4E4,
730 XTerm255: 0xEEEEEE,
731 AliceBlue: 0xF0F8FF,
732 AntiqueWhite: 0xFAEBD7,
733 AquaMarine: 0x7FFFD4,
734 Azure: 0xF0FFFF,
735 Beige: 0xF5F5DC,
736 Bisque: 0xFFE4C4,
737 BlanchedAlmond: 0xFFEBCD,
738 BlueViolet: 0x8A2BE2,
739 Brown: 0xA52A2A,
740 BurlyWood: 0xDEB887,
741 CadetBlue: 0x5F9EA0,
742 Chartreuse: 0x7FFF00,
743 Chocolate: 0xD2691E,
744 Coral: 0xFF7F50,
745 CornflowerBlue: 0x6495ED,
746 Cornsilk: 0xFFF8DC,
747 Crimson: 0xDC143C,
748 DarkBlue: 0x00008B,
749 DarkCyan: 0x008B8B,
750 DarkGoldenrod: 0xB8860B,
751 DarkGray: 0xA9A9A9,
752 DarkGreen: 0x006400,
753 DarkKhaki: 0xBDB76B,
754 DarkMagenta: 0x8B008B,
755 DarkOliveGreen: 0x556B2F,
756 DarkOrange: 0xFF8C00,
757 DarkOrchid: 0x9932CC,
758 DarkRed: 0x8B0000,
759 DarkSalmon: 0xE9967A,
760 DarkSeaGreen: 0x8FBC8F,
761 DarkSlateBlue: 0x483D8B,
762 DarkSlateGray: 0x2F4F4F,
763 DarkTurquoise: 0x00CED1,
764 DarkViolet: 0x9400D3,
765 DeepPink: 0xFF1493,
766 DeepSkyBlue: 0x00BFFF,
767 DimGray: 0x696969,
768 DodgerBlue: 0x1E90FF,
769 FireBrick: 0xB22222,
770 FloralWhite: 0xFFFAF0,
771 ForestGreen: 0x228B22,
772 Gainsboro: 0xDCDCDC,
773 GhostWhite: 0xF8F8FF,
774 Gold: 0xFFD700,
775 Goldenrod: 0xDAA520,
776 GreenYellow: 0xADFF2F,
777 Honeydew: 0xF0FFF0,
778 HotPink: 0xFF69B4,
779 IndianRed: 0xCD5C5C,
780 Indigo: 0x4B0082,
781 Ivory: 0xFFFFF0,
782 Khaki: 0xF0E68C,
783 Lavender: 0xE6E6FA,
784 LavenderBlush: 0xFFF0F5,
785 LawnGreen: 0x7CFC00,
786 LemonChiffon: 0xFFFACD,
787 LightBlue: 0xADD8E6,
788 LightCoral: 0xF08080,
789 LightCyan: 0xE0FFFF,
790 LightGoldenrodYellow: 0xFAFAD2,
791 LightGray: 0xD3D3D3,
792 LightGreen: 0x90EE90,
793 LightPink: 0xFFB6C1,
794 LightSalmon: 0xFFA07A,
795 LightSeaGreen: 0x20B2AA,
796 LightSkyBlue: 0x87CEFA,
797 LightSlateGray: 0x778899,
798 LightSteelBlue: 0xB0C4DE,
799 LightYellow: 0xFFFFE0,
800 LimeGreen: 0x32CD32,
801 Linen: 0xFAF0E6,
802 MediumAquamarine: 0x66CDAA,
803 MediumBlue: 0x0000CD,
804 MediumOrchid: 0xBA55D3,
805 MediumPurple: 0x9370DB,
806 MediumSeaGreen: 0x3CB371,
807 MediumSlateBlue: 0x7B68EE,
808 MediumSpringGreen: 0x00FA9A,
809 MediumTurquoise: 0x48D1CC,
810 MediumVioletRed: 0xC71585,
811 MidnightBlue: 0x191970,
812 MintCream: 0xF5FFFA,
813 MistyRose: 0xFFE4E1,
814 Moccasin: 0xFFE4B5,
815 NavajoWhite: 0xFFDEAD,
816 OldLace: 0xFDF5E6,
817 OliveDrab: 0x6B8E23,
818 Orange: 0xFFA500,
819 OrangeRed: 0xFF4500,
820 Orchid: 0xDA70D6,
821 PaleGoldenrod: 0xEEE8AA,
822 PaleGreen: 0x98FB98,
823 PaleTurquoise: 0xAFEEEE,
824 PaleVioletRed: 0xDB7093,
825 PapayaWhip: 0xFFEFD5,
826 PeachPuff: 0xFFDAB9,
827 Peru: 0xCD853F,
828 Pink: 0xFFC0CB,
829 Plum: 0xDDA0DD,
830 PowderBlue: 0xB0E0E6,
831 RebeccaPurple: 0x663399,
832 RosyBrown: 0xBC8F8F,
833 RoyalBlue: 0x4169E1,
834 SaddleBrown: 0x8B4513,
835 Salmon: 0xFA8072,
836 SandyBrown: 0xF4A460,
837 SeaGreen: 0x2E8B57,
838 Seashell: 0xFFF5EE,
839 Sienna: 0xA0522D,
840 Skyblue: 0x87CEEB,
841 SlateBlue: 0x6A5ACD,
842 SlateGray: 0x708090,
843 Snow: 0xFFFAFA,
844 SpringGreen: 0x00FF7F,
845 SteelBlue: 0x4682B4,
846 Tan: 0xD2B48C,
847 Thistle: 0xD8BFD8,
848 Tomato: 0xFF6347,
849 Turquoise: 0x40E0D0,
850 Violet: 0xEE82EE,
851 Wheat: 0xF5DEB3,
852 WhiteSmoke: 0xF5F5F5,
853 YellowGreen: 0x9ACD32,
854 }
855
856 // Special colors.
857 const (
858 // Reset is used to indicate that the color should use the
859 // vanilla terminal colors. (Basically go back to the defaults.)
860 Reset = IsSpecial | iota
861
862 // None indicates that we should not change the color from
863 // whatever is already displayed. This can only be used in limited
864 // circumstances.
865 None
866 )
867
868 // Names holds the written names of colors. Useful to present a list of
869 // recognized named colors.
870 var Names = map[string]Color{
871 "black": Black,
872 "maroon": Maroon,
873 "green": Green,
874 "olive": Olive,
875 "navy": Navy,
876 "purple": Purple,
877 "teal": Teal,
878 "silver": Silver,
879 "gray": Gray,
880 "red": Red,
881 "lime": Lime,
882 "yellow": Yellow,
883 "blue": Blue,
884 "fuchsia": Fuchsia,
885 "aqua": Aqua,
886 "white": White,
887 "aliceblue": AliceBlue,
888 "antiquewhite": AntiqueWhite,
889 "aquamarine": AquaMarine,
890 "azure": Azure,
891 "beige": Beige,
892 "bisque": Bisque,
893 "blanchedalmond": BlanchedAlmond,
894 "blueviolet": BlueViolet,
895 "brown": Brown,
896 "burlywood": BurlyWood,
897 "cadetblue": CadetBlue,
898 "chartreuse": Chartreuse,
899 "chocolate": Chocolate,
900 "coral": Coral,
901 "cornflowerblue": CornflowerBlue,
902 "cornsilk": Cornsilk,
903 "crimson": Crimson,
904 "darkblue": DarkBlue,
905 "darkcyan": DarkCyan,
906 "darkgoldenrod": DarkGoldenrod,
907 "darkgray": DarkGray,
908 "darkgreen": DarkGreen,
909 "darkkhaki": DarkKhaki,
910 "darkmagenta": DarkMagenta,
911 "darkolivegreen": DarkOliveGreen,
912 "darkorange": DarkOrange,
913 "darkorchid": DarkOrchid,
914 "darkred": DarkRed,
915 "darksalmon": DarkSalmon,
916 "darkseagreen": DarkSeaGreen,
917 "darkslateblue": DarkSlateBlue,
918 "darkslategray": DarkSlateGray,
919 "darkturquoise": DarkTurquoise,
920 "darkviolet": DarkViolet,
921 "deeppink": DeepPink,
922 "deepskyblue": DeepSkyBlue,
923 "dimgray": DimGray,
924 "dodgerblue": DodgerBlue,
925 "firebrick": FireBrick,
926 "floralwhite": FloralWhite,
927 "forestgreen": ForestGreen,
928 "gainsboro": Gainsboro,
929 "ghostwhite": GhostWhite,
930 "gold": Gold,
931 "goldenrod": Goldenrod,
932 "greenyellow": GreenYellow,
933 "honeydew": Honeydew,
934 "hotpink": HotPink,
935 "indianred": IndianRed,
936 "indigo": Indigo,
937 "ivory": Ivory,
938 "khaki": Khaki,
939 "lavender": Lavender,
940 "lavenderblush": LavenderBlush,
941 "lawngreen": LawnGreen,
942 "lemonchiffon": LemonChiffon,
943 "lightblue": LightBlue,
944 "lightcoral": LightCoral,
945 "lightcyan": LightCyan,
946 "lightgoldenrodyellow": LightGoldenrodYellow,
947 "lightgray": LightGray,
948 "lightgreen": LightGreen,
949 "lightpink": LightPink,
950 "lightsalmon": LightSalmon,
951 "lightseagreen": LightSeaGreen,
952 "lightskyblue": LightSkyBlue,
953 "lightslategray": LightSlateGray,
954 "lightsteelblue": LightSteelBlue,
955 "lightyellow": LightYellow,
956 "limegreen": LimeGreen,
957 "linen": Linen,
958 "mediumaquamarine": MediumAquamarine,
959 "mediumblue": MediumBlue,
960 "mediumorchid": MediumOrchid,
961 "mediumpurple": MediumPurple,
962 "mediumseagreen": MediumSeaGreen,
963 "mediumslateblue": MediumSlateBlue,
964 "mediumspringgreen": MediumSpringGreen,
965 "mediumturquoise": MediumTurquoise,
966 "mediumvioletred": MediumVioletRed,
967 "midnightblue": MidnightBlue,
968 "mintcream": MintCream,
969 "mistyrose": MistyRose,
970 "moccasin": Moccasin,
971 "navajowhite": NavajoWhite,
972 "oldlace": OldLace,
973 "olivedrab": OliveDrab,
974 "orange": Orange,
975 "orangered": OrangeRed,
976 "orchid": Orchid,
977 "palegoldenrod": PaleGoldenrod,
978 "palegreen": PaleGreen,
979 "paleturquoise": PaleTurquoise,
980 "palevioletred": PaleVioletRed,
981 "papayawhip": PapayaWhip,
982 "peachpuff": PeachPuff,
983 "peru": Peru,
984 "pink": Pink,
985 "plum": Plum,
986 "powderblue": PowderBlue,
987 "rebeccapurple": RebeccaPurple,
988 "rosybrown": RosyBrown,
989 "royalblue": RoyalBlue,
990 "saddlebrown": SaddleBrown,
991 "salmon": Salmon,
992 "sandybrown": SandyBrown,
993 "seagreen": SeaGreen,
994 "seashell": Seashell,
995 "sienna": Sienna,
996 "skyblue": Skyblue,
997 "slateblue": SlateBlue,
998 "slategray": SlateGray,
999 "snow": Snow,
1000 "springgreen": SpringGreen,
1001 "steelblue": SteelBlue,
1002 "tan": Tan,
1003 "thistle": Thistle,
1004 "tomato": Tomato,
1005 "turquoise": Turquoise,
1006 "violet": Violet,
1007 "wheat": Wheat,
1008 "whitesmoke": WhiteSmoke,
1009 "yellowgreen": YellowGreen,
1010 "grey": Gray,
1011 "dimgrey": DimGray,
1012 "darkgrey": DarkGray,
1013 "darkslategrey": DarkSlateGray,
1014 "lightgrey": LightGray,
1015 "lightslategrey": LightSlateGray,
1016 "slategrey": SlateGray,
1017 }
1018
1019 // Valid indicates the color is a valid value (has been set).
1020 func (c Color) Valid() bool {
1021 return c&IsValid != 0
1022 }
1023
1024 // IsRGB is true if the color is an RGB specific value.
1025 func (c Color) IsRGB() bool {
1026 return c&(IsValid|IsRGB) == (IsValid | IsRGB)
1027 }
1028
1029 // CSS returns the CSS hex string ( #ABCDEF ) if valid
1030 // if not a valid color returns empty string
1031 func (c Color) CSS() string {
1032 if !c.Valid() {
1033 return ""
1034 }
1035 return fmt.Sprintf("#%06X", c.Hex())
1036 }
1037
1038 // String implements fmt.Stringer to return either the
1039 // W3C name if it has one or the CSS hex string '#ABCDEF'
1040 func (c Color) String() string {
1041 if !c.Valid() {
1042 switch c {
1043 case None:
1044 return "none"
1045 case Default:
1046 return "default"
1047 case Reset:
1048 return "reset"
1049 }
1050 return ""
1051 }
1052 return c.Name(true)
1053 }
1054
1055 // Name returns W3C name or an empty string if no arguments
1056 // if passed true as an argument it will falls back to
1057 // the CSS hex string if no W3C name found '#ABCDEF'
1058 func (c Color) Name(css ...bool) string {
1059 for name, hex := range Names {
1060 if c == hex {
1061 return name
1062 }
1063 }
1064 if len(css) > 0 && css[0] {
1065 return c.CSS()
1066 }
1067 return ""
1068 }
1069
1070 // Hex returns the color's hexadecimal RGB 24-bit value with each component
1071 // consisting of a single byte, R << 16 | G << 8 | B. If the color
1072 // is unknown or unset, -1 is returned.
1073 func (c Color) Hex() int32 {
1074 if !c.Valid() {
1075 return -1
1076 }
1077 if c&IsRGB != 0 {
1078 return int32(c & 0xffffff)
1079 }
1080 if v, ok := ColorValues[c]; ok {
1081 return v
1082 }
1083 return -1
1084 }
1085
1086 // RGB returns the red, green, and blue components of the color, with
1087 // each component represented as a value 0-255. In the event that the
1088 // color cannot be broken up (not set usually), -1 is returned for each value.
1089 func (c Color) RGB() (int32, int32, int32) {
1090 v := c.Hex()
1091 if v < 0 {
1092 return -1, -1, -1
1093 }
1094 return (v >> 16) & 0xff, (v >> 8) & 0xff, v & 0xff
1095 }
1096
1097 // TrueColor returns the true color (RGB) version of the provided color.
1098 // This is useful for ensuring color accuracy when using named colors.
1099 // This will override terminal theme colors.
1100 func (c Color) TrueColor() Color {
1101 if !c.Valid() {
1102 return Default
1103 }
1104 if c&IsRGB != 0 {
1105 return c | IsValid
1106 }
1107 if hex := c.Hex(); hex < 0 {
1108 return Default
1109 } else {
1110 return Color(hex) | IsRGB | IsValid
1111 }
1112 }
1113
1114 // RGBA makes these colors directly usable as imageColor colors.
1115 // The values are scaled only to 16 bits. Invalid colors are returned
1116 // with all values being zero (notably the alpha is zero, so fully transparent),
1117 // otherwise the alpha channel is set to 0xffff (fully opaque).
1118 func (c Color) RGBA() (r, g, b, a uint32) {
1119 if !c.Valid() {
1120 return 0, 0, 0, 0
1121 }
1122 r1, g1, b1 := c.RGB()
1123 r = uint32(r1)
1124 g = uint32(g1)
1125 b = uint32(b1)
1126 r = r | r<<8
1127 g = g | g<<8
1128 b = b | b<<8
1129 a = 0xffff
1130 return r, g, b, a
1131 }
1132
1133 // NewRGBColor returns a new color with the given red, green, and blue values.
1134 // Each value must be represented in the range 0-255.
1135 func NewRGBColor(r, g, b int32) Color {
1136 return NewHexColor(((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff))
1137 }
1138
1139 // NewHexColor returns a color using the given 24-bit RGB value.
1140 func NewHexColor(v int32) Color {
1141 return IsRGB | Color(v) | IsValid
1142 }
1143
1144 // GetColor creates a Color from a color name (W3C name). A hex value may
1145 // be supplied as a string in the format "#ffffff".
1146 func GetColor(name string) Color {
1147 if c, ok := Names[name]; ok {
1148 return c
1149 }
1150 if len(name) == 7 && name[0] == '#' {
1151 if v, e := strconv.ParseInt(name[1:], 16, 32); e == nil {
1152 return NewHexColor(int32(v))
1153 }
1154 }
1155 return Default
1156 }
1157
1158 // PaletteColor creates a color based on the palette index.
1159 func PaletteColor(index int) Color {
1160 return Color(index) | IsValid
1161 }
1162
1163 // FromImageColor converts an image/color.Color into Color.
1164 // The alpha value is limited to just zero and non-zero, so it should
1165 // be tracked separately if full detail is needed. (A zero alpha
1166 // becomes the default color, which means no color change at all.)
1167 func FromImageColor(imageColor ic.Color) Color {
1168 r, g, b, a := imageColor.RGBA()
1169 if a == 0 {
1170 return Default
1171 }
1172 // NOTE image/color.Color RGB values range is [0, 0xFFFF] as uint32
1173 return NewRGBColor(int32(r>>8), int32(g>>8), int32(b>>8))
1174 }