diff lisp/faces.el @ 26736:a0674327c167

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.
author Eli Zaretskii <eliz@gnu.org>
date Mon, 06 Dec 1999 17:55:00 +0000
parents b5c0d55411ad
children 264b83a3a688
line wrap: on
line diff
--- a/lisp/faces.el	Mon Dec 06 17:52:27 1999 +0000
+++ b/lisp/faces.el	Mon Dec 06 17:55:00 1999 +0000
@@ -758,8 +758,7 @@
 		       (internal-lisp-face-attribute-values attribute))))
 	    ((:foreground :background)
 	     (mapcar #'(lambda (c) (cons c c))
-		     (or (and window-system (x-defined-colors frame))
-			 (tty-defined-colors))))
+		     (defined-colors frame)))
 	    ((:height)
 	     'integerp)
 	    (:stipple
@@ -858,6 +857,13 @@
     (cond ((listp valid)
 	   (setq new-value
 		 (face-read-string face old-value attribute-name valid))
+	   ;; Terminal frames can support colors that don't appear
+	   ;; explicitly in VALID, using color approximation code
+	   ;; in tty-colors.el.
+	   (if (and (memq attribute '(:foreground :background))
+		    (not (memq window-system '(x w32 mac)))
+		    (not (eq new-value 'unspecified)))
+	       (setq new-value (car (tty-color-desc new-value))))
 	   (unless (eq new-value 'unspecified)
 	     (setq new-value (cdr (assoc new-value valid)))))
 	  ((eq valid 'integerp)
@@ -1141,6 +1147,60 @@
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Frame-type independent color support.
+;;; We keep the old x-* names as aliases for back-compatibility.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(defun defined-colors (&optional frame)
+  "Return a list of colors supported for a particular frame.
+The argument FRAME specifies which frame to try.
+The value may be different for frames on different display types.
+If FRAME doesn't support colors, the value is nil."
+  (if (memq (framep (or frame (selected-frame))) '(x w32))
+      (xw-defined-colors frame)
+    (mapcar 'car tty-color-alist)))
+(defalias 'x-defined-colors 'defined-colors)
+
+(defun color-defined-p (color &optional frame)
+  "Return non-nil if color COLOR is supported on frame FRAME.
+If FRAME is omitted or nil, use the selected frame.
+If COLOR is the symbol `unspecified', the value is nil."
+  (if (eq color 'unspecified)
+      nil
+    (if (memq (framep (or frame (selected-frame))) '(x w32))
+	(xw-color-defined-p color frame)
+      (numberp (tty-color-translate color)))))
+(defalias 'x-color-defined-p 'color-defined-p)
+
+(defun color-values (color &optional frame)
+  "Return a description of the color named COLOR on frame FRAME.
+The value is a list of integer RGB values--\(RED GREEN BLUE\).
+These values appear to range from 0 to 65280 or 65535, depending
+on the system; white is \(65280 65280 65280\) or \(65535 65535 65535\).
+If FRAME is omitted or nil, use the selected frame.
+If FRAME cannot display COLOR, the value is nil.
+If COLOR is the symbol `unspecified', the value is nil."
+  (if (eq color 'unspecified)
+      nil
+    (if (memq (framep (or frame (selected-frame))) '(x w32))
+	(xw-color-values color frame)
+      (tty-color-values color frame))))
+(defalias 'x-color-values 'color-values)
+
+(defun display-color-p (&optional display)
+  "Return t if DISPLAY supports color.
+The optional argument DISPLAY specifies which display to ask about.
+DISPLAY should be either a frame or a display name (a string).
+If omitted or nil, that stands for the selected frame's display."
+  (if (and (stringp display) (not (fboundp 'x-display-list)))
+      nil
+    (if (memq (framep (or display (selected-frame))) '(x w32))
+	(xw-display-color-p display)
+      (tty-display-color-p))))
+(defalias 'x-display-color-p 'display-color-p)
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Background mode.
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;