Switch to recommended form of GPLv3 permissions notice.
[emacs.git] / lisp / term / tty-colors.el
blobaae02bec1c4cd5ada126fd1451cbff6586cb54e4
1 ;;; tty-colors.el --- color support for character terminals
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Eli Zaretskii
7 ;; Maintainer: FSF
8 ;; Keywords: terminals, faces
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; Emacs support for colors evolved from the X Window System; color
28 ;; support for character-based terminals came later. Many Lisp
29 ;; packages use color names defined by X and assume the availability
30 ;; of certain functions that look up colors, convert them to pixel
31 ;; values, etc.
33 ;; This file provides a more or less useful emulation of the X color
34 ;; functionality for character-based terminals, and thus relieves the
35 ;; rest of Emacs from including special code for this case.
37 ;; Here's how it works. The support for terminal and MSDOS frames
38 ;; maintains an alist, called `tty-defined-color-alist', which
39 ;; associates colors supported by the terminal driver with small
40 ;; integers. (These small integers are passed to the library
41 ;; functions which set the color, and are effectively indices of the
42 ;; colors in the supported color palette.) When Emacs needs to send a
43 ;; color command to the terminal, the color name is first looked up in
44 ;; `tty-defined-color-alist'. If not found, functions from this file
45 ;; can be used to map the color to one of the supported colors.
46 ;; Specifically, the X RGB values of the requested color are extracted
47 ;; from `color-name-rgb-alist' and then the supported color is found
48 ;; with the minimal distance in the RGB space from the requested
49 ;; color.
51 ;; `tty-defined-color-alist' is created at startup by calling the
52 ;; function `tty-color-define', defined below, passing it each
53 ;; supported color, its index, and its RGB values. The standard list
54 ;; of colors supported by many Unix color terminals, including xterm,
55 ;; FreeBSD, and GNU/Linux, is supplied below in `tty-standard-colors'.
56 ;; If your terminal supports different or additional colors, call
57 ;; `tty-color-define' from your `.emacs' or `site-start.el'. For
58 ;; more-or-less standard definitions of VGA text-mode colors, see the
59 ;; beginning of lisp/term/pc-win.el.
61 ;;; Code:
63 (defvar msdos-color-values)
65 ;; The following list is taken from rgb.txt distributed with X.
67 ;; WARNING: Some colors, such as "lightred", do not appear in this
68 ;; list. If you think it's a good idea to add them, don't! The
69 ;; problem is that the X-standard definition of "red" actually
70 ;; corresponds to "lightred" on VGA (that's why pc-win.el and
71 ;; w32-fns.el define "lightred" with the same RGB values as "red"
72 ;; below). Adding "lightred" here would therefore create confusing
73 ;; and counter-intuitive results, like "red" and "lightred" being the
74 ;; same color. A similar situation exists with other "light*" colors.
76 ;; Nevertheless, "lightred" and other similar color names *are*
77 ;; defined for the MS-DOS and MS-Windows consoles, because the users
78 ;; on those systems expect these colors to be available.
80 ;; For these reasons, package maintaners are advised NOT to use color
81 ;; names such as "lightred" or "lightblue", because they will have
82 ;; different effect on different displays. Instead, use "red1" and
83 ;; "blue1", respectively.
85 ;; Note: the RGB values below are in the range 0-65535, but are derived
86 ;; from the standard 8-bit X definitions (so the upper and lower bytes
87 ;; of each value are actually identical).
89 (defvar color-name-rgb-alist
90 '(("snow" 65535 64250 64250)
91 ("ghostwhite" 63736 63736 65535)
92 ("whitesmoke" 62965 62965 62965)
93 ("gainsboro" 56540 56540 56540)
94 ("floralwhite" 65535 64250 61680)
95 ("oldlace" 65021 62965 59110)
96 ("linen" 64250 61680 59110)
97 ("antiquewhite" 64250 60395 55255)
98 ("papayawhip" 65535 61423 54741)
99 ("blanchedalmond" 65535 60395 52685)
100 ("bisque" 65535 58596 50372)
101 ("peachpuff" 65535 56026 47545)
102 ("navajowhite" 65535 57054 44461)
103 ("moccasin" 65535 58596 46517)
104 ("cornsilk" 65535 63736 56540)
105 ("ivory" 65535 65535 61680)
106 ("lemonchiffon" 65535 64250 52685)
107 ("seashell" 65535 62965 61166)
108 ("honeydew" 61680 65535 61680)
109 ("mintcream" 62965 65535 64250)
110 ("azure" 61680 65535 65535)
111 ("aliceblue" 61680 63736 65535)
112 ("lavender" 59110 59110 64250)
113 ("lavenderblush" 65535 61680 62965)
114 ("mistyrose" 65535 58596 57825)
115 ("white" 65535 65535 65535)
116 ("black" 0 0 0)
117 ("darkslategray" 12079 20303 20303)
118 ("darkslategrey" 12079 20303 20303)
119 ("dimgray" 26985 26985 26985)
120 ("dimgrey" 26985 26985 26985)
121 ("slategray" 28784 32896 37008)
122 ("slategrey" 28784 32896 37008)
123 ("lightslategray" 30583 34952 39321)
124 ("lightslategrey" 30583 34952 39321)
125 ("gray" 48830 48830 48830)
126 ("grey" 48830 48830 48830)
127 ("lightgrey" 54227 54227 54227)
128 ("lightgray" 54227 54227 54227)
129 ("midnightblue" 6425 6425 28784)
130 ("navy" 0 0 32896)
131 ("navyblue" 0 0 32896)
132 ("cornflowerblue" 25700 38293 60909)
133 ("darkslateblue" 18504 15677 35723)
134 ("slateblue" 27242 23130 52685)
135 ("mediumslateblue" 31611 26728 61166)
136 ("lightslateblue" 33924 28784 65535)
137 ("mediumblue" 0 0 52685)
138 ("royalblue" 16705 26985 57825)
139 ("blue" 0 0 65535)
140 ("dodgerblue" 7710 37008 65535)
141 ("deepskyblue" 0 49087 65535)
142 ("skyblue" 34695 52942 60395)
143 ("lightskyblue" 34695 52942 64250)
144 ("steelblue" 17990 33410 46260)
145 ("lightsteelblue" 45232 50372 57054)
146 ("lightblue" 44461 55512 59110)
147 ("powderblue" 45232 57568 59110)
148 ("paleturquoise" 44975 61166 61166)
149 ("darkturquoise" 0 52942 53713)
150 ("mediumturquoise" 18504 53713 52428)
151 ("turquoise" 16448 57568 53456)
152 ("cyan" 0 65535 65535)
153 ("lightcyan" 57568 65535 65535)
154 ("cadetblue" 24415 40606 41120)
155 ("mediumaquamarine" 26214 52685 43690)
156 ("aquamarine" 32639 65535 54484)
157 ("darkgreen" 0 25700 0)
158 ("darkolivegreen" 21845 27499 12079)
159 ("darkseagreen" 36751 48316 36751)
160 ("seagreen" 11822 35723 22359)
161 ("mediumseagreen" 15420 46003 29041)
162 ("lightseagreen" 8224 45746 43690)
163 ("palegreen" 39064 64507 39064)
164 ("springgreen" 0 65535 32639)
165 ("lawngreen" 31868 64764 0)
166 ("green" 0 65535 0)
167 ("chartreuse" 32639 65535 0)
168 ("mediumspringgreen" 0 64250 39578)
169 ("greenyellow" 44461 65535 12079)
170 ("limegreen" 12850 52685 12850)
171 ("yellowgreen" 39578 52685 12850)
172 ("forestgreen" 8738 35723 8738)
173 ("olivedrab" 27499 36494 8995)
174 ("darkkhaki" 48573 47031 27499)
175 ("khaki" 61680 59110 35980)
176 ("palegoldenrod" 61166 59624 43690)
177 ("lightgoldenrodyellow" 64250 64250 53970)
178 ("lightyellow" 65535 65535 57568)
179 ("yellow" 65535 65535 0)
180 ("gold" 65535 55255 0)
181 ("lightgoldenrod" 61166 56797 33410)
182 ("goldenrod" 56026 42405 8224)
183 ("darkgoldenrod" 47288 34438 2827)
184 ("rosybrown" 48316 36751 36751)
185 ("indianred" 52685 23644 23644)
186 ("saddlebrown" 35723 17733 4883)
187 ("sienna" 41120 21074 11565)
188 ("peru" 52685 34181 16191)
189 ("burlywood" 57054 47288 34695)
190 ("beige" 62965 62965 56540)
191 ("wheat" 62965 57054 46003)
192 ("sandybrown" 62708 42148 24672)
193 ("tan" 53970 46260 35980)
194 ("chocolate" 53970 26985 7710)
195 ("firebrick" 45746 8738 8738)
196 ("brown" 42405 10794 10794)
197 ("darksalmon" 59881 38550 31354)
198 ("salmon" 64250 32896 29298)
199 ("lightsalmon" 65535 41120 31354)
200 ("orange" 65535 42405 0)
201 ("darkorange" 65535 35980 0)
202 ("coral" 65535 32639 20560)
203 ("lightcoral" 61680 32896 32896)
204 ("tomato" 65535 25443 18247)
205 ("orangered" 65535 17733 0)
206 ("red" 65535 0 0)
207 ("hotpink" 65535 26985 46260)
208 ("deeppink" 65535 5140 37779)
209 ("pink" 65535 49344 52171)
210 ("lightpink" 65535 46774 49601)
211 ("palevioletred" 56283 28784 37779)
212 ("maroon" 45232 12336 24672)
213 ("mediumvioletred" 51143 5397 34181)
214 ("violetred" 53456 8224 37008)
215 ("magenta" 65535 0 65535)
216 ("violet" 61166 33410 61166)
217 ("plum" 56797 41120 56797)
218 ("orchid" 56026 28784 54998)
219 ("mediumorchid" 47802 21845 54227)
220 ("darkorchid" 39321 12850 52428)
221 ("darkviolet" 38036 0 54227)
222 ("blueviolet" 35466 11051 58082)
223 ("purple" 41120 8224 61680)
224 ("mediumpurple" 37779 28784 56283)
225 ("thistle" 55512 49087 55512)
226 ("snow1" 65535 64250 64250)
227 ("snow2" 61166 59881 59881)
228 ("snow3" 52685 51657 51657)
229 ("snow4" 35723 35209 35209)
230 ("seashell1" 65535 62965 61166)
231 ("seashell2" 61166 58853 57054)
232 ("seashell3" 52685 50629 49087)
233 ("seashell4" 35723 34438 33410)
234 ("antiquewhite1" 65535 61423 56283)
235 ("antiquewhite2" 61166 57311 52428)
236 ("antiquewhite3" 52685 49344 45232)
237 ("antiquewhite4" 35723 33667 30840)
238 ("bisque1" 65535 58596 50372)
239 ("bisque2" 61166 54741 47031)
240 ("bisque3" 52685 47031 40606)
241 ("bisque4" 35723 32125 27499)
242 ("peachpuff1" 65535 56026 47545)
243 ("peachpuff2" 61166 52171 44461)
244 ("peachpuff3" 52685 44975 38293)
245 ("peachpuff4" 35723 30583 25957)
246 ("navajowhite1" 65535 57054 44461)
247 ("navajowhite2" 61166 53199 41377)
248 ("navajowhite3" 52685 46003 35723)
249 ("navajowhite4" 35723 31097 24158)
250 ("lemonchiffon1" 65535 64250 52685)
251 ("lemonchiffon2" 61166 59881 49087)
252 ("lemonchiffon3" 52685 51657 42405)
253 ("lemonchiffon4" 35723 35209 28784)
254 ("cornsilk1" 65535 63736 56540)
255 ("cornsilk2" 61166 59624 52685)
256 ("cornsilk3" 52685 51400 45489)
257 ("cornsilk4" 35723 34952 30840)
258 ("ivory1" 65535 65535 61680)
259 ("ivory2" 61166 61166 57568)
260 ("ivory3" 52685 52685 49601)
261 ("ivory4" 35723 35723 33667)
262 ("honeydew1" 61680 65535 61680)
263 ("honeydew2" 57568 61166 57568)
264 ("honeydew3" 49601 52685 49601)
265 ("honeydew4" 33667 35723 33667)
266 ("lavenderblush1" 65535 61680 62965)
267 ("lavenderblush2" 61166 57568 58853)
268 ("lavenderblush3" 52685 49601 50629)
269 ("lavenderblush4" 35723 33667 34438)
270 ("mistyrose1" 65535 58596 57825)
271 ("mistyrose2" 61166 54741 53970)
272 ("mistyrose3" 52685 47031 46517)
273 ("mistyrose4" 35723 32125 31611)
274 ("azure1" 61680 65535 65535)
275 ("azure2" 57568 61166 61166)
276 ("azure3" 49601 52685 52685)
277 ("azure4" 33667 35723 35723)
278 ("slateblue1" 33667 28527 65535)
279 ("slateblue2" 31354 26471 61166)
280 ("slateblue3" 26985 22873 52685)
281 ("slateblue4" 18247 15420 35723)
282 ("royalblue1" 18504 30326 65535)
283 ("royalblue2" 17219 28270 61166)
284 ("royalblue3" 14906 24415 52685)
285 ("royalblue4" 10023 16448 35723)
286 ("blue1" 0 0 65535)
287 ("blue2" 0 0 61166)
288 ("blue3" 0 0 52685)
289 ("blue4" 0 0 35723)
290 ("dodgerblue1" 7710 37008 65535)
291 ("dodgerblue2" 7196 34438 61166)
292 ("dodgerblue3" 6168 29812 52685)
293 ("dodgerblue4" 4112 20046 35723)
294 ("steelblue1" 25443 47288 65535)
295 ("steelblue2" 23644 44204 61166)
296 ("steelblue3" 20303 38036 52685)
297 ("steelblue4" 13878 25700 35723)
298 ("deepskyblue1" 0 49087 65535)
299 ("deepskyblue2" 0 45746 61166)
300 ("deepskyblue3" 0 39578 52685)
301 ("deepskyblue4" 0 26728 35723)
302 ("skyblue1" 34695 52942 65535)
303 ("skyblue2" 32382 49344 61166)
304 ("skyblue3" 27756 42662 52685)
305 ("skyblue4" 19018 28784 35723)
306 ("lightskyblue1" 45232 58082 65535)
307 ("lightskyblue2" 42148 54227 61166)
308 ("lightskyblue3" 36237 46774 52685)
309 ("lightskyblue4" 24672 31611 35723)
310 ("slategray1" 50886 58082 65535)
311 ("slategray2" 47545 54227 61166)
312 ("slategray3" 40863 46774 52685)
313 ("slategray4" 27756 31611 35723)
314 ("lightsteelblue1" 51914 57825 65535)
315 ("lightsteelblue2" 48316 53970 61166)
316 ("lightsteelblue3" 41634 46517 52685)
317 ("lightsteelblue4" 28270 31611 35723)
318 ("lightblue1" 49087 61423 65535)
319 ("lightblue2" 45746 57311 61166)
320 ("lightblue3" 39578 49344 52685)
321 ("lightblue4" 26728 33667 35723)
322 ("lightcyan1" 57568 65535 65535)
323 ("lightcyan2" 53713 61166 61166)
324 ("lightcyan3" 46260 52685 52685)
325 ("lightcyan4" 31354 35723 35723)
326 ("paleturquoise1" 48059 65535 65535)
327 ("paleturquoise2" 44718 61166 61166)
328 ("paleturquoise3" 38550 52685 52685)
329 ("paleturquoise4" 26214 35723 35723)
330 ("cadetblue1" 39064 62965 65535)
331 ("cadetblue2" 36494 58853 61166)
332 ("cadetblue3" 31354 50629 52685)
333 ("cadetblue4" 21331 34438 35723)
334 ("turquoise1" 0 62965 65535)
335 ("turquoise2" 0 58853 61166)
336 ("turquoise3" 0 50629 52685)
337 ("turquoise4" 0 34438 35723)
338 ("cyan1" 0 65535 65535)
339 ("cyan2" 0 61166 61166)
340 ("cyan3" 0 52685 52685)
341 ("cyan4" 0 35723 35723)
342 ("darkslategray1" 38807 65535 65535)
343 ("darkslategray2" 36237 61166 61166)
344 ("darkslategray3" 31097 52685 52685)
345 ("darkslategray4" 21074 35723 35723)
346 ("aquamarine1" 32639 65535 54484)
347 ("aquamarine2" 30326 61166 50886)
348 ("aquamarine3" 26214 52685 43690)
349 ("aquamarine4" 17733 35723 29812)
350 ("darkseagreen1" 49601 65535 49601)
351 ("darkseagreen2" 46260 61166 46260)
352 ("darkseagreen3" 39835 52685 39835)
353 ("darkseagreen4" 26985 35723 26985)
354 ("seagreen1" 21588 65535 40863)
355 ("seagreen2" 20046 61166 38036)
356 ("seagreen3" 17219 52685 32896)
357 ("seagreen4" 11822 35723 22359)
358 ("palegreen1" 39578 65535 39578)
359 ("palegreen2" 37008 61166 37008)
360 ("palegreen3" 31868 52685 31868)
361 ("palegreen4" 21588 35723 21588)
362 ("springgreen1" 0 65535 32639)
363 ("springgreen2" 0 61166 30326)
364 ("springgreen3" 0 52685 26214)
365 ("springgreen4" 0 35723 17733)
366 ("green1" 0 65535 0)
367 ("green2" 0 61166 0)
368 ("green3" 0 52685 0)
369 ("green4" 0 35723 0)
370 ("chartreuse1" 32639 65535 0)
371 ("chartreuse2" 30326 61166 0)
372 ("chartreuse3" 26214 52685 0)
373 ("chartreuse4" 17733 35723 0)
374 ("olivedrab1" 49344 65535 15934)
375 ("olivedrab2" 46003 61166 14906)
376 ("olivedrab3" 39578 52685 12850)
377 ("olivedrab4" 26985 35723 8738)
378 ("darkolivegreen1" 51914 65535 28784)
379 ("darkolivegreen2" 48316 61166 26728)
380 ("darkolivegreen3" 41634 52685 23130)
381 ("darkolivegreen4" 28270 35723 15677)
382 ("khaki1" 65535 63222 36751)
383 ("khaki2" 61166 59110 34181)
384 ("khaki3" 52685 50886 29555)
385 ("khaki4" 35723 34438 20046)
386 ("lightgoldenrod1" 65535 60652 35723)
387 ("lightgoldenrod2" 61166 56540 33410)
388 ("lightgoldenrod3" 52685 48830 28784)
389 ("lightgoldenrod4" 35723 33153 19532)
390 ("lightyellow1" 65535 65535 57568)
391 ("lightyellow2" 61166 61166 53713)
392 ("lightyellow3" 52685 52685 46260)
393 ("lightyellow4" 35723 35723 31354)
394 ("yellow1" 65535 65535 0)
395 ("yellow2" 61166 61166 0)
396 ("yellow3" 52685 52685 0)
397 ("yellow4" 35723 35723 0)
398 ("gold1" 65535 55255 0)
399 ("gold2" 61166 51657 0)
400 ("gold3" 52685 44461 0)
401 ("gold4" 35723 30069 0)
402 ("goldenrod1" 65535 49601 9509)
403 ("goldenrod2" 61166 46260 8738)
404 ("goldenrod3" 52685 39835 7453)
405 ("goldenrod4" 35723 26985 5140)
406 ("darkgoldenrod1" 65535 47545 3855)
407 ("darkgoldenrod2" 61166 44461 3598)
408 ("darkgoldenrod3" 52685 38293 3084)
409 ("darkgoldenrod4" 35723 25957 2056)
410 ("rosybrown1" 65535 49601 49601)
411 ("rosybrown2" 61166 46260 46260)
412 ("rosybrown3" 52685 39835 39835)
413 ("rosybrown4" 35723 26985 26985)
414 ("indianred1" 65535 27242 27242)
415 ("indianred2" 61166 25443 25443)
416 ("indianred3" 52685 21845 21845)
417 ("indianred4" 35723 14906 14906)
418 ("sienna1" 65535 33410 18247)
419 ("sienna2" 61166 31097 16962)
420 ("sienna3" 52685 26728 14649)
421 ("sienna4" 35723 18247 9766)
422 ("burlywood1" 65535 54227 39835)
423 ("burlywood2" 61166 50629 37265)
424 ("burlywood3" 52685 43690 32125)
425 ("burlywood4" 35723 29555 21845)
426 ("wheat1" 65535 59367 47802)
427 ("wheat2" 61166 55512 44718)
428 ("wheat3" 52685 47802 38550)
429 ("wheat4" 35723 32382 26214)
430 ("tan1" 65535 42405 20303)
431 ("tan2" 61166 39578 18761)
432 ("tan3" 52685 34181 16191)
433 ("tan4" 35723 23130 11051)
434 ("chocolate1" 65535 32639 9252)
435 ("chocolate2" 61166 30326 8481)
436 ("chocolate3" 52685 26214 7453)
437 ("chocolate4" 35723 17733 4883)
438 ("firebrick1" 65535 12336 12336)
439 ("firebrick2" 61166 11308 11308)
440 ("firebrick3" 52685 9766 9766)
441 ("firebrick4" 35723 6682 6682)
442 ("brown1" 65535 16448 16448)
443 ("brown2" 61166 15163 15163)
444 ("brown3" 52685 13107 13107)
445 ("brown4" 35723 8995 8995)
446 ("salmon1" 65535 35980 26985)
447 ("salmon2" 61166 33410 25186)
448 ("salmon3" 52685 28784 21588)
449 ("salmon4" 35723 19532 14649)
450 ("lightsalmon1" 65535 41120 31354)
451 ("lightsalmon2" 61166 38293 29298)
452 ("lightsalmon3" 52685 33153 25186)
453 ("lightsalmon4" 35723 22359 16962)
454 ("orange1" 65535 42405 0)
455 ("orange2" 61166 39578 0)
456 ("orange3" 52685 34181 0)
457 ("orange4" 35723 23130 0)
458 ("darkorange1" 65535 32639 0)
459 ("darkorange2" 61166 30326 0)
460 ("darkorange3" 52685 26214 0)
461 ("darkorange4" 35723 17733 0)
462 ("coral1" 65535 29298 22102)
463 ("coral2" 61166 27242 20560)
464 ("coral3" 52685 23387 17733)
465 ("coral4" 35723 15934 12079)
466 ("tomato1" 65535 25443 18247)
467 ("tomato2" 61166 23644 16962)
468 ("tomato3" 52685 20303 14649)
469 ("tomato4" 35723 13878 9766)
470 ("orangered1" 65535 17733 0)
471 ("orangered2" 61166 16448 0)
472 ("orangered3" 52685 14135 0)
473 ("orangered4" 35723 9509 0)
474 ("red1" 65535 0 0)
475 ("red2" 61166 0 0)
476 ("red3" 52685 0 0)
477 ("red4" 35723 0 0)
478 ("deeppink1" 65535 5140 37779)
479 ("deeppink2" 61166 4626 35209)
480 ("deeppink3" 52685 4112 30326)
481 ("deeppink4" 35723 2570 20560)
482 ("hotpink1" 65535 28270 46260)
483 ("hotpink2" 61166 27242 42919)
484 ("hotpink3" 52685 24672 37008)
485 ("hotpink4" 35723 14906 25186)
486 ("pink1" 65535 46517 50629)
487 ("pink2" 61166 43433 47288)
488 ("pink3" 52685 37265 40606)
489 ("pink4" 35723 25443 27756)
490 ("lightpink1" 65535 44718 47545)
491 ("lightpink2" 61166 41634 44461)
492 ("lightpink3" 52685 35980 38293)
493 ("lightpink4" 35723 24415 25957)
494 ("palevioletred1" 65535 33410 43947)
495 ("palevioletred2" 61166 31097 40863)
496 ("palevioletred3" 52685 26728 35209)
497 ("palevioletred4" 35723 18247 23901)
498 ("maroon1" 65535 13364 46003)
499 ("maroon2" 61166 12336 42919)
500 ("maroon3" 52685 10537 37008)
501 ("maroon4" 35723 7196 25186)
502 ("violetred1" 65535 15934 38550)
503 ("violetred2" 61166 14906 35980)
504 ("violetred3" 52685 12850 30840)
505 ("violetred4" 35723 8738 21074)
506 ("magenta1" 65535 0 65535)
507 ("magenta2" 61166 0 61166)
508 ("magenta3" 52685 0 52685)
509 ("magenta4" 35723 0 35723)
510 ("orchid1" 65535 33667 64250)
511 ("orchid2" 61166 31354 59881)
512 ("orchid3" 52685 26985 51657)
513 ("orchid4" 35723 18247 35209)
514 ("plum1" 65535 48059 65535)
515 ("plum2" 61166 44718 61166)
516 ("plum3" 52685 38550 52685)
517 ("plum4" 35723 26214 35723)
518 ("mediumorchid1" 57568 26214 65535)
519 ("mediumorchid2" 53713 24415 61166)
520 ("mediumorchid3" 46260 21074 52685)
521 ("mediumorchid4" 31354 14135 35723)
522 ("darkorchid1" 49087 15934 65535)
523 ("darkorchid2" 45746 14906 61166)
524 ("darkorchid3" 39578 12850 52685)
525 ("darkorchid4" 26728 8738 35723)
526 ("purple1" 39835 12336 65535)
527 ("purple2" 37265 11308 61166)
528 ("purple3" 32125 9766 52685)
529 ("purple4" 21845 6682 35723)
530 ("mediumpurple1" 43947 33410 65535)
531 ("mediumpurple2" 40863 31097 61166)
532 ("mediumpurple3" 35209 26728 52685)
533 ("mediumpurple4" 23901 18247 35723)
534 ("thistle1" 65535 57825 65535)
535 ("thistle2" 61166 53970 61166)
536 ("thistle3" 52685 46517 52685)
537 ("thistle4" 35723 31611 35723)
538 ("gray0" 0 0 0)
539 ("grey0" 0 0 0)
540 ("gray1" 771 771 771)
541 ("grey1" 771 771 771)
542 ("gray2" 1285 1285 1285)
543 ("grey2" 1285 1285 1285)
544 ("gray3" 2056 2056 2056)
545 ("grey3" 2056 2056 2056)
546 ("gray4" 2570 2570 2570)
547 ("grey4" 2570 2570 2570)
548 ("gray5" 3341 3341 3341)
549 ("grey5" 3341 3341 3341)
550 ("gray6" 3855 3855 3855)
551 ("grey6" 3855 3855 3855)
552 ("gray7" 4626 4626 4626)
553 ("grey7" 4626 4626 4626)
554 ("gray8" 5140 5140 5140)
555 ("grey8" 5140 5140 5140)
556 ("gray9" 5911 5911 5911)
557 ("grey9" 5911 5911 5911)
558 ("gray10" 6682 6682 6682)
559 ("grey10" 6682 6682 6682)
560 ("gray11" 7196 7196 7196)
561 ("grey11" 7196 7196 7196)
562 ("gray12" 7967 7967 7967)
563 ("grey12" 7967 7967 7967)
564 ("gray13" 8481 8481 8481)
565 ("grey13" 8481 8481 8481)
566 ("gray14" 9252 9252 9252)
567 ("grey14" 9252 9252 9252)
568 ("gray15" 9766 9766 9766)
569 ("grey15" 9766 9766 9766)
570 ("gray16" 10537 10537 10537)
571 ("grey16" 10537 10537 10537)
572 ("gray17" 11051 11051 11051)
573 ("grey17" 11051 11051 11051)
574 ("gray18" 11822 11822 11822)
575 ("grey18" 11822 11822 11822)
576 ("gray19" 12336 12336 12336)
577 ("grey19" 12336 12336 12336)
578 ("gray20" 13107 13107 13107)
579 ("grey20" 13107 13107 13107)
580 ("gray21" 13878 13878 13878)
581 ("grey21" 13878 13878 13878)
582 ("gray22" 14392 14392 14392)
583 ("grey22" 14392 14392 14392)
584 ("gray23" 15163 15163 15163)
585 ("grey23" 15163 15163 15163)
586 ("gray24" 15677 15677 15677)
587 ("grey24" 15677 15677 15677)
588 ("gray25" 16448 16448 16448)
589 ("grey25" 16448 16448 16448)
590 ("gray26" 16962 16962 16962)
591 ("grey26" 16962 16962 16962)
592 ("gray27" 17733 17733 17733)
593 ("grey27" 17733 17733 17733)
594 ("gray28" 18247 18247 18247)
595 ("grey28" 18247 18247 18247)
596 ("gray29" 19018 19018 19018)
597 ("grey29" 19018 19018 19018)
598 ("gray30" 19789 19789 19789)
599 ("grey30" 19789 19789 19789)
600 ("gray31" 20303 20303 20303)
601 ("grey31" 20303 20303 20303)
602 ("gray32" 21074 21074 21074)
603 ("grey32" 21074 21074 21074)
604 ("gray33" 21588 21588 21588)
605 ("grey33" 21588 21588 21588)
606 ("gray34" 22359 22359 22359)
607 ("grey34" 22359 22359 22359)
608 ("gray35" 22873 22873 22873)
609 ("grey35" 22873 22873 22873)
610 ("gray36" 23644 23644 23644)
611 ("grey36" 23644 23644 23644)
612 ("gray37" 24158 24158 24158)
613 ("grey37" 24158 24158 24158)
614 ("gray38" 24929 24929 24929)
615 ("grey38" 24929 24929 24929)
616 ("gray39" 25443 25443 25443)
617 ("grey39" 25443 25443 25443)
618 ("gray40" 26214 26214 26214)
619 ("grey40" 26214 26214 26214)
620 ("gray41" 26985 26985 26985)
621 ("grey41" 26985 26985 26985)
622 ("gray42" 27499 27499 27499)
623 ("grey42" 27499 27499 27499)
624 ("gray43" 28270 28270 28270)
625 ("grey43" 28270 28270 28270)
626 ("gray44" 28784 28784 28784)
627 ("grey44" 28784 28784 28784)
628 ("gray45" 29555 29555 29555)
629 ("grey45" 29555 29555 29555)
630 ("gray46" 30069 30069 30069)
631 ("grey46" 30069 30069 30069)
632 ("gray47" 30840 30840 30840)
633 ("grey47" 30840 30840 30840)
634 ("gray48" 31354 31354 31354)
635 ("grey48" 31354 31354 31354)
636 ("gray49" 32125 32125 32125)
637 ("grey49" 32125 32125 32125)
638 ("gray50" 32639 32639 32639)
639 ("grey50" 32639 32639 32639)
640 ("gray51" 33410 33410 33410)
641 ("grey51" 33410 33410 33410)
642 ("gray52" 34181 34181 34181)
643 ("grey52" 34181 34181 34181)
644 ("gray53" 34695 34695 34695)
645 ("grey53" 34695 34695 34695)
646 ("gray54" 35466 35466 35466)
647 ("grey54" 35466 35466 35466)
648 ("gray55" 35980 35980 35980)
649 ("grey55" 35980 35980 35980)
650 ("gray56" 36751 36751 36751)
651 ("grey56" 36751 36751 36751)
652 ("gray57" 37265 37265 37265)
653 ("grey57" 37265 37265 37265)
654 ("gray58" 38036 38036 38036)
655 ("grey58" 38036 38036 38036)
656 ("gray59" 38550 38550 38550)
657 ("grey59" 38550 38550 38550)
658 ("gray60" 39321 39321 39321)
659 ("grey60" 39321 39321 39321)
660 ("gray61" 40092 40092 40092)
661 ("grey61" 40092 40092 40092)
662 ("gray62" 40606 40606 40606)
663 ("grey62" 40606 40606 40606)
664 ("gray63" 41377 41377 41377)
665 ("grey63" 41377 41377 41377)
666 ("gray64" 41891 41891 41891)
667 ("grey64" 41891 41891 41891)
668 ("gray65" 42662 42662 42662)
669 ("grey65" 42662 42662 42662)
670 ("gray66" 43176 43176 43176)
671 ("grey66" 43176 43176 43176)
672 ("gray67" 43947 43947 43947)
673 ("grey67" 43947 43947 43947)
674 ("gray68" 44461 44461 44461)
675 ("grey68" 44461 44461 44461)
676 ("gray69" 45232 45232 45232)
677 ("grey69" 45232 45232 45232)
678 ("gray70" 46003 46003 46003)
679 ("grey70" 46003 46003 46003)
680 ("gray71" 46517 46517 46517)
681 ("grey71" 46517 46517 46517)
682 ("gray72" 47288 47288 47288)
683 ("grey72" 47288 47288 47288)
684 ("gray73" 47802 47802 47802)
685 ("grey73" 47802 47802 47802)
686 ("gray74" 48573 48573 48573)
687 ("grey74" 48573 48573 48573)
688 ("gray75" 49087 49087 49087)
689 ("grey75" 49087 49087 49087)
690 ("gray76" 49858 49858 49858)
691 ("grey76" 49858 49858 49858)
692 ("gray77" 50372 50372 50372)
693 ("grey77" 50372 50372 50372)
694 ("gray78" 51143 51143 51143)
695 ("grey78" 51143 51143 51143)
696 ("gray79" 51657 51657 51657)
697 ("grey79" 51657 51657 51657)
698 ("gray80" 52428 52428 52428)
699 ("grey80" 52428 52428 52428)
700 ("gray81" 53199 53199 53199)
701 ("grey81" 53199 53199 53199)
702 ("gray82" 53713 53713 53713)
703 ("grey82" 53713 53713 53713)
704 ("gray83" 54484 54484 54484)
705 ("grey83" 54484 54484 54484)
706 ("gray84" 54998 54998 54998)
707 ("grey84" 54998 54998 54998)
708 ("gray85" 55769 55769 55769)
709 ("grey85" 55769 55769 55769)
710 ("gray86" 56283 56283 56283)
711 ("grey86" 56283 56283 56283)
712 ("gray87" 57054 57054 57054)
713 ("grey87" 57054 57054 57054)
714 ("gray88" 57568 57568 57568)
715 ("grey88" 57568 57568 57568)
716 ("gray89" 58339 58339 58339)
717 ("grey89" 58339 58339 58339)
718 ("gray90" 58853 58853 58853)
719 ("grey90" 58853 58853 58853)
720 ("gray91" 59624 59624 59624)
721 ("grey91" 59624 59624 59624)
722 ("gray92" 60395 60395 60395)
723 ("grey92" 60395 60395 60395)
724 ("gray93" 60909 60909 60909)
725 ("grey93" 60909 60909 60909)
726 ("gray94" 61680 61680 61680)
727 ("grey94" 61680 61680 61680)
728 ("gray95" 62194 62194 62194)
729 ("grey95" 62194 62194 62194)
730 ("gray96" 62965 62965 62965)
731 ("grey96" 62965 62965 62965)
732 ("gray97" 63479 63479 63479)
733 ("grey97" 63479 63479 63479)
734 ("gray98" 64250 64250 64250)
735 ("grey98" 64250 64250 64250)
736 ("gray99" 64764 64764 64764)
737 ("grey99" 64764 64764 64764)
738 ("gray100" 65535 65535 65535)
739 ("grey100" 65535 65535 65535)
740 ("darkgrey" 43433 43433 43433)
741 ("darkgray" 43433 43433 43433)
742 ("darkblue" 0 0 35723)
743 ("darkcyan" 0 35723 35723) ; no "lightmagenta", see comment above
744 ("darkmagenta" 35723 0 35723)
745 ("darkred" 35723 0 0) ; but no "lightred", see comment above
746 ("lightgreen" 37008 61166 37008))
747 "An alist of X color names and associated 16-bit RGB values.")
749 (defvar tty-standard-colors
750 '(("black" 0 0 0 0)
751 ("red" 1 65535 0 0)
752 ("green" 2 0 65535 0)
753 ("yellow" 3 65535 65535 0)
754 ("blue" 4 0 0 65535)
755 ("magenta" 5 65535 0 65535)
756 ("cyan" 6 0 65535 65535)
757 ("white" 7 65535 65535 65535))
758 "An alist of 8 standard tty colors, their indices and RGB values.")
760 ;; This is used by term.c
761 (defvar tty-color-mode-alist
762 '((never . -1)
763 (no . -1)
764 (default . 0)
765 (auto . 0)
766 (ansi8 . 8)
767 (always . 8)
768 (yes . 8))
769 "An alist of supported standard tty color modes and their aliases.")
771 (defvar tty-defined-color-alist nil
772 "An alist of defined terminal colors and their RGB values.
774 See the docstring of `tty-color-alist' for the details.")
776 (defun tty-color-alist (&optional frame)
777 "Return an alist of colors supported by FRAME's terminal.
778 FRAME defaults to the selected frame.
779 Each element of the returned alist is of the form:
780 \(NAME INDEX R G B\)
781 where NAME is the name of the color, a string;
782 INDEX is the index of this color to be sent to the terminal driver
783 when the color should be displayed; it is typically a small integer;
784 R, G, and B are the intensities of, accordingly, red, green, and blue
785 components of the color, represented as numbers between 0 and 65535.
786 The file `etc/rgb.txt' in the Emacs distribution lists the standard
787 RGB values of the X colors. If RGB is nil, this color will not be
788 considered by `tty-color-translate' as an approximation to another
789 color."
790 tty-defined-color-alist)
792 (defun tty-modify-color-alist (elt &optional frame)
793 "Put the association ELT into the alist of terminal colors for FRAME.
794 ELT should be of the form \(NAME INDEX R G B\) (see `tty-color-alist'
795 for details).
796 If the association for NAME already exists in the color alist, it is
797 modified to specify \(INDEX R G B\) as its cdr. Otherwise, ELT is
798 appended to the end of the color alist.
799 If FRAME is unspecified or nil, it defaults to the selected frame.
800 Value is the modified color alist for FRAME."
801 (let* ((entry (assoc (car elt) (tty-color-alist frame))))
802 (if entry
803 (setcdr entry (cdr elt))
804 ;; Keep the colors in the order they are registered.
805 (setq entry
806 (list (append (list (car elt)
807 (cadr elt))
808 (copy-sequence (cddr elt)))))
809 (setq tty-defined-color-alist (nconc tty-defined-color-alist entry)))
810 tty-defined-color-alist))
812 (defun tty-register-default-colors ()
813 "Register the default set of colors for a character terminal."
814 (let* ((colors (cond ((eq window-system 'pc)
815 msdos-color-values)
816 (t tty-standard-colors)))
817 (color (car colors)))
818 (while colors
819 (tty-color-define (car color) (cadr color) (cddr color))
820 (setq colors (cdr colors) color (car colors)))
821 ;; Modifying color mappings means realized faces don't
822 ;; use the right colors, so clear them.
823 (clear-face-cache)))
825 (defun tty-color-canonicalize (color)
826 "Return COLOR in canonical form.
827 A canonicalized color name is all-lower case, with any blanks removed."
828 (let ((case-fold-search nil))
829 (if (string-match "[A-Z ]" color)
830 (replace-regexp-in-string " +" "" (downcase color))
831 color)))
833 (defun tty-color-define (name index &optional rgb frame)
834 "Specify a tty color by its NAME, terminal INDEX and RGB values.
835 NAME is a string, INDEX is typically a small integer used to send to
836 the terminal driver a command to switch this color on, and RGB is a
837 list of 3 numbers that specify the intensity of red, green, and blue
838 components of the color.
839 If specified, each one of the RGB components must be a number between
840 0 and 65535. If RGB is omitted, the specified color will never be used
841 by `tty-color-translate' as an approximation to another color.
842 FRAME is the frame where the defined color should be used.
843 If FRAME is not specified or is nil, it defaults to the selected frame."
844 (if (or (not (stringp name))
845 (not (integerp index))
846 (and rgb (or (not (listp rgb)) (/= (length rgb) 3))))
847 (error "Invalid specification for tty color \"%s\"" name))
848 (tty-modify-color-alist
849 (append (list (tty-color-canonicalize name) index) rgb) frame))
851 (defun tty-color-clear (&optional frame)
852 "Clear the list of supported tty colors for frame FRAME.
853 If FRAME is unspecified or nil, it defaults to the selected frame."
854 (setq tty-defined-color-alist nil))
856 (defun tty-color-off-gray-diag (r g b)
857 "Compute the angle between the color given by R,G,B and the gray diagonal.
858 The gray diagonal is the diagonal of the 3D cube in RGB space which
859 connects the points corresponding to the black and white colors. All the
860 colors whose RGB coordinates belong to this diagonal are various shades
861 of gray, thus the name."
862 (let ((mag (sqrt (* 3 (+ (* r r) (* g g) (* b b))))))
863 (if (< mag 1) 0 (acos (/ (+ r g b) mag)))))
865 (defun tty-color-approximate (rgb &optional frame)
866 "Find the color in `tty-color-alist' that best approximates RGB.
867 Value is a list of the form \(NAME INDEX R G B\).
868 The argument RGB should be an rgb value, that is, a list of three
869 integers in the 0..65535 range.
870 FRAME defaults to the selected frame."
871 (let* ((color-list (tty-color-alist frame))
872 (candidate (car color-list))
873 (best-distance 195076) ;; 3 * 255^2 + 15
874 (r (ash (car rgb) -8))
875 (g (ash (cadr rgb) -8))
876 (b (ash (nth 2 rgb) -8))
877 best-color)
878 (while candidate
879 (let ((try-rgb (cddr candidate))
880 ;; If the approximated color is not close enough to the
881 ;; gray diagonal of the RGB cube, favor non-gray colors.
882 ;; (The number 0.065 is an empirical ad-hoc'ery.)
883 (favor-non-gray (>= (tty-color-off-gray-diag r g b) 0.065))
884 try-r try-g try-b
885 dif-r dif-g dif-b dist)
886 ;; If the RGB values of the candidate color are unknown, we
887 ;; never consider it for approximating another color.
888 (if try-rgb
889 (progn
890 (setq try-r (lsh (car try-rgb) -8)
891 try-g (lsh (cadr try-rgb) -8)
892 try-b (lsh (nth 2 try-rgb) -8))
893 (setq dif-r (- r try-r)
894 dif-g (- g try-g)
895 dif-b (- b try-b))
896 (setq dist (+ (* dif-r dif-r) (* dif-g dif-g) (* dif-b dif-b)))
897 (if (and (< dist best-distance)
898 ;; The candidate color is on the gray diagonal
899 ;; if its RGB components are all equal.
900 (or (/= try-r try-g) (/= try-g try-b)
901 (not favor-non-gray)))
902 (setq best-distance dist
903 best-color candidate)))))
904 (setq color-list (cdr color-list))
905 (setq candidate (car color-list)))
906 best-color))
908 (defun tty-color-standard-values (color)
909 "Return standard RGB values of the color COLOR.
911 The result is a list of integer RGB values--(RED GREEN BLUE).
912 These values range from 0 to 65535; white is (65535 65535 65535).
914 The returned value reflects the standard X definition of COLOR,
915 regardless of whether the terminal can display it, so the return value
916 should be the same regardless of what display is being used."
917 (let ((len (length color)))
918 (cond ((and (>= len 4) ;; X-style "#XXYYZZ" color spec
919 (eq (aref color 0) ?#)
920 (member (aref color 1)
921 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9
922 ?a ?b ?c ?d ?e ?f)))
923 ;; Translate the string "#XXYYZZ" into a list
924 ;; of numbers (XX YY ZZ). If the primary colors
925 ;; are specified with less than 4 hex digits,
926 ;; the used digits represent the most significant
927 ;; bits of the value (e.g. #XYZ = #X000Y000Z000).
928 (let* ((ndig (/ (- len 1) 3))
929 (i1 1)
930 (i2 (+ i1 ndig))
931 (i3 (+ i2 ndig)))
932 (list
933 (lsh
934 (string-to-number (substring color i1 i2) 16)
935 (* 4 (- 4 ndig)))
936 (lsh
937 (string-to-number (substring color i2 i3) 16)
938 (* 4 (- 4 ndig)))
939 (lsh
940 (string-to-number (substring color i3) 16)
941 (* 4 (- 4 ndig))))))
942 ((and (>= len 9) ;; X-style RGB:xx/yy/zz color spec
943 (string= (substring color 0 4) "rgb:"))
944 ;; Translate the string "RGB:XX/YY/ZZ" into a list
945 ;; of numbers (XX YY ZZ). If fewer than 4 hex
946 ;; digits are used, they represent the fraction
947 ;; of the maximum value (RGB:X/Y/Z = #XXXXYYYYZZZZ).
948 (let* ((ndig (/ (- len 3) 3))
949 (maxval (1- (ash 1 (* 4 (- ndig 1)))))
950 (i1 4)
951 (i2 (+ i1 ndig))
952 (i3 (+ i2 ndig)))
953 (list
954 (/ (* (string-to-number
955 (substring color i1 (- i2 1)) 16)
956 255)
957 maxval)
958 (/ (* (string-to-number
959 (substring color i2 (- i3 1)) 16)
960 255)
961 maxval)
962 (/ (* (string-to-number
963 (substring color i3) 16)
964 255)
965 maxval))))
967 (cdr (assoc color color-name-rgb-alist))))))
969 (defun tty-color-translate (color &optional frame)
970 "Given a color COLOR, return the index of the corresponding TTY color.
972 COLOR must be a string that is either the color's name, or its X-style
973 specification like \"#RRGGBB\" or \"RGB:rr/gg/bb\", where each primary.
974 color can be given with 1 to 4 hex digits.
976 If COLOR is a color name that is found among supported colors in
977 `tty-color-alist', the associated index is returned. Otherwise, the
978 RGB values of the color, either as given by the argument or from
979 looking up the name in `color-name-rgb-alist', are used to find the
980 supported color that is the best approximation for COLOR in the RGB
981 space.
982 If COLOR is neither a valid X RGB specification of the color, nor a
983 name of a color in `color-name-rgb-alist', the returned value is nil.
985 If FRAME is unspecified or nil, it defaults to the selected frame."
986 (cadr (tty-color-desc color frame)))
988 (defun tty-color-by-index (idx &optional frame)
989 "Given a numeric index of a tty color, return its description.
991 FRAME, if unspecified or nil, defaults to the selected frame.
992 Value is a list of the form \(NAME INDEX R G B\)."
993 (and idx
994 (let ((colors (tty-color-alist frame))
995 desc found)
996 (while colors
997 (setq desc (car colors))
998 (if (eq idx (car (cdr desc)))
999 (setq found desc))
1000 (setq colors (cdr colors)))
1001 found)))
1003 (defun tty-color-values (color &optional frame)
1004 "Return RGB values of the color COLOR on a termcap frame FRAME.
1006 If COLOR is not directly supported by the display, return the RGB
1007 values for a supported color that is its best approximation.
1008 The value is a list of integer RGB values--\(RED GREEN BLUE\).
1009 These values range from 0 to 65535; white is (65535 65535 65535).
1010 If FRAME is omitted or nil, use the selected frame."
1011 (cddr (tty-color-desc color frame)))
1013 (defun tty-color-desc (color &optional frame)
1014 "Return the description of the color COLOR for a character terminal.
1015 Value is a list of the form \(NAME INDEX R G B\). The returned NAME or
1016 RGB value may not be the same as the argument COLOR, because the latter
1017 might need to be approximated if it is not supported directly."
1018 (and (stringp color)
1019 (let ((color (tty-color-canonicalize color)))
1020 (or (assoc color (tty-color-alist frame))
1021 (let ((rgb (tty-color-standard-values color)))
1022 (and rgb (tty-color-approximate rgb frame)))))))
1024 (defun tty-color-gray-shades (&optional display)
1025 "Return the number of gray colors supported by DISPLAY's terminal.
1026 A color is considered gray if the 3 components of its RGB value are equal."
1027 (let* ((frame (if (framep display) display
1028 ;; FIXME: this uses an arbitrary frame from DISPLAY!
1029 (car (frames-on-display-list display))))
1030 (colors (tty-color-alist frame))
1031 (count 0)
1032 desc r g b)
1033 (while colors
1034 (setq desc (cddr (car colors))
1035 r (car desc)
1036 g (cadr desc)
1037 b (car (cddr desc)))
1038 (and (numberp r)
1039 (eq r g) (eq g b)
1040 (setq count (1+ count)))
1041 (setq colors (cdr colors)))
1042 count))
1044 ;; arch-tag: 84d5c3ef-ae22-4754-99ac-e6350c0967ae
1045 ;;; tty-colors.el ends here