aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/term
diff options
context:
space:
mode:
authorPip Cet2019-07-22 02:40:35 +0000
committerEli Zaretskii2019-07-27 14:05:46 +0300
commit357399014acacc75bd1825fb2f498f1a4be7b362 (patch)
treefbbfbca7fed181b564f5814c6941297e6f5f0372 /lisp/term
parente310843d9dc106187d0e45ef7f0b9cd90a881eec (diff)
downloademacs-357399014acacc75bd1825fb2f498f1a4be7b362.tar.gz
emacs-357399014acacc75bd1825fb2f498f1a4be7b362.zip
Use the CSS convention for #RGB colors (bug#36304)
* src/xterm.c (x_parse_color): Change interpretation of #RGB color triplets to match CSS rather than X conventions. * lisp/term/tty-colors.el (tty-color-standard-values): Change interpretation of #RGB color triplets to match CSS rather than X conventions. Allow upper-case digits. Fix rgb:R/G/B interpretation. * doc/emacs/display.texi (Colors): Specify the convention used for "#RGB" color triplets. * test/lisp/tty-colors-tests.el: New file. * etc/NEWS: Mention the change.
Diffstat (limited to 'lisp/term')
-rw-r--r--lisp/term/tty-colors.el74
1 files changed, 40 insertions, 34 deletions
diff --git a/lisp/term/tty-colors.el b/lisp/term/tty-colors.el
index 5af8170203e..43c1071ceb7 100644
--- a/lisp/term/tty-colors.el
+++ b/lisp/term/tty-colors.el
@@ -919,57 +919,63 @@ FRAME defaults to the selected frame."
919The result is a list of integer RGB values--(RED GREEN BLUE). 919The result is a list of integer RGB values--(RED GREEN BLUE).
920These values range from 0 to 65535; white is (65535 65535 65535). 920These values range from 0 to 65535; white is (65535 65535 65535).
921 921
922The returned value reflects the standard X definition of COLOR, 922The returned value reflects the standard Emacs definition of
923regardless of whether the terminal can display it, so the return value 923COLOR (see the info node `(emacs) Colors'), regardless of whether
924should be the same regardless of what display is being used." 924the terminal can display it, so the return value should be the
925same regardless of what display is being used."
925 (let ((len (length color))) 926 (let ((len (length color)))
926 (cond ((and (>= len 4) ;; X-style "#XXYYZZ" color spec 927 (cond ((and (>= len 4) ;; HTML/CSS/SVG-style "#XXYYZZ" color spec
927 (eq (aref color 0) ?#) 928 (eq (aref color 0) ?#)
928 (member (aref color 1) 929 (member (aref color 1)
929 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9 930 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9
930 ?a ?b ?c ?d ?e ?f))) 931 ?a ?b ?c ?d ?e ?f
931 ;; Translate the string "#XXYYZZ" into a list 932 ?A ?B ?C ?D ?E ?F)))
932 ;; of numbers (XX YY ZZ). If the primary colors 933 ;; Translate the string "#XXYYZZ" into a list of numbers
933 ;; are specified with less than 4 hex digits, 934 ;; (XX YY ZZ), scaling each to the {0..65535} range. This
934 ;; the used digits represent the most significant 935 ;; follows the HTML color convention, where both "#fff" and
935 ;; bits of the value (e.g. #XYZ = #X000Y000Z000). 936 ;; "#ffffff" represent the same color, white.
936 (let* ((ndig (/ (- len 1) 3)) 937 (let* ((ndig (/ (- len 1) 3))
938 (maxval (1- (ash 1 (* 4 ndig))))
937 (i1 1) 939 (i1 1)
938 (i2 (+ i1 ndig)) 940 (i2 (+ i1 ndig))
939 (i3 (+ i2 ndig))) 941 (i3 (+ i2 ndig))
942 (i4 (+ i3 ndig)))
940 (list 943 (list
941 (ash 944 (/ (* (string-to-number
942 (string-to-number (substring color i1 i2) 16) 945 (substring color i1 i2) 16)
943 (* 4 (- 4 ndig))) 946 65535)
944 (ash 947 maxval)
945 (string-to-number (substring color i2 i3) 16) 948 (/ (* (string-to-number
946 (* 4 (- 4 ndig))) 949 (substring color i2 i3) 16)
947 (ash 950 65535)
948 (string-to-number (substring color i3) 16) 951 maxval)
949 (* 4 (- 4 ndig)))))) 952 (/ (* (string-to-number
950 ((and (>= len 9) ;; X-style RGB:xx/yy/zz color spec 953 (substring color i3 i4) 16)
954 65535)
955 maxval))))
956 ((and (>= len 9) ;; X-style rgb:xx/yy/zz color spec
951 (string= (substring color 0 4) "rgb:")) 957 (string= (substring color 0 4) "rgb:"))
952 ;; Translate the string "RGB:XX/YY/ZZ" into a list 958 ;; Translate the string "rgb:XX/YY/ZZ" into a list of
953 ;; of numbers (XX YY ZZ). If fewer than 4 hex 959 ;; numbers (XX YY ZZ), scaling each to the {0..65535}
954 ;; digits are used, they represent the fraction 960 ;; range. "rgb:F/F/F" is white.
955 ;; of the maximum value (RGB:X/Y/Z = #XXXXYYYYZZZZ).
956 (let* ((ndig (/ (- len 3) 3)) 961 (let* ((ndig (/ (- len 3) 3))
957 (maxval (1- (ash 1 (* 4 (- ndig 1))))) 962 (maxval (1- (ash 1 (* 4 (- ndig 1)))))
958 (i1 4) 963 (i1 4)
959 (i2 (+ i1 ndig)) 964 (i2 (+ i1 ndig))
960 (i3 (+ i2 ndig))) 965 (i3 (+ i2 ndig))
966 (i4 (+ i3 ndig)))
961 (list 967 (list
962 (/ (* (string-to-number 968 (/ (* (string-to-number
963 (substring color i1 (- i2 1)) 16) 969 (substring color i1 (- i2 1)) 16)
964 255) 970 65535)
965 maxval) 971 maxval)
966 (/ (* (string-to-number 972 (/ (* (string-to-number
967 (substring color i2 (- i3 1)) 16) 973 (substring color i2 (- i3 1)) 16)
968 255) 974 65535)
969 maxval) 975 maxval)
970 (/ (* (string-to-number 976 (/ (* (string-to-number
971 (substring color i3) 16) 977 (substring color i3 (1- i4)) 16)
972 255) 978 65535)
973 maxval)))) 979 maxval))))
974 (t 980 (t
975 (cdr (assoc color color-name-rgb-alist)))))) 981 (cdr (assoc color color-name-rgb-alist))))))
@@ -977,9 +983,9 @@ should be the same regardless of what display is being used."
977(defun tty-color-translate (color &optional frame) 983(defun tty-color-translate (color &optional frame)
978 "Given a color COLOR, return the index of the corresponding TTY color. 984 "Given a color COLOR, return the index of the corresponding TTY color.
979 985
980COLOR must be a string that is either the color's name, or its X-style 986COLOR must be a string that is either the color's name, or its
981specification like \"#RRGGBB\" or \"RGB:rr/gg/bb\", where each primary. 987color triplet specification like \"#RRGGBB\" or \"rgb:RR/GG/BB\",
982color can be given with 1 to 4 hex digits. 988where each primary color can be given with 1 to 4 hex digits.
983 989
984If COLOR is a color name that is found among supported colors in 990If COLOR is a color name that is found among supported colors in
985`tty-color-alist', the associated index is returned. Otherwise, the 991`tty-color-alist', the associated index is returned. Otherwise, the
@@ -987,7 +993,7 @@ RGB values of the color, either as given by the argument or from
987looking up the name in `color-name-rgb-alist', are used to find the 993looking up the name in `color-name-rgb-alist', are used to find the
988supported color that is the best approximation for COLOR in the RGB 994supported color that is the best approximation for COLOR in the RGB
989space. 995space.
990If COLOR is neither a valid X RGB specification of the color, nor a 996If COLOR is neither a valid RGB specification of the color, nor a
991name of a color in `color-name-rgb-alist', the returned value is nil. 997name of a color in `color-name-rgb-alist', the returned value is nil.
992 998
993If FRAME is unspecified or nil, it defaults to the selected frame." 999If FRAME is unspecified or nil, it defaults to the selected frame."