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