aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii1999-12-06 17:55:00 +0000
committerEli Zaretskii1999-12-06 17:55:00 +0000
commitf795f63364fb98a5999930d6e09caabeae55ec1b (patch)
treed10e43e1beb5a324bee768876422759c43f72e79
parentb55048d4d61bc80e5906b469bdd41abdf472de68 (diff)
downloademacs-f795f63364fb98a5999930d6e09caabeae55ec1b.tar.gz
emacs-f795f63364fb98a5999930d6e09caabeae55ec1b.zip
Changes for automatic remapping of X colors on terminal frames:
* term/pc-win.el (msdos-setup-initial-frame): New function, run by term-setup-hook. Call msdos-remember-default-colors and msdos-handle-reverse-video. (msdos-face-setup): Parts of code moved to msdos-setup-initial-frame. (msdos-handle-reverse-video): New function, modeled after x-handle-reverse-video. (make-msdos-frame): Don't use initial-frame-alist and default-frame-alist. Call msdos-handle-reverse-video. (msdos-color-aliases): Remove. (msdos-color-translate, msdos-approximate-color): Remove. (msdos-color-values): Use 16-bit RGB values. RGB values updated for better approximation of X colors. (msdos-face-setup): Call tty-color-clear. Remove code that sets up tty-color-alist (it is now on startup.el). (x-display-color-p, x-color-defined-p, x-color-values, x-defined-colors, face-color-supported-p, face-color-gray-p): Remove. * facemenu.el (facemenu-read-color, list-colors-display): Use defined-colors for all frame types. (facemenu-color-equal): Use color-values for all frame types. * faces.el (read-face-attribute): For :foreground and :background attributes and frames on character terminals, translate the color to the closest supported one before looking it up in the list of valid values. (face-valid-attribute-values): Call defined-colors for all types of frames. (defined-colors, color-defined-p, color-values, display-color-p): New finctions. (x-defined-colors, x-color-defined-p, x-color-values, x-display-color-p): Aliases for the above. * startup.el (command-line): Register terminal colors for frame types other than x and w32, but only if the terminal supports colors. Call tty-color-define instead of face-register-tty-color. * term/x-win.el (xw-defined-colors): Renamed from x-defined-colors. * term/w32-win.el (xw-defined-colors): Likewise. * term/tty-colors.el: New file. * loadup.el: Load term/tty-colors.
-rw-r--r--lisp/ChangeLog49
-rw-r--r--lisp/facemenu.el18
-rw-r--r--lisp/faces.el64
-rw-r--r--lisp/loadup.el1
-rw-r--r--lisp/startup.el18
-rw-r--r--lisp/term/pc-win.el361
-rw-r--r--lisp/term/tty-colors.el938
-rw-r--r--lisp/term/w32-win.el6
-rw-r--r--lisp/term/x-win.el6
9 files changed, 1132 insertions, 329 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7972adaff37..36e9fb90c1b 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,52 @@
11999-12-06 Eli Zaretskii <eliz@is.elta.co.il>
2
3 Changes for automatic remapping of X colors on terminal frames:
4
5 * term/pc-win.el (msdos-setup-initial-frame): New function, run by
6 term-setup-hook. Call msdos-remember-default-colors and
7 msdos-handle-reverse-video.
8 (msdos-face-setup): Parts of code moved to
9 msdos-setup-initial-frame.
10 (msdos-handle-reverse-video): New function, modeled after
11 x-handle-reverse-video.
12 (make-msdos-frame): Don't use initial-frame-alist and
13 default-frame-alist. Call msdos-handle-reverse-video.
14 (msdos-color-aliases): Remove.
15 (msdos-color-translate, msdos-approximate-color): Remove.
16 (msdos-color-values): Use 16-bit RGB values. RGB values updated
17 for better approximation of X colors.
18 (msdos-face-setup): Call tty-color-clear. Remove code that sets
19 up tty-color-alist (it is now on startup.el).
20 (x-display-color-p, x-color-defined-p, x-color-values,
21 x-defined-colors, face-color-supported-p, face-color-gray-p):
22 Remove.
23
24 * facemenu.el (facemenu-read-color, list-colors-display): Use
25 defined-colors for all frame types.
26 (facemenu-color-equal): Use color-values for all frame types.
27
28 * faces.el (read-face-attribute): For :foreground and :background
29 attributes and frames on character terminals, translate the color
30 to the closest supported one before looking it up in the list of
31 valid values.
32 (face-valid-attribute-values): Call defined-colors for all types
33 of frames.
34 (defined-colors, color-defined-p, color-values, display-color-p):
35 New finctions.
36 (x-defined-colors, x-color-defined-p, x-color-values,
37 x-display-color-p): Aliases for the above.
38
39 * startup.el (command-line): Register terminal colors for frame
40 types other than x and w32, but only if the terminal supports
41 colors. Call tty-color-define instead of face-register-tty-color.
42
43 * term/x-win.el (xw-defined-colors): Renamed from
44 x-defined-colors.
45 * term/w32-win.el (xw-defined-colors): Likewise.
46
47 * term/tty-colors.el: New file.
48 * loadup.el: Load term/tty-colors.
49
11999-12-06 Dave Love <fx@gnu.org> 501999-12-06 Dave Love <fx@gnu.org>
2 51
3 * ffap.el: Autoload the ffap alias directly. 52 * ffap.el: Autoload the ffap alias directly.
diff --git a/lisp/facemenu.el b/lisp/facemenu.el
index 5ab3ccb7615..38414e582fc 100644
--- a/lisp/facemenu.el
+++ b/lisp/facemenu.el
@@ -467,9 +467,7 @@ These special properties include `invisible', `intangible' and `read-only'."
467 "Read a color using the minibuffer." 467 "Read a color using the minibuffer."
468 (let ((col (completing-read (or prompt "Color: ") 468 (let ((col (completing-read (or prompt "Color: ")
469 (or facemenu-color-alist 469 (or facemenu-color-alist
470 (if window-system 470 (mapcar 'list (defined-colors)))
471 (mapcar 'list (x-defined-colors))
472 (mapcar 'list (tty-defined-colors))))
473 nil t))) 471 nil t)))
474 (if (equal "" col) 472 (if (equal "" col)
475 nil 473 nil
@@ -483,9 +481,7 @@ colors to display. Otherwise, this command computes a list
483of colors that the current display can handle." 481of colors that the current display can handle."
484 (interactive) 482 (interactive)
485 (when (null list) 483 (when (null list)
486 (setq list (if window-system 484 (setq list (defined-colors))
487 (x-defined-colors)
488 (tty-defined-colors)))
489 ;; Delete duplicate colors. 485 ;; Delete duplicate colors.
490 (let ((l list)) 486 (let ((l list))
491 (while (cdr l) 487 (while (cdr l)
@@ -511,15 +507,11 @@ of colors that the current display can handle."
511(defun facemenu-color-equal (a b) 507(defun facemenu-color-equal (a b)
512 "Return t if colors A and B are the same color. 508 "Return t if colors A and B are the same color.
513A and B should be strings naming colors. 509A and B should be strings naming colors.
514This function queries the window-system server to find out what the 510This function queries the display system to find out what the color
515color names mean. It returns nil if the colors differ or if it can't 511names mean. It returns nil if the colors differ or if it can't
516determine the correct answer." 512determine the correct answer."
517 (cond ((equal a b) t) 513 (cond ((equal a b) t)
518 ((and (memq window-system '(x w32)) 514 ((equal (color-values a) (color-values b)))))
519 (equal (x-color-values a) (x-color-values b))))
520 ((eq window-system 'pc)
521 (and (x-color-defined-p a) (x-color-defined-p b)
522 (eq (msdos-color-translate a) (msdos-color-translate b))))))
523 515
524(defun facemenu-add-face (face &optional start end) 516(defun facemenu-add-face (face &optional start end)
525 "Add FACE to text between START and END. 517 "Add FACE to text between START and END.
diff --git a/lisp/faces.el b/lisp/faces.el
index 74fb666f6cc..80ed7fc12a7 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -758,8 +758,7 @@ an integer value."
758 (internal-lisp-face-attribute-values attribute)))) 758 (internal-lisp-face-attribute-values attribute))))
759 ((:foreground :background) 759 ((:foreground :background)
760 (mapcar #'(lambda (c) (cons c c)) 760 (mapcar #'(lambda (c) (cons c c))
761 (or (and window-system (x-defined-colors frame)) 761 (defined-colors frame)))
762 (tty-defined-colors))))
763 ((:height) 762 ((:height)
764 'integerp) 763 'integerp)
765 (:stipple 764 (:stipple
@@ -858,6 +857,13 @@ of a global face. Value is the new attribute value."
858 (cond ((listp valid) 857 (cond ((listp valid)
859 (setq new-value 858 (setq new-value
860 (face-read-string face old-value attribute-name valid)) 859 (face-read-string face old-value attribute-name valid))
860 ;; Terminal frames can support colors that don't appear
861 ;; explicitly in VALID, using color approximation code
862 ;; in tty-colors.el.
863 (if (and (memq attribute '(:foreground :background))
864 (not (memq window-system '(x w32 mac)))
865 (not (eq new-value 'unspecified)))
866 (setq new-value (car (tty-color-desc new-value))))
861 (unless (eq new-value 'unspecified) 867 (unless (eq new-value 'unspecified)
862 (setq new-value (cdr (assoc new-value valid))))) 868 (setq new-value (cdr (assoc new-value valid)))))
863 ((eq valid 'integerp) 869 ((eq valid 'integerp)
@@ -1141,6 +1147,60 @@ is used. If nil or omitted, use the selected frame."
1141 1147
1142 1148
1143;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1149;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1150;;; Frame-type independent color support.
1151;;; We keep the old x-* names as aliases for back-compatibility.
1152;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1153
1154(defun defined-colors (&optional frame)
1155 "Return a list of colors supported for a particular frame.
1156The argument FRAME specifies which frame to try.
1157The value may be different for frames on different display types.
1158If FRAME doesn't support colors, the value is nil."
1159 (if (memq (framep (or frame (selected-frame))) '(x w32))
1160 (xw-defined-colors frame)
1161 (mapcar 'car tty-color-alist)))
1162(defalias 'x-defined-colors 'defined-colors)
1163
1164(defun color-defined-p (color &optional frame)
1165 "Return non-nil if color COLOR is supported on frame FRAME.
1166If FRAME is omitted or nil, use the selected frame.
1167If COLOR is the symbol `unspecified', the value is nil."
1168 (if (eq color 'unspecified)
1169 nil
1170 (if (memq (framep (or frame (selected-frame))) '(x w32))
1171 (xw-color-defined-p color frame)
1172 (numberp (tty-color-translate color)))))
1173(defalias 'x-color-defined-p 'color-defined-p)
1174
1175(defun color-values (color &optional frame)
1176 "Return a description of the color named COLOR on frame FRAME.
1177The value is a list of integer RGB values--\(RED GREEN BLUE\).
1178These values appear to range from 0 to 65280 or 65535, depending
1179on the system; white is \(65280 65280 65280\) or \(65535 65535 65535\).
1180If FRAME is omitted or nil, use the selected frame.
1181If FRAME cannot display COLOR, the value is nil.
1182If COLOR is the symbol `unspecified', the value is nil."
1183 (if (eq color 'unspecified)
1184 nil
1185 (if (memq (framep (or frame (selected-frame))) '(x w32))
1186 (xw-color-values color frame)
1187 (tty-color-values color frame))))
1188(defalias 'x-color-values 'color-values)
1189
1190(defun display-color-p (&optional display)
1191 "Return t if DISPLAY supports color.
1192The optional argument DISPLAY specifies which display to ask about.
1193DISPLAY should be either a frame or a display name (a string).
1194If omitted or nil, that stands for the selected frame's display."
1195 (if (and (stringp display) (not (fboundp 'x-display-list)))
1196 nil
1197 (if (memq (framep (or display (selected-frame))) '(x w32))
1198 (xw-display-color-p display)
1199 (tty-display-color-p))))
1200(defalias 'x-display-color-p 'display-color-p)
1201
1202
1203;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1144;;; Background mode. 1204;;; Background mode.
1145;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 1205;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1146 1206
diff --git a/lisp/loadup.el b/lisp/loadup.el
index e4bca952c26..3a3fddd61bb 100644
--- a/lisp/loadup.el
+++ b/lisp/loadup.el
@@ -107,6 +107,7 @@
107(load "isearch") 107(load "isearch")
108(load "window") 108(load "window")
109(load "frame") 109(load "frame")
110(load "term/tty-colors")
110(load "faces") 111(load "faces")
111(if (fboundp 'frame-face-alist) 112(if (fboundp 'frame-face-alist)
112 (progn 113 (progn
diff --git a/lisp/startup.el b/lisp/startup.el
index 5a0b63e906c..e24f564cdc4 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -735,16 +735,16 @@ or `CVS', and any subdirectory that contains a file named `.nosearch'."
735 (funcall initial-major-mode)))) 735 (funcall initial-major-mode))))
736 736
737 ;; Register default TTY colors for the case the terminal hasn't a 737 ;; Register default TTY colors for the case the terminal hasn't a
738 ;; terminal init file. The colors are good for xterm-color and the 738 ;; terminal init file.
739 ;; FreeBSD console (cons.*). They should be sufficient for Linux 739 (or (memq window-system '(x w32))
740 ;; too, I guess. 740 (not (tty-display-color-p))
741 (or (eq window-system 'pc) ; pc-win.el did this already 741 (let* ((colors (if (eq window-system 'pc)
742 (let ((colors '("black" "red" "green" "yellow" "blue" "magenta" 742 msdos-color-values
743 "cyan" "white")) 743 tty-standard-colors))
744 (i 0)) 744 (color (car colors)))
745 (while colors 745 (while colors
746 (face-register-tty-color (car colors) i) 746 (tty-color-define (car color) (cadr color) (cddr color))
747 (setq colors (cdr colors) i (1+ i))))) 747 (setq colors (cdr colors) color (car colors)))))
748 748
749 ;; Load library for our terminal type. 749 ;; Load library for our terminal type.
750 ;; User init file can set term-file-prefix to nil to prevent this. 750 ;; User init file can set term-file-prefix to nil to prevent this.
diff --git a/lisp/term/pc-win.el b/lisp/term/pc-win.el
index b5a0e98ba3d..d08e6af2ec9 100644
--- a/lisp/term/pc-win.el
+++ b/lisp/term/pc-win.el
@@ -26,285 +26,46 @@
26 26
27(load "term/internal" nil t) 27(load "term/internal" nil t)
28 28
29;; Color translation -- doesn't really need to be fast.
30;; Colors listed here do not include the "light-",
31;; "medium-" and "dark-" prefixes that are accounted for
32;; by `msdos-color-translate', which see below).
33
34(defvar msdos-color-aliases
35 '(("snow" . "white")
36 ("ghost white" . "white")
37 ("ghostwhite" . "white")
38 ("white smoke" . "white")
39 ("whitesmoke" . "white")
40 ("gainsboro" . "white")
41 ("floral white" . "white")
42 ("floralwhite" . "white")
43 ("old lace" . "white")
44 ("oldlace" . "white")
45 ("linen" . "white")
46 ("antique white" . "white")
47 ("antiquewhite" . "white")
48 ("papaya whip" . "white")
49 ("papayawhip" . "white")
50 ("blanched almond" . "white")
51 ("blanchedalmond" . "white")
52 ("bisque" . "white")
53 ("peach puff" . "lightred")
54 ("peachpuff" . "lightred")
55 ("navajo white" . "lightred")
56 ("navajowhite" . "lightred")
57 ("moccasin" . "lightred")
58 ("cornsilk" . "white")
59 ("ivory" . "white")
60 ("lemon chiffon" . "yellow")
61 ("lemonchiffon" . "yellow")
62 ("seashell" . "white")
63 ("honeydew" . "white")
64 ("mint cream" . "white")
65 ("mintcream" . "white")
66 ("azure" . "lightcyan")
67 ("alice blue" . "lightcyan")
68 ("aliceblue" . "lightcyan")
69 ("lavender" . "lightcyan")
70 ("lavender blush" . "lightcyan")
71 ("lavenderblush" . "lightcyan")
72 ("misty rose" . "lightred")
73 ("mistyrose" . "lightred")
74 ("aquamarine" . "blue")
75 ("cadet blue" . "blue")
76 ("cadetblue" . "blue")
77 ("cornflower blue" . "lightblue")
78 ("cornflowerblue" . "lightblue")
79 ("midnight blue" . "blue")
80 ("midnightblue" . "blue")
81 ("navy blue" . "cyan")
82 ("navyblue" . "cyan")
83 ("navy" . "cyan")
84 ("royalblue" . "blue")
85 ("royal blue" . "blue")
86 ("sky blue" . "lightblue")
87 ("skyblue" . "lightblue")
88 ("dodger blue" . "blue")
89 ("dodgerblue" . "blue")
90 ("powder blue" . "lightblue")
91 ("powderblue" . "lightblue")
92 ("slate blue" . "cyan")
93 ("slateblue" . "cyan")
94 ("steel blue" . "blue")
95 ("steelblue" . "blue")
96 ("coral" . "lightred")
97 ("tomato" . "lightred")
98 ("firebrick" . "red")
99 ("gold" . "yellow")
100 ("goldenrod" . "yellow")
101 ("goldenrod yellow" . "yellow")
102 ("goldenrodyellow" . "yellow")
103 ("pale goldenrod" . "yellow")
104 ("palegoldenrod" . "yellow")
105 ("olive green" . "lightgreen")
106 ("olivegreen" . "lightgreen")
107 ("olive drab" . "green")
108 ("olivedrab" . "green")
109 ("forest green" . "green")
110 ("forestgreen" . "green")
111 ("lime green" . "lightgreen")
112 ("limegreen" . "lightgreen")
113 ("sea green" . "lightcyan")
114 ("seagreen" . "lightcyan")
115 ("spring green" . "green")
116 ("springgreen" . "green")
117 ("lawn green" . "lightgreen")
118 ("lawngreen" . "lightgreen")
119 ("chartreuse" . "yellow")
120 ("yellow green" . "lightgreen")
121 ("yellowgreen" . "lightgreen")
122 ("green yellow" . "lightgreen")
123 ("greenyellow" . "lightgreen")
124 ("slate grey" . "lightgray")
125 ("slategrey" . "lightgray")
126 ("slate gray" . "lightgray")
127 ("slategray" . "lightgray")
128 ("dim grey" . "darkgray")
129 ("dimgrey" . "darkgray")
130 ("dim gray" . "darkgray")
131 ("dimgray" . "darkgray")
132 ("light grey" . "lightgray")
133 ("lightgrey" . "lightgray")
134 ("light gray" . "lightgray")
135 ("gray" . "darkgray")
136 ("grey" . "darkgray")
137 ("khaki" . "green")
138 ("maroon" . "red")
139 ("orange" . "brown")
140 ("orchid" . "brown")
141 ("saddle brown" . "red")
142 ("saddlebrown" . "red")
143 ("peru" . "red")
144 ("burlywood" . "brown")
145 ("sandy brown" . "brown")
146 ("sandybrown" . "brown")
147 ("pink" . "lightred")
148 ("hotpink" . "lightred")
149 ("hot pink" ."lightred")
150 ("plum" . "magenta")
151 ("indian red" . "red")
152 ("indianred" . "red")
153 ("violet red" . "magenta")
154 ("violetred" . "magenta")
155 ("orange red" . "red")
156 ("orangered" . "red")
157 ("salmon" . "lightred")
158 ("sienna" . "lightred")
159 ("tan" . "lightred")
160 ("chocolate" . "brown")
161 ("thistle" . "magenta")
162 ("turquoise" . "lightgreen")
163 ("pale turquoise" . "cyan")
164 ("paleturquoise" . "cyan")
165 ("violet" . "magenta")
166 ("blue violet" . "lightmagenta")
167 ("blueviolet" . "lightmagenta")
168 ("wheat" . "white")
169 ("green yellow" . "yellow")
170 ("greenyellow" . "yellow")
171 ("purple" . "magenta")
172 ("rosybrown" . "brown")
173 ("rosy brown" . "brown")
174 ("beige" . "brown"))
175 "List of alternate names for colors.")
176
177(defun msdos-color-translate (name)
178 "Translate color specification in NAME into something DOS terminal groks."
179 (setq name (downcase name))
180 (let* ((len (length name))
181 (val (- (length x-colors)
182 (length (member name x-colors))))
183 (try))
184 (if (or (< val 0) (>= val (length x-colors))) (setq val nil))
185 (or val
186 (and (setq try (cdr (assoc name msdos-color-aliases)))
187 (msdos-color-translate try))
188 (and (> len 5)
189 (string= "light" (substring name 0 5))
190 (setq try (msdos-color-translate (substring name 5)))
191 (logior try 8))
192 (and (> len 6)
193 (string= "light " (substring name 0 6))
194 (setq try (msdos-color-translate (substring name 6)))
195 (logior try 8))
196 (and (> len 4)
197 (string= "pale" (substring name 0 4))
198 (setq try (msdos-color-translate (substring name 4)))
199 (logior try 8))
200 (and (> len 5)
201 (string= "pale " (substring name 0 5))
202 (setq try (msdos-color-translate (substring name 5)))
203 (logior try 8))
204 (and (> len 6)
205 (string= "medium" (substring name 0 6))
206 (msdos-color-translate (substring name 6)))
207 (and (> len 7)
208 (string= "medium " (substring name 0 7))
209 (msdos-color-translate (substring name 7)))
210 (and (> len 4)
211 (or (string= "dark" (substring name 0 4))
212 (string= "deep" (substring name 0 4)))
213 (msdos-color-translate (substring name 4)))
214 (and (> len 5)
215 (or (string= "dark " (substring name 0 5))
216 (string= "deep " (substring name 0 5)))
217 (msdos-color-translate (substring name 5)))
218 (and (> len 4) ;; gray shades: gray0 to gray100
219 (save-match-data
220 (and
221 (string-match "gr[ae]y[0-9]" name)
222 (string-match "[0-9]+\\'" name)
223 (let ((num (string-to-int
224 (substring name (match-beginning 0)))))
225 (msdos-color-translate
226 (cond
227 ((> num 90) "white")
228 ((> num 50) "lightgray")
229 ((> num 10) "darkgray")
230 (t "black")))))))
231 (and (> len 1) ;; purple1 to purple4 and the like
232 (save-match-data
233 (and
234 (string-match "[1-4]\\'" name)
235 (msdos-color-translate
236 (substring name 0 (match-beginning 0))))))
237 (and (= len 7) ;; X-style "#XXYYZZ" color spec
238 (eq (aref name 0) ?#)
239 (member (aref name 1)
240 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9
241 ?A ?B ?C ?D ?E ?F ?a ?b ?c ?d ?e ?f))
242 (msdos-color-translate
243 (msdos-approximate-color (string-to-number
244 (substring name 1) 16)))))))
245;;;
246;;; This is copied from etc/rgb.txt, except that some values were changed 29;;; This is copied from etc/rgb.txt, except that some values were changed
247;;; a bit to make them consistent with DOS console colors. The order of 30;;; a bit to make them consistent with DOS console colors, and the RGB
248;;; the colors is according to the PC text mode color codes. 31;;; values were scaled up to 16 bits, as `tty-define-color' requires.
32;;;
33;;; The mapping between the 16 standard EGA/VGA colors and X color names
34;;; was done by running a Unix version of Emacs inside an X client and a
35;;; DJGPP-compiled Emacs on the same PC. The names of X colors used to
36;;; define the pixel values are shown as comments to each color below.
249;;; 37;;;
250;;; If you want to change the RGB values, keep in mind that various pieces 38;;; If you want to change the RGB values, keep in mind that various pieces
251;;; of Emacs think that a color whose RGB values add up to less than 0.6 of 39;;; of Emacs think that a color whose RGB values add up to less than 0.6 of
252;;; the values for WHITE (i.e. less than 459) are ``dark'', otherwise the 40;;; the values for WHITE (i.e. less than 117963) are ``dark'', otherwise the
253;;; color is ``light''; see `frame-set-background-mode' in lisp/faces.el for 41;;; color is ``light''; see `frame-set-background-mode' in lisp/faces.el for
254;;; an example. 42;;; an example.
255(defvar msdos-color-values 43(defvar msdos-color-values
256 '(("black" 0 0 0) 44 '(("white" 15 65535 65535 65535)
257 ("blue" 0 0 255) 45 ("yellow" 14 65535 65535 0) ; Yellow
258 ("green" 0 255 0) 46 ("lightmagenta" 13 65535 0 65535) ; Magenta
259 ("cyan" 0 255 255) 47 ("lightred" 12 65535 0 0) ; Red
260 ("red" 255 0 0) 48 ("lightcyan" 11 0 65535 65535) ; Cyan
261 ("magenta" 139 0 139) ; dark magenta 49 ("lightgreen" 10 0 65535 0) ; Green
262 ("brown" 165 42 42) 50 ("lightblue" 9 0 0 65535) ; Blue
263 ("lightgray" 211 211 211) 51 ("darkgray" 8 26112 26112 26112) ; Gray40
264 ("darkgray" 102 102 102) ; gray40 52 ("lightgray" 7 48640 48640 48640) ; Gray
265 ("lightblue" 173 216 230) 53 ("brown" 6 40960 20992 11520) ; Sienna
266 ("lightgreen" 144 238 144) 54 ("magenta" 5 35584 0 35584) ; DarkMagenta
267 ("lightcyan" 224 255 255) 55 ("red" 4 45568 8704 8704) ; FireBrick
268 ("lightred" 255 52 179) ; maroon1 56 ("cyan" 3 0 52736 53504) ; DarkTurquoise
269 ("lightmagenta" 238 0 238) ; magenta2 57 ("green" 2 8704 35584 8704) ; ForestGreen
270 ("yellow" 255 255 0) 58 ("blue" 1 0 0 52480) ; MediumBlue
271 ("white" 255 255 255)) 59 ("black" 0 0 0 0))
272 "A list of MS-DOS console colors and their RGB values.") 60 "A list of MS-DOS console colors, their indices and 16-bit RGB values.")
273 61
274(defun msdos-approximate-color (num)
275 "Return a DOS color name which is the best approximation for the number NUM."
276 (let ((color-values msdos-color-values)
277 (candidate (car msdos-color-values))
278 (best-distance 16777216) ;; 0xFFFFFF + 1
279 best-color)
280 (while candidate
281 (let* ((values (cdr candidate))
282 (value (+ (lsh (car values) 16)
283 (lsh (car (cdr values)) 8)
284 (nth 2 values))))
285 (if (< (abs (- value num)) best-distance)
286 (setq best-distance (abs (- value num))
287 best-color (car candidate))))
288 (setq color-values (cdr color-values))
289 (setq candidate (car color-values)))
290 best-color))
291;; --------------------------------------------------------------------------- 62;; ---------------------------------------------------------------------------
292;; We want to delay setting frame parameters until the faces are setup 63;; We want to delay setting frame parameters until the faces are setup
293(defvar default-frame-alist nil) 64(defvar default-frame-alist nil)
294(modify-frame-parameters terminal-frame default-frame-alist) 65(modify-frame-parameters terminal-frame default-frame-alist)
66(tty-color-clear)
295 67
296(defun msdos-face-setup () 68(defun msdos-face-setup ()
297 (modify-frame-parameters terminal-frame default-frame-alist)
298 (face-clear-tty-colors)
299 (let ((colors msdos-color-values)
300 (i 0))
301 (while colors
302 (face-register-tty-color (car (car colors)) i)
303 (setq colors (cdr colors) i (1+ i))))
304
305 (frame-set-background-mode terminal-frame)
306 (face-set-after-frame-default terminal-frame)
307
308 (set-face-foreground 'bold "yellow" terminal-frame) 69 (set-face-foreground 'bold "yellow" terminal-frame)
309 (set-face-foreground 'italic "red" terminal-frame) 70 (set-face-foreground 'italic "red" terminal-frame)
310 (set-face-foreground 'bold-italic "lightred" terminal-frame) 71 (set-face-foreground 'bold-italic "lightred" terminal-frame)
@@ -319,18 +80,47 @@
319 (set-face-background 'msdos-menu-passive-face "blue" terminal-frame) 80 (set-face-background 'msdos-menu-passive-face "blue" terminal-frame)
320 (set-face-background 'msdos-menu-select-face "red" terminal-frame)) 81 (set-face-background 'msdos-menu-select-face "red" terminal-frame))
321 82
322;; We have only one font, so...
323(add-hook 'before-init-hook 'msdos-face-setup) 83(add-hook 'before-init-hook 'msdos-face-setup)
324 84
85(defun msdos-handle-reverse-video (frame parameters)
86 "Handle the reverse-video frame parameter on MS-DOS frames."
87 (when (cdr (assq 'reverse parameters))
88 (let* ((params (frame-parameters frame))
89 (bg (cdr (assq 'foreground-color params)))
90 (fg (cdr (assq 'background-color params))))
91 (modify-frame-parameters frame '((reverse . nil)))
92 (if (equal bg (cdr (assq 'mouse-color params)))
93 (modify-frame-parameters frame
94 (list (cons 'mouse-color fg))))
95 (if (equal bg (cdr (assq 'cursor-color params)))
96 (modify-frame-parameters frame
97 (list (cons 'cursor-color fg)))))))
98
99;; This must run after all the default colors are inserted into
100;; tty-color-alist, since msdos-handle-reverse-video needs to know the
101;; actual frame colors. tty-color-alist is set up by startup.el, but
102;; only after it runs before-init-hook and after-init-hook.
103(defun msdos-setup-initial-frame ()
104 (modify-frame-parameters terminal-frame default-frame-alist)
105 ;; This remembers the screen colors after applying default-frame-alist,
106 ;; so that all subsequent frames could begin with those colors.
107 (msdos-remember-default-colors terminal-frame)
108 (modify-frame-parameters terminal-frame initial-frame-alist)
109 (msdos-handle-reverse-video terminal-frame
110 (frame-parameters terminal-frame))
111
112 (frame-set-background-mode terminal-frame)
113 (face-set-after-frame-default terminal-frame))
114
115(add-hook 'term-setup-hook 'msdos-setup-initial-frame)
116
325;; We create frames as if we were a terminal, but with a twist. 117;; We create frames as if we were a terminal, but with a twist.
326(defun make-msdos-frame (&optional parameters) 118(defun make-msdos-frame (&optional parameters)
327 (let* ((parms 119 (let ((frame (make-terminal-frame parameters))
328 (append initial-frame-alist default-frame-alist parameters nil)) 120 success)
329 (frame (make-terminal-frame parms))
330 success)
331 (unwind-protect 121 (unwind-protect
332 (progn 122 (progn
333 (x-handle-reverse-video frame parms) 123 (msdos-handle-reverse-video frame (frame-parameters frame))
334 (frame-set-background-mode frame) 124 (frame-set-background-mode frame)
335 (face-set-after-frame-default frame) 125 (face-set-after-frame-default frame)
336 (setq success t)) 126 (setq success t))
@@ -346,12 +136,10 @@
346;; a useful function for returning 'nil regardless of argument. 136;; a useful function for returning 'nil regardless of argument.
347 137
348;; From src/xfns.c 138;; From src/xfns.c
349(defun x-display-color-p (&optional display) 't)
350(defun x-list-fonts (pattern &optional face frame maximum width) 139(defun x-list-fonts (pattern &optional face frame maximum width)
351 (if (or (null width) (and (numberp width) (= width 1))) 140 (if (or (null width) (and (numberp width) (= width 1)))
352 (list "ms-dos") 141 (list "ms-dos")
353 (list "no-such-font"))) 142 (list "no-such-font")))
354(defun x-color-defined-p (color) (numberp (msdos-color-translate color)))
355(defun x-display-pixel-width (&optional frame) (frame-width frame)) 143(defun x-display-pixel-width (&optional frame) (frame-width frame))
356(defun x-display-pixel-height (&optional frame) (frame-height frame)) 144(defun x-display-pixel-height (&optional frame) (frame-height frame))
357(defun x-display-planes (&optional frame) 4) ;bg switched to 16 colors as well 145(defun x-display-planes (&optional frame) 4) ;bg switched to 16 colors as well
@@ -367,33 +155,12 @@
367(fset 'x-display-save-under 'ignore) 155(fset 'x-display-save-under 'ignore)
368(fset 'x-get-resource 'ignore) 156(fset 'x-get-resource 'ignore)
369 157
370(defun x-color-values (color &optional frame)
371 "Return a description of the color named COLOR on frame FRAME.\n\
372The value is a list of integer RGB values--(RED GREEN BLUE).\n\
373These values range from 0 to 255; white is (255 255 255).\n\
374If FRAME is omitted or nil, use the selected frame."
375 (if (x-color-defined-p color)
376 (let ((frame (or frame (selected-frame)))
377 (color-code (msdos-color-translate color)))
378 (cdr (nth color-code msdos-color-values)))))
379
380;; From lisp/term/x-win.el 158;; From lisp/term/x-win.el
381(setq x-display-name "pc") 159(defvar x-display-name "pc"
160 "The display name specifying the MS-DOS display and frame type.")
382(setq split-window-keep-point t) 161(setq split-window-keep-point t)
383(defvar x-colors (mapcar 'car msdos-color-values) 162(defvar x-colors (mapcar 'car msdos-color-values)
384 "The list of colors available on a PC display under MS-DOS.") 163 "The list of colors available on a PC display under MS-DOS.")
385(defun x-defined-colors (&optional frame)
386 "Return a list of colors supported for a particular frame.
387The argument FRAME specifies which frame to try.
388The value may be different for frames on different X displays."
389 x-colors)
390
391(defun face-color-supported-p (color)
392 (x-color-defined-p color))
393
394(defun face-color-gray-p (color)
395 (member (msdos-color-translate color)
396 '("black" "lightgray" "darkgray" "white")))
397 164
398;; From lisp/term/w32-win.el 165;; From lisp/term/w32-win.el
399; 166;
diff --git a/lisp/term/tty-colors.el b/lisp/term/tty-colors.el
new file mode 100644
index 00000000000..f4836fe8efa
--- /dev/null
+++ b/lisp/term/tty-colors.el
@@ -0,0 +1,938 @@
1;;; tty-color.el --- color support for character terminals
2
3;; Copyright (C) 1999 Free Software Foundation, Inc.
4
5;; Author: Eli Zaretskii <eliz@is.elta.co.il>
6;; Maintainer: FSF
7;; Keywords: terminals, faces
8
9;; This file is part of GNU Emacs.
10
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 2, or (at your option)
14;; any later version.
15
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.
20
21;; You should have received a copy of the GNU General Public License
22;; along with GNU Emacs; see the file COPYING. If not, write to the
23;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24;; Boston, MA 02111-1307, USA.
25
26;;; Commentary:
27
28;; Emacs support for colors evolved from the X Window System; color
29;; support for character-based terminals came later. Many Lisp
30;; packages use color names defined by X and assume the availability
31;; of certain functions that look up colors, convert them to pixel
32;; values, etc.
33
34;; This file provides a more or less useful emulation of the X color
35;; functionality for character-based terminals, and thus relieves the
36;; rest of Emacs from including special code for this case.
37
38;; Here's how it works. The support for terminal and MSDOS frames
39;; maintains an alist, called `tty-color-alist', which associates
40;; colors supported by the terminal driver with small integers.
41;; (These small integers are passed to the library functions which set
42;; the color, and are effectively indices of the colors in the
43;; supported color palette.) When Emacs needs to send a color command
44;; to the terminal, the color name is first looked up in
45;; `tty-color-alist'. If not found, functions from this file can be
46;; used to map the color to one of the supported colors.
47;; Specifically, the X RGB values of the requested color are extracted
48;; from `color-name-rgb-alist' and then the supported color is found
49;; with the minimal distance in the RGB space from the requested
50;; color.
51
52;; `tty-color-alist' is created at startup by calling the function
53;; `tty-color-define', defined below, passing it each supported color,
54;; its index, and its RGB values. The standard list of colors
55;; supported by many Unix color terminals, including xterm, FreeBSD,
56;; and GNU/Linux, is supplied below in `tty-standard-colors'. If your
57;; terminal supports different or additional colors, call
58;; `tty-color-define' from your `.emacs' or `site-start.el'.
59
60;;; Code:
61
62(defvar color-name-rgb-alist
63 '(("snow" 255 250 250)
64 ("ghostwhite" 248 248 255)
65 ("whitesmoke" 245 245 245)
66 ("gainsboro" 220 220 220)
67 ("floralwhite" 255 250 240)
68 ("oldlace" 253 245 230)
69 ("linen" 250 240 230)
70 ("antiquewhite" 250 235 215)
71 ("papayawhip" 255 239 213)
72 ("blanchedalmond" 255 235 205)
73 ("bisque" 255 228 196)
74 ("peachpuff" 255 218 185)
75 ("navajowhite" 255 222 173)
76 ("moccasin" 255 228 181)
77 ("cornsilk" 255 248 220)
78 ("ivory" 255 255 240)
79 ("lemonchiffon" 255 250 205)
80 ("seashell" 255 245 238)
81 ("honeydew" 240 255 240)
82 ("mintcream" 245 255 250)
83 ("azure" 240 255 255)
84 ("aliceblue" 240 248 255)
85 ("lavender" 230 230 250)
86 ("lavenderblush" 255 240 245)
87 ("mistyrose" 255 228 225)
88 ("white" 255 255 255)
89 ("black" 0 0 0)
90 ("darkslategray" 47 79 79)
91 ("darkslategrey" 47 79 79)
92 ("dimgray" 105 105 105)
93 ("dimgrey" 105 105 105)
94 ("slategray" 112 128 144)
95 ("slategrey" 112 128 144)
96 ("lightslategray" 119 136 153)
97 ("lightslategrey" 119 136 153)
98 ("gray" 190 190 190)
99 ("grey" 190 190 190)
100 ("lightgrey" 211 211 211)
101 ("lightgray" 211 211 211)
102 ("midnightblue" 25 25 112)
103 ("navy" 0 0 128)
104 ("navyblue" 0 0 128)
105 ("cornflowerblue" 100 149 237)
106 ("darkslateblue" 72 61 139)
107 ("slateblue" 106 90 205)
108 ("mediumslateblue" 123 104 238)
109 ("lightslateblue" 132 112 255)
110 ("mediumblue" 0 0 205)
111 ("royalblue" 65 105 225)
112 ("blue" 0 0 255)
113 ("dodgerblue" 30 144 255)
114 ("deepskyblue" 0 191 255)
115 ("skyblue" 135 206 235)
116 ("lightskyblue" 135 206 250)
117 ("steelblue" 70 130 180)
118 ("lightsteelblue" 176 196 222)
119 ("lightblue" 173 216 230)
120 ("powderblue" 176 224 230)
121 ("paleturquoise" 175 238 238)
122 ("darkturquoise" 0 206 209)
123 ("mediumturquoise" 72 209 204)
124 ("turquoise" 64 224 208)
125 ("cyan" 0 255 255)
126 ("lightcyan" 224 255 255)
127 ("cadetblue" 95 158 160)
128 ("mediumaquamarine" 102 205 170)
129 ("aquamarine" 127 255 212)
130 ("darkgreen" 0 100 0)
131 ("darkolivegreen" 85 107 47)
132 ("darkseagreen" 143 188 143)
133 ("seagreen" 46 139 87)
134 ("mediumseagreen" 60 179 113)
135 ("lightseagreen" 32 178 170)
136 ("palegreen" 152 251 152)
137 ("springgreen" 0 255 127)
138 ("lawngreen" 124 252 0)
139 ("green" 0 255 0)
140 ("chartreuse" 127 255 0)
141 ("mediumspringgreen" 0 250 154)
142 ("greenyellow" 173 255 47)
143 ("limegreen" 50 205 50)
144 ("yellowgreen" 154 205 50)
145 ("forestgreen" 34 139 34)
146 ("olivedrab" 107 142 35)
147 ("darkkhaki" 189 183 107)
148 ("khaki" 240 230 140)
149 ("palegoldenrod" 238 232 170)
150 ("lightgoldenrodyellow" 250 250 210)
151 ("lightyellow" 255 255 224)
152 ("yellow" 255 255 0)
153 ("gold" 255 215 0)
154 ("lightgoldenrod" 238 221 130)
155 ("goldenrod" 218 165 32)
156 ("darkgoldenrod" 184 134 11)
157 ("rosybrown" 188 143 143)
158 ("indianred" 205 92 92)
159 ("saddlebrown" 139 69 19)
160 ("sienna" 160 82 45)
161 ("peru" 205 133 63)
162 ("burlywood" 222 184 135)
163 ("beige" 245 245 220)
164 ("wheat" 245 222 179)
165 ("sandybrown" 244 164 96)
166 ("tan" 210 180 140)
167 ("chocolate" 210 105 30)
168 ("firebrick" 178 34 34)
169 ("brown" 165 42 42)
170 ("darksalmon" 233 150 122)
171 ("salmon" 250 128 114)
172 ("lightsalmon" 255 160 122)
173 ("orange" 255 165 0)
174 ("darkorange" 255 140 0)
175 ("coral" 255 127 80)
176 ("lightcoral" 240 128 128)
177 ("tomato" 255 99 71)
178 ("orangered" 255 69 0)
179 ("red" 255 0 0)
180 ("hotpink" 255 105 180)
181 ("deeppink" 255 20 147)
182 ("pink" 255 192 203)
183 ("lightpink" 255 182 193)
184 ("palevioletred" 219 112 147)
185 ("maroon" 176 48 96)
186 ("mediumvioletred" 199 21 133)
187 ("violetred" 208 32 144)
188 ("magenta" 255 0 255)
189 ("violet" 238 130 238)
190 ("plum" 221 160 221)
191 ("orchid" 218 112 214)
192 ("mediumorchid" 186 85 211)
193 ("darkorchid" 153 50 204)
194 ("darkviolet" 148 0 211)
195 ("blueviolet" 138 43 226)
196 ("purple" 160 32 240)
197 ("mediumpurple" 147 112 219)
198 ("thistle" 216 191 216)
199 ("snow1" 255 250 250)
200 ("snow2" 238 233 233)
201 ("snow3" 205 201 201)
202 ("snow4" 139 137 137)
203 ("seashell1" 255 245 238)
204 ("seashell2" 238 229 222)
205 ("seashell3" 205 197 191)
206 ("seashell4" 139 134 130)
207 ("antiquewhite1" 255 239 219)
208 ("antiquewhite2" 238 223 204)
209 ("antiquewhite3" 205 192 176)
210 ("antiquewhite4" 139 131 120)
211 ("bisque1" 255 228 196)
212 ("bisque2" 238 213 183)
213 ("bisque3" 205 183 158)
214 ("bisque4" 139 125 107)
215 ("peachpuff1" 255 218 185)
216 ("peachpuff2" 238 203 173)
217 ("peachpuff3" 205 175 149)
218 ("peachpuff4" 139 119 101)
219 ("navajowhite1" 255 222 173)
220 ("navajowhite2" 238 207 161)
221 ("navajowhite3" 205 179 139)
222 ("navajowhite4" 139 121 94)
223 ("lemonchiffon1" 255 250 205)
224 ("lemonchiffon2" 238 233 191)
225 ("lemonchiffon3" 205 201 165)
226 ("lemonchiffon4" 139 137 112)
227 ("cornsilk1" 255 248 220)
228 ("cornsilk2" 238 232 205)
229 ("cornsilk3" 205 200 177)
230 ("cornsilk4" 139 136 120)
231 ("ivory1" 255 255 240)
232 ("ivory2" 238 238 224)
233 ("ivory3" 205 205 193)
234 ("ivory4" 139 139 131)
235 ("honeydew1" 240 255 240)
236 ("honeydew2" 224 238 224)
237 ("honeydew3" 193 205 193)
238 ("honeydew4" 131 139 131)
239 ("lavenderblush1" 255 240 245)
240 ("lavenderblush2" 238 224 229)
241 ("lavenderblush3" 205 193 197)
242 ("lavenderblush4" 139 131 134)
243 ("mistyrose1" 255 228 225)
244 ("mistyrose2" 238 213 210)
245 ("mistyrose3" 205 183 181)
246 ("mistyrose4" 139 125 123)
247 ("azure1" 240 255 255)
248 ("azure2" 224 238 238)
249 ("azure3" 193 205 205)
250 ("azure4" 131 139 139)
251 ("slateblue1" 131 111 255)
252 ("slateblue2" 122 103 238)
253 ("slateblue3" 105 89 205)
254 ("slateblue4" 71 60 139)
255 ("royalblue1" 72 118 255)
256 ("royalblue2" 67 110 238)
257 ("royalblue3" 58 95 205)
258 ("royalblue4" 39 64 139)
259 ("blue1" 0 0 255)
260 ("blue2" 0 0 238)
261 ("blue3" 0 0 205)
262 ("blue4" 0 0 139)
263 ("dodgerblue1" 30 144 255)
264 ("dodgerblue2" 28 134 238)
265 ("dodgerblue3" 24 116 205)
266 ("dodgerblue4" 16 78 139)
267 ("steelblue1" 99 184 255)
268 ("steelblue2" 92 172 238)
269 ("steelblue3" 79 148 205)
270 ("steelblue4" 54 100 139)
271 ("deepskyblue1" 0 191 255)
272 ("deepskyblue2" 0 178 238)
273 ("deepskyblue3" 0 154 205)
274 ("deepskyblue4" 0 104 139)
275 ("skyblue1" 135 206 255)
276 ("skyblue2" 126 192 238)
277 ("skyblue3" 108 166 205)
278 ("skyblue4" 74 112 139)
279 ("lightskyblue1" 176 226 255)
280 ("lightskyblue2" 164 211 238)
281 ("lightskyblue3" 141 182 205)
282 ("lightskyblue4" 96 123 139)
283 ("slategray1" 198 226 255)
284 ("slategray2" 185 211 238)
285 ("slategray3" 159 182 205)
286 ("slategray4" 108 123 139)
287 ("lightsteelblue1" 202 225 255)
288 ("lightsteelblue2" 188 210 238)
289 ("lightsteelblue3" 162 181 205)
290 ("lightsteelblue4" 110 123 139)
291 ("lightblue1" 191 239 255)
292 ("lightblue2" 178 223 238)
293 ("lightblue3" 154 192 205)
294 ("lightblue4" 104 131 139)
295 ("lightcyan1" 224 255 255)
296 ("lightcyan2" 209 238 238)
297 ("lightcyan3" 180 205 205)
298 ("lightcyan4" 122 139 139)
299 ("paleturquoise1" 187 255 255)
300 ("paleturquoise2" 174 238 238)
301 ("paleturquoise3" 150 205 205)
302 ("paleturquoise4" 102 139 139)
303 ("cadetblue1" 152 245 255)
304 ("cadetblue2" 142 229 238)
305 ("cadetblue3" 122 197 205)
306 ("cadetblue4" 83 134 139)
307 ("turquoise1" 0 245 255)
308 ("turquoise2" 0 229 238)
309 ("turquoise3" 0 197 205)
310 ("turquoise4" 0 134 139)
311 ("cyan1" 0 255 255)
312 ("cyan2" 0 238 238)
313 ("cyan3" 0 205 205)
314 ("cyan4" 0 139 139)
315 ("darkslategray1" 151 255 255)
316 ("darkslategray2" 141 238 238)
317 ("darkslategray3" 121 205 205)
318 ("darkslategray4" 82 139 139)
319 ("aquamarine1" 127 255 212)
320 ("aquamarine2" 118 238 198)
321 ("aquamarine3" 102 205 170)
322 ("aquamarine4" 69 139 116)
323 ("darkseagreen1" 193 255 193)
324 ("darkseagreen2" 180 238 180)
325 ("darkseagreen3" 155 205 155)
326 ("darkseagreen4" 105 139 105)
327 ("seagreen1" 84 255 159)
328 ("seagreen2" 78 238 148)
329 ("seagreen3" 67 205 128)
330 ("seagreen4" 46 139 87)
331 ("palegreen1" 154 255 154)
332 ("palegreen2" 144 238 144)
333 ("palegreen3" 124 205 124)
334 ("palegreen4" 84 139 84)
335 ("springgreen1" 0 255 127)
336 ("springgreen2" 0 238 118)
337 ("springgreen3" 0 205 102)
338 ("springgreen4" 0 139 69)
339 ("green1" 0 255 0)
340 ("green2" 0 238 0)
341 ("green3" 0 205 0)
342 ("green4" 0 139 0)
343 ("chartreuse1" 127 255 0)
344 ("chartreuse2" 118 238 0)
345 ("chartreuse3" 102 205 0)
346 ("chartreuse4" 69 139 0)
347 ("olivedrab1" 192 255 62)
348 ("olivedrab2" 179 238 58)
349 ("olivedrab3" 154 205 50)
350 ("olivedrab4" 105 139 34)
351 ("darkolivegreen1" 202 255 112)
352 ("darkolivegreen2" 188 238 104)
353 ("darkolivegreen3" 162 205 90)
354 ("darkolivegreen4" 110 139 61)
355 ("khaki1" 255 246 143)
356 ("khaki2" 238 230 133)
357 ("khaki3" 205 198 115)
358 ("khaki4" 139 134 78)
359 ("lightgoldenrod1" 255 236 139)
360 ("lightgoldenrod2" 238 220 130)
361 ("lightgoldenrod3" 205 190 112)
362 ("lightgoldenrod4" 139 129 76)
363 ("lightyellow1" 255 255 224)
364 ("lightyellow2" 238 238 209)
365 ("lightyellow3" 205 205 180)
366 ("lightyellow4" 139 139 122)
367 ("yellow1" 255 255 0)
368 ("yellow2" 238 238 0)
369 ("yellow3" 205 205 0)
370 ("yellow4" 139 139 0)
371 ("gold1" 255 215 0)
372 ("gold2" 238 201 0)
373 ("gold3" 205 173 0)
374 ("gold4" 139 117 0)
375 ("goldenrod1" 255 193 37)
376 ("goldenrod2" 238 180 34)
377 ("goldenrod3" 205 155 29)
378 ("goldenrod4" 139 105 20)
379 ("darkgoldenrod1" 255 185 15)
380 ("darkgoldenrod2" 238 173 14)
381 ("darkgoldenrod3" 205 149 12)
382 ("darkgoldenrod4" 139 101 8)
383 ("rosybrown1" 255 193 193)
384 ("rosybrown2" 238 180 180)
385 ("rosybrown3" 205 155 155)
386 ("rosybrown4" 139 105 105)
387 ("indianred1" 255 106 106)
388 ("indianred2" 238 99 99)
389 ("indianred3" 205 85 85)
390 ("indianred4" 139 58 58)
391 ("sienna1" 255 130 71)
392 ("sienna2" 238 121 66)
393 ("sienna3" 205 104 57)
394 ("sienna4" 139 71 38)
395 ("burlywood1" 255 211 155)
396 ("burlywood2" 238 197 145)
397 ("burlywood3" 205 170 125)
398 ("burlywood4" 139 115 85)
399 ("wheat1" 255 231 186)
400 ("wheat2" 238 216 174)
401 ("wheat3" 205 186 150)
402 ("wheat4" 139 126 102)
403 ("tan1" 255 165 79)
404 ("tan2" 238 154 73)
405 ("tan3" 205 133 63)
406 ("tan4" 139 90 43)
407 ("chocolate1" 255 127 36)
408 ("chocolate2" 238 118 33)
409 ("chocolate3" 205 102 29)
410 ("chocolate4" 139 69 19)
411 ("firebrick1" 255 48 48)
412 ("firebrick2" 238 44 44)
413 ("firebrick3" 205 38 38)
414 ("firebrick4" 139 26 26)
415 ("brown1" 255 64 64)
416 ("brown2" 238 59 59)
417 ("brown3" 205 51 51)
418 ("brown4" 139 35 35)
419 ("salmon1" 255 140 105)
420 ("salmon2" 238 130 98)
421 ("salmon3" 205 112 84)
422 ("salmon4" 139 76 57)
423 ("lightsalmon1" 255 160 122)
424 ("lightsalmon2" 238 149 114)
425 ("lightsalmon3" 205 129 98)
426 ("lightsalmon4" 139 87 66)
427 ("orange1" 255 165 0)
428 ("orange2" 238 154 0)
429 ("orange3" 205 133 0)
430 ("orange4" 139 90 0)
431 ("darkorange1" 255 127 0)
432 ("darkorange2" 238 118 0)
433 ("darkorange3" 205 102 0)
434 ("darkorange4" 139 69 0)
435 ("coral1" 255 114 86)
436 ("coral2" 238 106 80)
437 ("coral3" 205 91 69)
438 ("coral4" 139 62 47)
439 ("tomato1" 255 99 71)
440 ("tomato2" 238 92 66)
441 ("tomato3" 205 79 57)
442 ("tomato4" 139 54 38)
443 ("orangered1" 255 69 0)
444 ("orangered2" 238 64 0)
445 ("orangered3" 205 55 0)
446 ("orangered4" 139 37 0)
447 ("red1" 255 0 0)
448 ("red2" 238 0 0)
449 ("red3" 205 0 0)
450 ("red4" 139 0 0)
451 ("deeppink1" 255 20 147)
452 ("deeppink2" 238 18 137)
453 ("deeppink3" 205 16 118)
454 ("deeppink4" 139 10 80)
455 ("hotpink1" 255 110 180)
456 ("hotpink2" 238 106 167)
457 ("hotpink3" 205 96 144)
458 ("hotpink4" 139 58 98)
459 ("pink1" 255 181 197)
460 ("pink2" 238 169 184)
461 ("pink3" 205 145 158)
462 ("pink4" 139 99 108)
463 ("lightpink1" 255 174 185)
464 ("lightpink2" 238 162 173)
465 ("lightpink3" 205 140 149)
466 ("lightpink4" 139 95 101)
467 ("palevioletred1" 255 130 171)
468 ("palevioletred2" 238 121 159)
469 ("palevioletred3" 205 104 137)
470 ("palevioletred4" 139 71 93)
471 ("maroon1" 255 52 179)
472 ("maroon2" 238 48 167)
473 ("maroon3" 205 41 144)
474 ("maroon4" 139 28 98)
475 ("violetred1" 255 62 150)
476 ("violetred2" 238 58 140)
477 ("violetred3" 205 50 120)
478 ("violetred4" 139 34 82)
479 ("magenta1" 255 0 255)
480 ("magenta2" 238 0 238)
481 ("magenta3" 205 0 205)
482 ("magenta4" 139 0 139)
483 ("orchid1" 255 131 250)
484 ("orchid2" 238 122 233)
485 ("orchid3" 205 105 201)
486 ("orchid4" 139 71 137)
487 ("plum1" 255 187 255)
488 ("plum2" 238 174 238)
489 ("plum3" 205 150 205)
490 ("plum4" 139 102 139)
491 ("mediumorchid1" 224 102 255)
492 ("mediumorchid2" 209 95 238)
493 ("mediumorchid3" 180 82 205)
494 ("mediumorchid4" 122 55 139)
495 ("darkorchid1" 191 62 255)
496 ("darkorchid2" 178 58 238)
497 ("darkorchid3" 154 50 205)
498 ("darkorchid4" 104 34 139)
499 ("purple1" 155 48 255)
500 ("purple2" 145 44 238)
501 ("purple3" 125 38 205)
502 ("purple4" 85 26 139)
503 ("mediumpurple1" 171 130 255)
504 ("mediumpurple2" 159 121 238)
505 ("mediumpurple3" 137 104 205)
506 ("mediumpurple4" 93 71 139)
507 ("thistle1" 255 225 255)
508 ("thistle2" 238 210 238)
509 ("thistle3" 205 181 205)
510 ("thistle4" 139 123 139)
511 ("gray0" 0 0 0)
512 ("grey0" 0 0 0)
513 ("gray1" 3 3 3)
514 ("grey1" 3 3 3)
515 ("gray2" 5 5 5)
516 ("grey2" 5 5 5)
517 ("gray3" 8 8 8)
518 ("grey3" 8 8 8)
519 ("gray4" 10 10 10)
520 ("grey4" 10 10 10)
521 ("gray5" 13 13 13)
522 ("grey5" 13 13 13)
523 ("gray6" 15 15 15)
524 ("grey6" 15 15 15)
525 ("gray7" 18 18 18)
526 ("grey7" 18 18 18)
527 ("gray8" 20 20 20)
528 ("grey8" 20 20 20)
529 ("gray9" 23 23 23)
530 ("grey9" 23 23 23)
531 ("gray10" 26 26 26)
532 ("grey10" 26 26 26)
533 ("gray11" 28 28 28)
534 ("grey11" 28 28 28)
535 ("gray12" 31 31 31)
536 ("grey12" 31 31 31)
537 ("gray13" 33 33 33)
538 ("grey13" 33 33 33)
539 ("gray14" 36 36 36)
540 ("grey14" 36 36 36)
541 ("gray15" 38 38 38)
542 ("grey15" 38 38 38)
543 ("gray16" 41 41 41)
544 ("grey16" 41 41 41)
545 ("gray17" 43 43 43)
546 ("grey17" 43 43 43)
547 ("gray18" 46 46 46)
548 ("grey18" 46 46 46)
549 ("gray19" 48 48 48)
550 ("grey19" 48 48 48)
551 ("gray20" 51 51 51)
552 ("grey20" 51 51 51)
553 ("gray21" 54 54 54)
554 ("grey21" 54 54 54)
555 ("gray22" 56 56 56)
556 ("grey22" 56 56 56)
557 ("gray23" 59 59 59)
558 ("grey23" 59 59 59)
559 ("gray24" 61 61 61)
560 ("grey24" 61 61 61)
561 ("gray25" 64 64 64)
562 ("grey25" 64 64 64)
563 ("gray26" 66 66 66)
564 ("grey26" 66 66 66)
565 ("gray27" 69 69 69)
566 ("grey27" 69 69 69)
567 ("gray28" 71 71 71)
568 ("grey28" 71 71 71)
569 ("gray29" 74 74 74)
570 ("grey29" 74 74 74)
571 ("gray30" 77 77 77)
572 ("grey30" 77 77 77)
573 ("gray31" 79 79 79)
574 ("grey31" 79 79 79)
575 ("gray32" 82 82 82)
576 ("grey32" 82 82 82)
577 ("gray33" 84 84 84)
578 ("grey33" 84 84 84)
579 ("gray34" 87 87 87)
580 ("grey34" 87 87 87)
581 ("gray35" 89 89 89)
582 ("grey35" 89 89 89)
583 ("gray36" 92 92 92)
584 ("grey36" 92 92 92)
585 ("gray37" 94 94 94)
586 ("grey37" 94 94 94)
587 ("gray38" 97 97 97)
588 ("grey38" 97 97 97)
589 ("gray39" 99 99 99)
590 ("grey39" 99 99 99)
591 ("gray40" 102 102 102)
592 ("grey40" 102 102 102)
593 ("gray41" 105 105 105)
594 ("grey41" 105 105 105)
595 ("gray42" 107 107 107)
596 ("grey42" 107 107 107)
597 ("gray43" 110 110 110)
598 ("grey43" 110 110 110)
599 ("gray44" 112 112 112)
600 ("grey44" 112 112 112)
601 ("gray45" 115 115 115)
602 ("grey45" 115 115 115)
603 ("gray46" 117 117 117)
604 ("grey46" 117 117 117)
605 ("gray47" 120 120 120)
606 ("grey47" 120 120 120)
607 ("gray48" 122 122 122)
608 ("grey48" 122 122 122)
609 ("gray49" 125 125 125)
610 ("grey49" 125 125 125)
611 ("gray50" 127 127 127)
612 ("grey50" 127 127 127)
613 ("gray51" 130 130 130)
614 ("grey51" 130 130 130)
615 ("gray52" 133 133 133)
616 ("grey52" 133 133 133)
617 ("gray53" 135 135 135)
618 ("grey53" 135 135 135)
619 ("gray54" 138 138 138)
620 ("grey54" 138 138 138)
621 ("gray55" 140 140 140)
622 ("grey55" 140 140 140)
623 ("gray56" 143 143 143)
624 ("grey56" 143 143 143)
625 ("gray57" 145 145 145)
626 ("grey57" 145 145 145)
627 ("gray58" 148 148 148)
628 ("grey58" 148 148 148)
629 ("gray59" 150 150 150)
630 ("grey59" 150 150 150)
631 ("gray60" 153 153 153)
632 ("grey60" 153 153 153)
633 ("gray61" 156 156 156)
634 ("grey61" 156 156 156)
635 ("gray62" 158 158 158)
636 ("grey62" 158 158 158)
637 ("gray63" 161 161 161)
638 ("grey63" 161 161 161)
639 ("gray64" 163 163 163)
640 ("grey64" 163 163 163)
641 ("gray65" 166 166 166)
642 ("grey65" 166 166 166)
643 ("gray66" 168 168 168)
644 ("grey66" 168 168 168)
645 ("gray67" 171 171 171)
646 ("grey67" 171 171 171)
647 ("gray68" 173 173 173)
648 ("grey68" 173 173 173)
649 ("gray69" 176 176 176)
650 ("grey69" 176 176 176)
651 ("gray70" 179 179 179)
652 ("grey70" 179 179 179)
653 ("gray71" 181 181 181)
654 ("grey71" 181 181 181)
655 ("gray72" 184 184 184)
656 ("grey72" 184 184 184)
657 ("gray73" 186 186 186)
658 ("grey73" 186 186 186)
659 ("gray74" 189 189 189)
660 ("grey74" 189 189 189)
661 ("gray75" 191 191 191)
662 ("grey75" 191 191 191)
663 ("gray76" 194 194 194)
664 ("grey76" 194 194 194)
665 ("gray77" 196 196 196)
666 ("grey77" 196 196 196)
667 ("gray78" 199 199 199)
668 ("grey78" 199 199 199)
669 ("gray79" 201 201 201)
670 ("grey79" 201 201 201)
671 ("gray80" 204 204 204)
672 ("grey80" 204 204 204)
673 ("gray81" 207 207 207)
674 ("grey81" 207 207 207)
675 ("gray82" 209 209 209)
676 ("grey82" 209 209 209)
677 ("gray83" 212 212 212)
678 ("grey83" 212 212 212)
679 ("gray84" 214 214 214)
680 ("grey84" 214 214 214)
681 ("gray85" 217 217 217)
682 ("grey85" 217 217 217)
683 ("gray86" 219 219 219)
684 ("grey86" 219 219 219)
685 ("gray87" 222 222 222)
686 ("grey87" 222 222 222)
687 ("gray88" 224 224 224)
688 ("grey88" 224 224 224)
689 ("gray89" 227 227 227)
690 ("grey89" 227 227 227)
691 ("gray90" 229 229 229)
692 ("grey90" 229 229 229)
693 ("gray91" 232 232 232)
694 ("grey91" 232 232 232)
695 ("gray92" 235 235 235)
696 ("grey92" 235 235 235)
697 ("gray93" 237 237 237)
698 ("grey93" 237 237 237)
699 ("gray94" 240 240 240)
700 ("grey94" 240 240 240)
701 ("gray95" 242 242 242)
702 ("grey95" 242 242 242)
703 ("gray96" 245 245 245)
704 ("grey96" 245 245 245)
705 ("gray97" 247 247 247)
706 ("grey97" 247 247 247)
707 ("gray98" 250 250 250)
708 ("grey98" 250 250 250)
709 ("gray99" 252 252 252)
710 ("grey99" 252 252 252)
711 ("gray100" 255 255 255)
712 ("grey100" 255 255 255)
713 ("darkgrey" 169 169 169)
714 ("darkgray" 169 169 169)
715 ("darkblue" 0 0 139)
716 ("darkcyan" 0 139 139)
717 ("darkmagenta" 139 0 139)
718 ("darkred" 139 0 0)
719 ("lightgreen" 144 238 144))
720 "An alist of X color names and associated 8-bit RGB values.")
721
722(defvar tty-standard-colors
723 '(("white" 7 65535 65535 65535)
724 ("cyan" 6 0 65535 65535)
725 ("magenta" 5 65535 0 65535)
726 ("blue" 4 0 0 65535)
727 ("yellow" 3 65535 65535 0)
728 ("green" 2 0 65535 0)
729 ("red" 1 65535 0 0)
730 ("black" 0 0 0 0))
731 "An alist of 8 standard tty colors, their indices and RGB values.")
732
733(defvar tty-color-alist nil
734 "An alist of colors supported by the terminal.
735Each element is of the form:
736 \(NAME INDEX R G B\)
737where NAME is the name of the color, a string;
738INDEX is the index of this color to be sent to the terminal driver
739when the color should be displayed; it is typically a small integer;
740R, G, and B are the intensities of, accordingly, red, green, and blue
741components of the color, represented as numbers between 0 and 65535.
742The file `etc/rgb.txt' in the Emacs distribution lists the standard
743RGB values of the X colors. If RGB is nil, this color will not be
744considered by `tty-color-translate' as an approximation to another
745color.")
746
747(defun tty-color-canonicalize (color)
748 "Return COLOR in canonical form.
749A canonicalized color name is all-lower case, with any blanks removed."
750 (let ((color (downcase color)))
751 (while (string-match " +" color)
752 (setq color (replace-match "" nil nil color)))
753 color))
754
755(defun tty-color-define (name index &optional rgb)
756 "Specify a tty color by its NAME, terminal INDEX and RGB values.
757NAME is a string, INDEX is typically a small integer used to send to
758the terminal driver to switch on this color, and RGB is a list of 3
759numbers that specify the intensity of red, green, and blue components
760of the color.
761If specified, each one of the RGB components must be a number between
7620 and 65535. If RGB is omitted, the specified color will never be used
763by `tty-color-translate' as an approximation to another color."
764 (if (or (not (stringp name))
765 (not (integerp index))
766 (and rgb (or (not (listp rgb)) (/= (length rgb) 3))))
767 (error "Invalid specification for tty color \"%s\"" name))
768 (let* ((name (tty-color-canonicalize name))
769 (entry (assoc name tty-color-alist)))
770 (if entry
771 (setcdr entry (cons index rgb))
772 (setq tty-color-alist
773 (cons (append (list name index) rgb) tty-color-alist)))
774 tty-color-alist))
775
776(defun tty-color-clear ()
777 "Clear the list of supported tty colors."
778 (setq tty-color-alist nil))
779
780(defun tty-color-off-gray-diag (r g b)
781 "Compute the angle between the color given by R,G,B and the gray diagonal."
782 (let ((mag (sqrt (* 3 (+ (* r r) (* g g) (* b b))))))
783 (if (< mag 1) 0 (acos (/ (+ r g b) mag)))))
784
785(defun tty-color-approximate (rgb)
786 "Given a list of 3 rgb values in RGB, find the color in `tty-color-alist'
787which is the best approximation in the 3-dimensional RGB space,
788and return the index associated with the approximating color.
789Each value of the RGB triplet has to be scaled to the 0..255 range."
790 (let* ((color-list tty-color-alist)
791 (candidate (car color-list))
792 (best-distance 195076) ;; 3 * 255^2 + 15
793 best-color)
794 (while candidate
795 (let* ((try-rgb (cddr candidate))
796 (r (car rgb))
797 (g (cadr rgb))
798 (b (nth 2 rgb))
799 ;; If the approximated color is not close enough to the
800 ;; gray diagonal of the RGB cube, favor non-gray colors.
801 ;; (The number 0.065 is an empirical ad-hoc'ery.)
802 (favor-non-gray (>= (tty-color-off-gray-diag r g b) 0.065))
803 try-r try-g try-b
804 dif-r dif-g dif-b dist)
805 ;; If the RGB values of the candidate color are unknown, we
806 ;; never consider it for approximating another color.
807 (if try-rgb
808 (progn
809 (setq try-r (lsh (car try-rgb) -8)
810 try-g (lsh (cadr try-rgb) -8)
811 try-b (lsh (nth 2 try-rgb) -8))
812 (setq dif-r (- (car rgb) try-r)
813 dif-g (- (cadr rgb) try-g)
814 dif-b (- (nth 2 rgb) try-b))
815 (setq dist (+ (* dif-r dif-r) (* dif-g dif-g) (* dif-b dif-b)))
816 (if (and (< dist best-distance)
817 ;; The candidate color is on the gray diagonal
818 ;; if its RGB components are all equal.
819 (or (/= try-r try-g) (/= try-g try-b)
820 (not favor-non-gray)))
821 (setq best-distance dist
822 best-color candidate)))))
823 (setq color-list (cdr color-list))
824 (setq candidate (car color-list)))
825 (cadr best-color)))
826
827(defun tty-color-translate (color)
828 "Given a color COLOR, return the index of the corresponding TTY color.
829COLOR must be a string that is either the color's name, or its X-style
830specification like \"#RRGGBB\" or \"RGB:rr/gg/bb\", where each primary.
831color can be given with 1 to 4 hex digits.
832If COLOR is a color name that is found among supported colors in
833`tty-color-alist', the associated index is returned. Otherwise, the
834RGB values of the color, either as given by the argument or from
835looking up the name in `color-name-rgb-alist', are used to find the
836supported color that is the best approximation for COLOR in the RGB
837space.
838If COLOR is neither a valid X RGB specification of the color, nor a
839name of a color in `color-name-rgb-alist', the returned value is nil."
840 (and (stringp color)
841 (let* ((color (tty-color-canonicalize color))
842 (idx (cadr (assoc color tty-color-alist))))
843 (or idx
844 (let* ((len (length color))
845 (maxval 256)
846 (rgb
847 (cond
848 ((and (>= len 4) ;; X-style "#XXYYZZ" color spec
849 (eq (aref color 0) ?#)
850 (member (aref color 1)
851 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9
852 ?a ?b ?c ?d ?e ?f)))
853 ;; Translate the string "#XXYYZZ" into a list
854 ;; of numbers (XX YY ZZ). If the primary colors
855 ;; are specified with less than 4 hex digits,
856 ;; the used digits represent the most significant
857 ;; bits of the value (e.g. #XYZ = #X000Y000Z000).
858 (let* ((ndig (/ (- len 1) 3))
859 (i1 1)
860 (i2 (+ i1 ndig))
861 (i3 (+ i2 ndig)))
862 (list
863 (lsh
864 (string-to-number (substring color i1 i2) 16)
865 (* 4 (- 2 ndig)))
866 (lsh
867 (string-to-number (substring color i2 i3) 16)
868 (* 4 (- 2 ndig)))
869 (lsh
870 (string-to-number (substring color i3) 16)
871 (* 4 (- 2 ndig))))))
872 ((and (>= len 9) ;; X-style RGB:xx/yy/zz color spec
873 (string= (substring color 0 4) "rgb:"))
874 ;; Translate the string "RGB:XX/YY/ZZ" into a list
875 ;; of numbers (XX YY ZZ). If fewer than 4 hex
876 ;; digits are used, they represent the fraction
877 ;; of the maximum value (RGB:X/Y/Z = #XXXXYYYYZZZZ).
878 (let* ((ndig (/ (- len 3) 3))
879 (maxval (1- (expt 16 (- ndig 1))))
880 (i1 4)
881 (i2 (+ i1 ndig))
882 (i3 (+ i2 ndig)))
883 (list
884 (/ (* (string-to-number
885 (substring color i1 (- i2 1)) 16)
886 255)
887 maxval)
888 (/ (* (string-to-number
889 (substring color i2 (- i3 1)) 16)
890 255)
891 maxval)
892 (/ (* (string-to-number
893 (substring color i3) 16)
894 255)
895 maxval))))
896 (t
897 (cdr (assoc color color-name-rgb-alist))))))
898 (and rgb (tty-color-approximate rgb)))))))
899
900(defun tty-color-by-index (idx)
901 "Given a numeric index of a tty color, return its description.
902Value is a list of the form \(NAME INDEX R G B\)."
903 (and idx
904 (let ((colors tty-color-alist)
905 desc found)
906 (while colors
907 (setq desc (car colors))
908 (if (eq idx (car (cdr desc)))
909 (setq found desc))
910 (setq colors (cdr colors)))
911 found)))
912
913(defun tty-color-values (color &optional frame)
914 "Return RGB values of the color COLOR on a termcap frame FRAME.
915If COLOR is not directly supported by the display, return the RGB
916values for a supported color that is its best approximation.
917The value is a list of integer RGB values--\(RED GREEN BLUE\).
918These values range from 0 to 65535; white is (65535 65535 65535).
919If FRAME is omitted or nil, use the selected frame."
920 (let* ((frame (or frame (selected-frame)))
921 (color (tty-color-canonicalize color))
922 (supported (assoc color tty-color-alist)))
923 (or (and supported (cddr supported)) ; full spec in tty-color-alist
924 (and supported ; no RGB values in tty-color-alist: use X RGB values
925 (assoc color color-name-rgb-alist)
926 (cddr
927 (tty-color-by-index
928 (tty-color-approximate
929 (cdr (assoc color color-name-rgb-alist))))))
930 (cddr (tty-color-by-index (tty-color-translate color))))))
931
932(defun tty-color-desc (color)
933 "Return the description of the color COLOR for a character terminal.
934Value is a list of the form \(NAME INDEX R G B\). Note that the returned
935NAME is not necessarily the same string as the argument COLOR, because
936the latter might need to be approximated if it is not supported directly."
937 (let ((idx (tty-color-translate color)))
938 (tty-color-by-index idx)))
diff --git a/lisp/term/w32-win.el b/lisp/term/w32-win.el
index a46f2334e9e..5bff6c11117 100644
--- a/lisp/term/w32-win.el
+++ b/lisp/term/w32-win.el
@@ -517,10 +517,8 @@ This returns ARGS with the arguments that have been processed removed."
517 "GreenYellow") 517 "GreenYellow")
518 "The full list of X colors from the `rgb.text' file.") 518 "The full list of X colors from the `rgb.text' file.")
519 519
520(defun x-defined-colors (&optional frame) 520(defun xw-defined-colors (&optional frame)
521 "Return a list of colors supported for a particular frame. 521 "Internal function called by `defined-colors', which see."
522The argument FRAME specifies which frame to try.
523The value may be different for frames on different X displays."
524 (or frame (setq frame (selected-frame))) 522 (or frame (setq frame (selected-frame)))
525 (let* ((color-map-colors (mapcar (lambda (clr) (car clr)) w32-color-map)) 523 (let* ((color-map-colors (mapcar (lambda (clr) (car clr)) w32-color-map))
526 (all-colors (or color-map-colors x-colors)) 524 (all-colors (or color-map-colors x-colors))
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el
index 032b6f32e89..6b13f14cbb8 100644
--- a/lisp/term/x-win.el
+++ b/lisp/term/x-win.el
@@ -428,10 +428,8 @@ This function returns ARGS minus the arguments that have been processed."
428 "GreenYellow") 428 "GreenYellow")
429 "The list of X colors from the `rgb.txt' file.") 429 "The list of X colors from the `rgb.txt' file.")
430 430
431(defun x-defined-colors (&optional frame) 431(defun xw-defined-colors (&optional frame)
432 "Return a list of colors supported for a particular frame. 432 "Internal function called by `defined-colors', which see."
433The argument FRAME specifies which frame to try.
434The value may be different for frames on different X displays."
435 (or frame (setq frame (selected-frame))) 433 (or frame (setq frame (selected-frame)))
436 (let ((all-colors x-colors) 434 (let ((all-colors x-colors)
437 (this-color nil) 435 (this-color nil)