• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10/emacs-93/emacs/lisp/term/

Lines Matching +defs:color +defs:name

1 ;;; tty-colors.el --- color support for character terminals
29 ;; Emacs support for colors evolved from the X Window System; color
31 ;; packages use color names defined by X and assume the availability
35 ;; This file provides a more or less useful emulation of the X color
40 ;; maintains an alist, called `tty-defined-color-alist', which
43 ;; functions which set the color, and are effectively indices of the
44 ;; colors in the supported color palette.) When Emacs needs to send a
45 ;; color command to the terminal, the color name is first looked up in
46 ;; `tty-defined-color-alist'. If not found, functions from this file
47 ;; can be used to map the color to one of the supported colors.
48 ;; Specifically, the X RGB values of the requested color are extracted
49 ;; from `color-name-rgb-alist' and then the supported color is found
51 ;; color.
53 ;; `tty-defined-color-alist' is created at startup by calling the
54 ;; function `tty-color-define', defined below, passing it each
55 ;; supported color, its index, and its RGB values. The standard list
56 ;; of colors supported by many Unix color terminals, including xterm,
59 ;; `tty-color-define' from your `.emacs' or `site-start.el'. For
65 (defvar msdos-color-values)
76 ;; same color. A similar situation exists with other "light*" colors.
78 ;; Nevertheless, "lightred" and other similar color names *are*
82 ;; For these reasons, package maintaners are advised NOT to use color
91 (defvar color-name-rgb-alist
749 "An alist of X color names and associated 16-bit RGB values.")
763 (defvar tty-color-mode-alist
771 "An alist of supported standard tty color modes and their aliases.")
773 (defvar tty-defined-color-alist nil
776 See the docstring of `tty-color-alist' for the details.")
778 (defun tty-color-alist (&optional frame)
783 where NAME is the name of the color, a string;
784 INDEX is the index of this color to be sent to the terminal driver
785 when the color should be displayed; it is typically a small integer;
787 components of the color, represented as numbers between 0 and 65535.
789 RGB values of the X colors. If RGB is nil, this color will not be
790 considered by `tty-color-translate' as an approximation to another
791 color."
792 tty-defined-color-alist)
794 (defun tty-modify-color-alist (elt &optional frame)
796 ELT should be of the form \(NAME INDEX R G B\) (see `tty-color-alist'
798 If the association for NAME already exists in the color alist, it is
800 appended to the end of the color alist.
802 Value is the modified color alist for FRAME."
803 (let* ((entry (assoc (car elt) (tty-color-alist frame))))
811 (setq tty-defined-color-alist (nconc tty-defined-color-alist entry)))
812 tty-defined-color-alist))
817 msdos-color-values)
821 (color (car colors)))
823 (tty-color-define (car color) (cadr color) (cddr color))
824 (setq colors (cdr colors) color (car colors)))
825 ;; Modifying color mappings means realized faces don't
829 (defun tty-color-canonicalize (color)
831 A canonicalized color name is all-lower case, with any blanks removed."
833 (if (string-match "[A-Z ]" color)
834 (replace-regexp-in-string " +" "" (downcase color))
835 color)))
837 (defun tty-color-define (name index &optional rgb frame)
838 "Specify a tty color by its NAME, terminal INDEX and RGB values.
840 the terminal driver a command to switch this color on, and RGB is a
842 components of the color.
844 0 and 65535. If RGB is omitted, the specified color will never be used
845 by `tty-color-translate' as an approximation to another color.
846 FRAME is the frame where the defined color should be used.
848 (if (or (not (stringp name))
851 (error "Invalid specification for tty color \"%s\"" name))
852 (tty-modify-color-alist
853 (append (list (tty-color-canonicalize name) index) rgb) frame))
855 (defun tty-color-clear (&optional frame)
858 (setq tty-defined-color-alist nil))
860 (defun tty-color-off-gray-diag (r g b)
861 "Compute the angle between the color given by R,G,B and the gray diagonal.
865 of gray, thus the name."
869 (defun tty-color-approximate (rgb &optional frame)
870 "Find the color in `tty-color-alist' that best approximates RGB.
875 (let* ((color-list (tty-color-alist frame))
876 (candidate (car color-list))
881 best-color)
884 ;; If the approximated color is not close enough to the
887 (favor-non-gray (>= (tty-color-off-gray-diag r g b) 0.065))
890 ;; If the RGB values of the candidate color are unknown, we
891 ;; never consider it for approximating another color.
902 ;; The candidate color is on the gray diagonal
907 best-color candidate)))))
908 (setq color-list (cdr color-list))
909 (setq candidate (car color-list)))
910 best-color))
912 (defun tty-color-standard-values (color)
913 "Return standard RGB values of the color COLOR.
921 (let ((len (length color)))
922 (cond ((and (>= len 4) ;; X-style "#XXYYZZ" color spec
923 (eq (aref color 0) ?#)
924 (member (aref color 1)
938 (string-to-number (substring color i1 i2) 16)
941 (string-to-number (substring color i2 i3) 16)
944 (string-to-number (substring color i3) 16)
946 ((and (>= len 9) ;; X-style RGB:xx/yy/zz color spec
947 (string= (substring color 0 4) "rgb:"))
959 (substring color i1 (- i2 1)) 16)
963 (substring color i2 (- i3 1)) 16)
967 (substring color i3) 16)
971 (cdr (assoc color color-name-rgb-alist))))))
973 (defun tty-color-translate (color &optional frame)
974 "Given a color COLOR, return the index of the corresponding TTY color.
976 COLOR must be a string that is either the color's name, or its X-style
978 color can be given with 1 to 4 hex digits.
980 If COLOR is a color name that is found among supported colors in
981 `tty-color-alist', the associated index is returned. Otherwise, the
982 RGB values of the color, either as given by the argument or from
983 looking up the name in `color-name-rgb-alist', are used to find the
984 supported color that is the best approximation for COLOR in the RGB
986 If COLOR is neither a valid X RGB specification of the color, nor a
987 name of a color in `color-name-rgb-alist', the returned value is nil.
990 (cadr (tty-color-desc color frame)))
992 (defun tty-color-by-index (idx &optional frame)
993 "Given a numeric index of a tty color, return its description.
998 (let ((colors (tty-color-alist frame))
1007 (defun tty-color-values (color &optional frame)
1008 "Return RGB values of the color COLOR on a termcap frame FRAME.
1011 values for a supported color that is its best approximation.
1015 (cddr (tty-color-desc color frame)))
1017 (defun tty-color-desc (color &optional frame)
1018 "Return the description of the color COLOR for a character terminal.
1022 (and (stringp color)
1023 (let ((color (tty-color-canonicalize color)))
1024 (or (assoc color (tty-color-alist frame))
1025 (let ((rgb (tty-color-standard-values color)))
1026 (and rgb (tty-color-approximate rgb frame)))))))
1028 (defun tty-color-gray-shades (&optional display)
1030 A color is considered gray if the 3 components of its RGB value are equal."
1034 (colors (tty-color-alist frame))