Refill some copyright headers.
[bpt/emacs.git] / lisp / term / tty-colors.el
CommitLineData
8184a578 1;;; tty-colors.el --- color support for character terminals
f795f633 2
e9bffc61
GM
3;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4;; 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
f795f633 5
361535c2 6;; Author: Eli Zaretskii
f795f633
EZ
7;; Maintainer: FSF
8;; Keywords: terminals, faces
9
10;; This file is part of GNU Emacs.
11
1fecc8fe 12;; GNU Emacs is free software: you can redistribute it and/or modify
f795f633 13;; it under the terms of the GNU General Public License as published by
1fecc8fe
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
f795f633
EZ
16
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.
21
22;; You should have received a copy of the GNU General Public License
1fecc8fe 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
f795f633
EZ
24
25;;; Commentary:
26
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.
32
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.
36
37;; Here's how it works. The support for terminal and MSDOS frames
c8ad9e95
EZ
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.
f795f633
EZ
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.
50
c8ad9e95 51;; `tty-defined-color-alist' is created at startup by calling the
8e96a98d
EZ
52;; function `tty-register-default-colors', defined below, which in
53;; turn calls `tty-color-define', passing it each supported color, its
54;; index, and its RGB values. The standard list of colors supported
55;; by many Unix color terminals, including xterm, FreeBSD, and
56;; GNU/Linux, is supplied below in `tty-standard-colors'. Some
57;; terminal-specific files in lisp/term define their own standard
58;; colors. If your terminal supports different or additional colors,
59;; call `tty-color-define' from your `.emacs' or `site-start.el'. For
60;; more-or-less standard definitions of VGA text-mode colors, see
61;; lisp/term/pc-win.el.
f795f633
EZ
62
63;;; Code:
64
c8ad9e95
EZ
65;; The following list is taken from rgb.txt distributed with X.
66;;
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.
75;;
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.
79;;
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.
39ed191f
MB
84;;
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).
88;;
8f43cbf3 89(defconst color-name-rgb-alist
39ed191f
MB
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.")
f795f633 748
8f43cbf3 749(defconst tty-standard-colors
68fe2e0f 750 '(("black" 0 0 0 0)
f795f633 751 ("red" 1 65535 0 0)
68fe2e0f
EZ
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))
f795f633
EZ
758 "An alist of 8 standard tty colors, their indices and RGB values.")
759
9da8545a 760;; This is used by term.c
8f43cbf3 761(defconst tty-color-mode-alist
9da8545a
EZ
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.")
770
20de726e
EZ
771(defun tty-color-alist (&optional frame)
772 "Return an alist of colors supported by FRAME's terminal.
773FRAME defaults to the selected frame.
774Each element of the returned alist is of the form:
f795f633
EZ
775 \(NAME INDEX R G B\)
776where NAME is the name of the color, a string;
777INDEX is the index of this color to be sent to the terminal driver
778when the color should be displayed; it is typically a small integer;
779R, G, and B are the intensities of, accordingly, red, green, and blue
780components of the color, represented as numbers between 0 and 65535.
781The file `etc/rgb.txt' in the Emacs distribution lists the standard
782RGB values of the X colors. If RGB is nil, this color will not be
783considered by `tty-color-translate' as an approximation to another
20de726e
EZ
784color."
785 tty-defined-color-alist)
786
787(defun tty-modify-color-alist (elt &optional frame)
68fe2e0f 788 "Put the association ELT into the alist of terminal colors for FRAME.
20de726e
EZ
789ELT should be of the form \(NAME INDEX R G B\) (see `tty-color-alist'
790for details).
68fe2e0f
EZ
791If the association for NAME already exists in the color alist, it is
792modified to specify \(INDEX R G B\) as its cdr. Otherwise, ELT is
793appended to the end of the color alist.
20de726e
EZ
794If FRAME is unspecified or nil, it defaults to the selected frame.
795Value is the modified color alist for FRAME."
796 (let* ((entry (assoc (car elt) (tty-color-alist frame))))
797 (if entry
798 (setcdr entry (cdr elt))
68fe2e0f
EZ
799 ;; Keep the colors in the order they are registered.
800 (setq entry
801 (list (append (list (car elt)
802 (cadr elt))
803 (copy-sequence (cddr elt)))))
804 (setq tty-defined-color-alist (nconc tty-defined-color-alist entry)))
20de726e 805 tty-defined-color-alist))
f795f633 806
68fe2e0f
EZ
807(defun tty-register-default-colors ()
808 "Register the default set of colors for a character terminal."
8e96a98d 809 (let* ((colors tty-standard-colors)
68fe2e0f
EZ
810 (color (car colors)))
811 (while colors
812 (tty-color-define (car color) (cadr color) (cddr color))
813 (setq colors (cdr colors) color (car colors)))
814 ;; Modifying color mappings means realized faces don't
815 ;; use the right colors, so clear them.
816 (clear-face-cache)))
817
f795f633
EZ
818(defun tty-color-canonicalize (color)
819 "Return COLOR in canonical form.
820A canonicalized color name is all-lower case, with any blanks removed."
39ed191f
MB
821 (let ((case-fold-search nil))
822 (if (string-match "[A-Z ]" color)
823 (replace-regexp-in-string " +" "" (downcase color))
824 color)))
f795f633 825
20de726e 826(defun tty-color-define (name index &optional rgb frame)
f795f633
EZ
827 "Specify a tty color by its NAME, terminal INDEX and RGB values.
828NAME is a string, INDEX is typically a small integer used to send to
e2f599e9
EZ
829the terminal driver a command to switch this color on, and RGB is a
830list of 3 numbers that specify the intensity of red, green, and blue
831components of the color.
f795f633
EZ
832If specified, each one of the RGB components must be a number between
8330 and 65535. If RGB is omitted, the specified color will never be used
20de726e 834by `tty-color-translate' as an approximation to another color.
e2f599e9 835FRAME is the frame where the defined color should be used.
20de726e 836If FRAME is not specified or is nil, it defaults to the selected frame."
f795f633
EZ
837 (if (or (not (stringp name))
838 (not (integerp index))
839 (and rgb (or (not (listp rgb)) (/= (length rgb) 3))))
840 (error "Invalid specification for tty color \"%s\"" name))
20de726e
EZ
841 (tty-modify-color-alist
842 (append (list (tty-color-canonicalize name) index) rgb) frame))
f795f633 843
20de726e
EZ
844(defun tty-color-clear (&optional frame)
845 "Clear the list of supported tty colors for frame FRAME.
846If FRAME is unspecified or nil, it defaults to the selected frame."
847 (setq tty-defined-color-alist nil))
f795f633
EZ
848
849(defun tty-color-off-gray-diag (r g b)
e2f599e9
EZ
850 "Compute the angle between the color given by R,G,B and the gray diagonal.
851The gray diagonal is the diagonal of the 3D cube in RGB space which
852connects the points corresponding to the black and white colors. All the
853colors whose RGB coordinates belong to this diagonal are various shades
854of gray, thus the name."
f795f633
EZ
855 (let ((mag (sqrt (* 3 (+ (* r r) (* g g) (* b b))))))
856 (if (< mag 1) 0 (acos (/ (+ r g b) mag)))))
857
20de726e 858(defun tty-color-approximate (rgb &optional frame)
b96b979c
LT
859 "Find the color in `tty-color-alist' that best approximates RGB.
860Value is a list of the form \(NAME INDEX R G B\).
861The argument RGB should be an rgb value, that is, a list of three
862integers in the 0..65535 range.
20de726e
EZ
863FRAME defaults to the selected frame."
864 (let* ((color-list (tty-color-alist frame))
f795f633
EZ
865 (candidate (car color-list))
866 (best-distance 195076) ;; 3 * 255^2 + 15
39ed191f
MB
867 (r (ash (car rgb) -8))
868 (g (ash (cadr rgb) -8))
869 (b (ash (nth 2 rgb) -8))
f795f633
EZ
870 best-color)
871 (while candidate
39ed191f
MB
872 (let ((try-rgb (cddr candidate))
873 ;; If the approximated color is not close enough to the
874 ;; gray diagonal of the RGB cube, favor non-gray colors.
875 ;; (The number 0.065 is an empirical ad-hoc'ery.)
876 (favor-non-gray (>= (tty-color-off-gray-diag r g b) 0.065))
877 try-r try-g try-b
878 dif-r dif-g dif-b dist)
f795f633
EZ
879 ;; If the RGB values of the candidate color are unknown, we
880 ;; never consider it for approximating another color.
881 (if try-rgb
882 (progn
883 (setq try-r (lsh (car try-rgb) -8)
884 try-g (lsh (cadr try-rgb) -8)
885 try-b (lsh (nth 2 try-rgb) -8))
39ed191f
MB
886 (setq dif-r (- r try-r)
887 dif-g (- g try-g)
888 dif-b (- b try-b))
f795f633
EZ
889 (setq dist (+ (* dif-r dif-r) (* dif-g dif-g) (* dif-b dif-b)))
890 (if (and (< dist best-distance)
891 ;; The candidate color is on the gray diagonal
892 ;; if its RGB components are all equal.
893 (or (/= try-r try-g) (/= try-g try-b)
894 (not favor-non-gray)))
895 (setq best-distance dist
896 best-color candidate)))))
897 (setq color-list (cdr color-list))
898 (setq candidate (car color-list)))
39ed191f
MB
899 best-color))
900
901(defun tty-color-standard-values (color)
902"Return standard RGB values of the color COLOR.
903
904The result is a list of integer RGB values--(RED GREEN BLUE).
905These values range from 0 to 65535; white is (65535 65535 65535).
906
907The returned value reflects the standard X definition of COLOR,
908regardless of whether the terminal can display it, so the return value
909should be the same regardless of what display is being used."
910 (let ((len (length color)))
911 (cond ((and (>= len 4) ;; X-style "#XXYYZZ" color spec
912 (eq (aref color 0) ?#)
913 (member (aref color 1)
914 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9
915 ?a ?b ?c ?d ?e ?f)))
916 ;; Translate the string "#XXYYZZ" into a list
917 ;; of numbers (XX YY ZZ). If the primary colors
918 ;; are specified with less than 4 hex digits,
919 ;; the used digits represent the most significant
920 ;; bits of the value (e.g. #XYZ = #X000Y000Z000).
921 (let* ((ndig (/ (- len 1) 3))
922 (i1 1)
923 (i2 (+ i1 ndig))
924 (i3 (+ i2 ndig)))
925 (list
926 (lsh
927 (string-to-number (substring color i1 i2) 16)
928 (* 4 (- 4 ndig)))
929 (lsh
930 (string-to-number (substring color i2 i3) 16)
931 (* 4 (- 4 ndig)))
932 (lsh
933 (string-to-number (substring color i3) 16)
934 (* 4 (- 4 ndig))))))
935 ((and (>= len 9) ;; X-style RGB:xx/yy/zz color spec
936 (string= (substring color 0 4) "rgb:"))
937 ;; Translate the string "RGB:XX/YY/ZZ" into a list
938 ;; of numbers (XX YY ZZ). If fewer than 4 hex
939 ;; digits are used, they represent the fraction
940 ;; of the maximum value (RGB:X/Y/Z = #XXXXYYYYZZZZ).
941 (let* ((ndig (/ (- len 3) 3))
942 (maxval (1- (ash 1 (* 4 (- ndig 1)))))
943 (i1 4)
944 (i2 (+ i1 ndig))
945 (i3 (+ i2 ndig)))
946 (list
947 (/ (* (string-to-number
948 (substring color i1 (- i2 1)) 16)
949 255)
950 maxval)
951 (/ (* (string-to-number
952 (substring color i2 (- i3 1)) 16)
953 255)
954 maxval)
955 (/ (* (string-to-number
956 (substring color i3) 16)
957 255)
958 maxval))))
959 (t
960 (cdr (assoc color color-name-rgb-alist))))))
f795f633 961
20de726e 962(defun tty-color-translate (color &optional frame)
f795f633 963 "Given a color COLOR, return the index of the corresponding TTY color.
e2f599e9 964
f795f633
EZ
965COLOR must be a string that is either the color's name, or its X-style
966specification like \"#RRGGBB\" or \"RGB:rr/gg/bb\", where each primary.
967color can be given with 1 to 4 hex digits.
e2f599e9 968
f795f633
EZ
969If COLOR is a color name that is found among supported colors in
970`tty-color-alist', the associated index is returned. Otherwise, the
971RGB values of the color, either as given by the argument or from
972looking up the name in `color-name-rgb-alist', are used to find the
973supported color that is the best approximation for COLOR in the RGB
974space.
975If COLOR is neither a valid X RGB specification of the color, nor a
20de726e 976name of a color in `color-name-rgb-alist', the returned value is nil.
e2f599e9 977
20de726e 978If FRAME is unspecified or nil, it defaults to the selected frame."
39ed191f 979 (cadr (tty-color-desc color frame)))
f795f633 980
20de726e 981(defun tty-color-by-index (idx &optional frame)
f795f633 982 "Given a numeric index of a tty color, return its description.
e2f599e9 983
20de726e 984FRAME, if unspecified or nil, defaults to the selected frame.
f795f633
EZ
985Value is a list of the form \(NAME INDEX R G B\)."
986 (and idx
20de726e 987 (let ((colors (tty-color-alist frame))
f795f633
EZ
988 desc found)
989 (while colors
990 (setq desc (car colors))
991 (if (eq idx (car (cdr desc)))
992 (setq found desc))
993 (setq colors (cdr colors)))
994 found)))
995
996(defun tty-color-values (color &optional frame)
997 "Return RGB values of the color COLOR on a termcap frame FRAME.
e2f599e9 998
f795f633
EZ
999If COLOR is not directly supported by the display, return the RGB
1000values for a supported color that is its best approximation.
1001The value is a list of integer RGB values--\(RED GREEN BLUE\).
1002These values range from 0 to 65535; white is (65535 65535 65535).
1003If FRAME is omitted or nil, use the selected frame."
39ed191f 1004 (cddr (tty-color-desc color frame)))
f795f633 1005
20de726e 1006(defun tty-color-desc (color &optional frame)
f795f633 1007 "Return the description of the color COLOR for a character terminal.
39ed191f
MB
1008Value is a list of the form \(NAME INDEX R G B\). The returned NAME or
1009RGB value may not be the same as the argument COLOR, because the latter
1010might need to be approximated if it is not supported directly."
1011 (and (stringp color)
1012 (let ((color (tty-color-canonicalize color)))
1013 (or (assoc color (tty-color-alist frame))
1014 (let ((rgb (tty-color-standard-values color)))
1015 (and rgb (tty-color-approximate rgb frame)))))))
c527e600
EZ
1016
1017(defun tty-color-gray-shades (&optional display)
1018 "Return the number of gray colors supported by DISPLAY's terminal.
1019A color is considered gray if the 3 components of its RGB value are equal."
1020 (let* ((frame (if (framep display) display
1021 ;; FIXME: this uses an arbitrary frame from DISPLAY!
1022 (car (frames-on-display-list display))))
1023 (colors (tty-color-alist frame))
1024 (count 0)
1025 desc r g b)
1026 (while colors
1027 (setq desc (cddr (car colors))
1028 r (car desc)
1029 g (cadr desc)
1030 b (car (cddr desc)))
26b09289
EZ
1031 (and (numberp r)
1032 (eq r g) (eq g b)
c527e600
EZ
1033 (setq count (1+ count)))
1034 (setq colors (cdr colors)))
1035 count))
55535639
PJ
1036
1037;;; tty-colors.el ends here