diff options
| author | Rami Ylimäki | 2017-02-18 13:04:55 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2017-02-18 13:04:55 +0200 |
| commit | e463e5762bbe628be3d15da066a90f079a8468b3 (patch) | |
| tree | 2aa517f3626acbe0dbc73dc7ad5a8ec7d81656c9 /lisp/term | |
| parent | 464a51ed46990554bed8a9443168c976d6c3c6d3 (diff) | |
| download | emacs-e463e5762bbe628be3d15da066a90f079a8468b3.tar.gz emacs-e463e5762bbe628be3d15da066a90f079a8468b3.zip | |
Support 24-bit direct colors on text terminals
* src/term.c (init_tty): Use 24-bit terminal colors if corresponding
foreground and background functions are present in terminal type
definition.
* src/tparam.h: Define prototype for tigetstr.
* lisp/term/tty-colors.el (tty-color-define): Convert color palette
index to pixel value on 16.7M color terminals.
(tty-color-24bit): New function to convert color palette index to
pixel value on 16.7M color terminals.
(tty-color-desc): Don't approximate colors on 16.7M color terminals.
* lisp/term/xterm.el (xterm-register-default-colors): Define all named
TTY colors on 16.7M color terminals.
* doc/misc/efaq.texi (Colors on a TTY): Add instructions on how to
enable direct color TTY mode.
* etc/NEWS: Mention direct color TTY mode and point to FAQ.
Diffstat (limited to 'lisp/term')
| -rw-r--r-- | lisp/term/tty-colors.el | 19 | ||||
| -rw-r--r-- | lisp/term/xterm.el | 8 |
2 files changed, 25 insertions, 2 deletions
diff --git a/lisp/term/tty-colors.el b/lisp/term/tty-colors.el index 252a4301295..9cfe30a4630 100644 --- a/lisp/term/tty-colors.el +++ b/lisp/term/tty-colors.el | |||
| @@ -824,6 +824,15 @@ A canonicalized color name is all-lower case, with any blanks removed." | |||
| 824 | (replace-regexp-in-string " +" "" (downcase color)) | 824 | (replace-regexp-in-string " +" "" (downcase color)) |
| 825 | color))) | 825 | color))) |
| 826 | 826 | ||
| 827 | (defun tty-color-24bit (rgb) | ||
| 828 | "Return pixel value on 24-bit terminals. Return nil if RGB is | ||
| 829 | nil or not on 24-bit terminal." | ||
| 830 | (when (and rgb (= (display-color-cells) 16777216)) | ||
| 831 | (let ((r (lsh (car rgb) -8)) | ||
| 832 | (g (lsh (cadr rgb) -8)) | ||
| 833 | (b (lsh (nth 2 rgb) -8))) | ||
| 834 | (logior (lsh r 16) (lsh g 8) b)))) | ||
| 835 | |||
| 827 | (defun tty-color-define (name index &optional rgb frame) | 836 | (defun tty-color-define (name index &optional rgb frame) |
| 828 | "Specify a tty color by its NAME, terminal INDEX and RGB values. | 837 | "Specify a tty color by its NAME, terminal INDEX and RGB values. |
| 829 | NAME is a string, INDEX is typically a small integer used to send to | 838 | NAME is a string, INDEX is typically a small integer used to send to |
| @@ -840,7 +849,10 @@ If FRAME is not specified or is nil, it defaults to the selected frame." | |||
| 840 | (and rgb (or (not (listp rgb)) (/= (length rgb) 3)))) | 849 | (and rgb (or (not (listp rgb)) (/= (length rgb) 3)))) |
| 841 | (error "Invalid specification for tty color \"%s\"" name)) | 850 | (error "Invalid specification for tty color \"%s\"" name)) |
| 842 | (tty-modify-color-alist | 851 | (tty-modify-color-alist |
| 843 | (append (list (tty-color-canonicalize name) index) rgb) frame)) | 852 | (append (list (tty-color-canonicalize name) |
| 853 | (or (tty-color-24bit rgb) index)) | ||
| 854 | rgb) | ||
| 855 | frame)) | ||
| 844 | 856 | ||
| 845 | (defun tty-color-clear (&optional _frame) | 857 | (defun tty-color-clear (&optional _frame) |
| 846 | "Clear the list of supported tty colors for frame FRAME. | 858 | "Clear the list of supported tty colors for frame FRAME. |
| @@ -1013,7 +1025,10 @@ might need to be approximated if it is not supported directly." | |||
| 1013 | (let ((color (tty-color-canonicalize color))) | 1025 | (let ((color (tty-color-canonicalize color))) |
| 1014 | (or (assoc color (tty-color-alist frame)) | 1026 | (or (assoc color (tty-color-alist frame)) |
| 1015 | (let ((rgb (tty-color-standard-values color))) | 1027 | (let ((rgb (tty-color-standard-values color))) |
| 1016 | (and rgb (tty-color-approximate rgb frame))))))) | 1028 | (and rgb |
| 1029 | (let ((pixel (tty-color-24bit rgb))) | ||
| 1030 | (or (and pixel (cons color (cons pixel rgb))) | ||
| 1031 | (tty-color-approximate rgb frame))))))))) | ||
| 1017 | 1032 | ||
| 1018 | (defun tty-color-gray-shades (&optional display) | 1033 | (defun tty-color-gray-shades (&optional display) |
| 1019 | "Return the number of gray colors supported by DISPLAY's terminal. | 1034 | "Return the number of gray colors supported by DISPLAY's terminal. |
diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index 339d05d9728..e6d224dd3de 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el | |||
| @@ -930,6 +930,14 @@ versions of xterm." | |||
| 930 | ;; are more colors to support, compute them now. | 930 | ;; are more colors to support, compute them now. |
| 931 | (when (> ncolors 0) | 931 | (when (> ncolors 0) |
| 932 | (cond | 932 | (cond |
| 933 | ((= ncolors 16777200) ; 24-bit xterm | ||
| 934 | ;; all named tty colors | ||
| 935 | (let ((idx (length xterm-standard-colors))) | ||
| 936 | (mapc (lambda (color) | ||
| 937 | (unless (assoc (car color) xterm-standard-colors) | ||
| 938 | (tty-color-define (car color) idx (cdr color)) | ||
| 939 | (setq idx (1+ idx)))) | ||
| 940 | color-name-rgb-alist))) | ||
| 933 | ((= ncolors 240) ; 256-color xterm | 941 | ((= ncolors 240) ; 256-color xterm |
| 934 | ;; 216 non-gray colors first | 942 | ;; 216 non-gray colors first |
| 935 | (let ((r 0) (g 0) (b 0)) | 943 | (let ((r 0) (g 0) (b 0)) |