[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/1] Detect 24-bit TTY color support with standard Terminfo capab
From: |
Rami Ylimäki |
Subject: |
[PATCH 1/1] Detect 24-bit TTY color support with standard Terminfo capabilites. |
Date: |
Tue, 23 Jan 2018 22:05:36 +0200 |
Latest Terminfo supports RGB capability flag for direct color mode
terminals. Foreground and background colors are set with setaf and
setab capability strings.
* src/term.c (init_tty): Use standard Terminfo capabilities to detect
24-bit TTY color support.
* src/tparam.h: Define prototype for tigetflag.
* doc/misc/efaq.texi (Colors on a TTY): Fix instructions on how to
enable direct color TTY mode.
---
doc/misc/efaq.texi | 34 +++++++---------------------------
src/term.c | 26 +++++++++++++-------------
src/tparam.h | 3 ++-
3 files changed, 22 insertions(+), 41 deletions(-)
diff --git a/doc/misc/efaq.texi b/doc/misc/efaq.texi
index 8014c2b71f..0ed58eda66 100644
--- a/doc/misc/efaq.texi
+++ b/doc/misc/efaq.texi
@@ -1491,37 +1491,17 @@ Colors on a TTY
Syntax highlighting is on by default since version 22.1.
Emacs 26.1 and later support direct color mode in terminals. If Emacs
-finds Terminfo capabilities @samp{setb24} and @samp{setf24}, 24-bit
-direct color mode is used. The capability strings are expected to
-take one 24-bit pixel value as argument and transform the pixel to a
-string that can be used to send 24-bit colors to the terminal.
-
-There aren't yet any standard terminal type definitions that would
-support the capabilities, but Emacs can be invoked with a custom
-definition as shown below.
+finds Terminfo capability @samp{RGB}, 24-bit direct color mode is
+used.
@example
-$ cat terminfo-24bit.src
-
-# Use colon separators.
-xterm-24bit|xterm with 24-bit direct color mode,
- use=xterm-256color,
-
setb24=\E[48:2:address@hidden@}%/%d:address@hidden@}%/address@hidden@}%&%d:address@hidden@}%&%dm,
-
setf24=\E[38:2:address@hidden@}%/%d:address@hidden@}%/address@hidden@}%&%d:address@hidden@}%&%dm,
-# Use semicolon separators.
-xterm-24bits|xterm with 24-bit direct color mode,
- use=xterm-256color,
-
setb24=\E[48;2;address@hidden@}%/%d;address@hidden@}%/address@hidden@}%&%d;address@hidden@}%&%dm,
-
setf24=\E[38;2;address@hidden@}%/%d;address@hidden@}%/address@hidden@}%&%d;address@hidden@}%&%dm,
-
-$ tic -x -o ~/.terminfo terminfo-24bit.src
-
-$ TERM=xterm-24bit emacs -nw
+$ TERM=xterm-direct2 emacs -nw
@end example
-Currently there's no standard way to determine whether a terminal
-supports direct color mode. If such standard arises later on, support
-for @samp{setb24} and @samp{setf24} may be removed.
+Currently direct color mode support is quite fragmented and therefore
+Terminfo provides various terminal specifications. You need to make
+sure that the @samp{setab} and @samp{setaf} capabilites of your TERM
+match your terminal.
@node Debugging a customization file
@section How do I debug a @file{.emacs} file?
diff --git a/src/term.c b/src/term.c
index b3707da70a..975ba956d7 100644
--- a/src/term.c
+++ b/src/term.c
@@ -4144,19 +4144,19 @@ use the Bourne shell command 'TERM=...; export TERM'
(C-shell:\n\
tty->TN_max_colors = tgetnum ("Co");
#ifdef TERMINFO
- /* Non-standard support for 24-bit colors. */
- {
- const char *fg = tigetstr ("setf24");
- const char *bg = tigetstr ("setb24");
- if (fg && bg
- && fg != (char *) (intptr_t) -1
- && bg != (char *) (intptr_t) -1)
- {
- tty->TS_set_foreground = fg;
- tty->TS_set_background = bg;
- tty->TN_max_colors = 16777216;
- }
- }
+ if (tigetflag ("RGB") > 0)
+ {
+ const char *fg = tigetstr ("setaf");
+ const char *bg = tigetstr ("setab");
+ if (fg && bg
+ && fg != (char *) (intptr_t) -1
+ && bg != (char *) (intptr_t) -1)
+ {
+ tty->TS_set_foreground = fg;
+ tty->TS_set_background = bg;
+ tty->TN_max_colors = 16777216;
+ }
+ }
#endif
tty->TN_no_color_video = tgetnum ("NC");
diff --git a/src/tparam.h b/src/tparam.h
index f8fb9e0869..3a3cb52c17 100644
--- a/src/tparam.h
+++ b/src/tparam.h
@@ -37,7 +37,8 @@ extern char *BC;
extern char *UP;
#ifdef TERMINFO
-char *tigetstr(const char *);
+int tigetflag (const char *);
+char *tigetstr (const char *);
#endif
#endif /* EMACS_TPARAM_H */
--
2.11.0