From: "Rami Ylimäki" <rami.ylimaki@vincit.fi>
To: emacs-devel@gnu.org
Cc: "Rami Ylimäki" <rami.ylimaki@vincit.fi>
Subject: [PATCH 1/1] Detect 24-bit TTY color support with standard Terminfo capabilites.
Date: Tue, 23 Jan 2018 22:05:36 +0200 [thread overview]
Message-ID: <20180123200536.26554-2-rami.ylimaki@vincit.fi> (raw)
In-Reply-To: <20180123200536.26554-1-rami.ylimaki@vincit.fi>
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:%p1%@{65536@}%/%d:%p1%@{256@}%/%@{255@}%&%d:%p1%@{255@}%&%dm,
- setf24=\E[38:2:%p1%@{65536@}%/%d:%p1%@{256@}%/%@{255@}%&%d:%p1%@{255@}%&%dm,
-# Use semicolon separators.
-xterm-24bits|xterm with 24-bit direct color mode,
- use=xterm-256color,
- setb24=\E[48;2;%p1%@{65536@}%/%d;%p1%@{256@}%/%@{255@}%&%d;%p1%@{255@}%&%dm,
- setf24=\E[38;2;%p1%@{65536@}%/%d;%p1%@{256@}%/%@{255@}%&%d;%p1%@{255@}%&%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
next prev parent reply other threads:[~2018-01-23 20:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-23 20:05 [PATCH 0/1] Proper 24-bit TTY detection for Emacs 26 Rami Ylimäki
2018-01-23 20:05 ` Rami Ylimäki [this message]
2018-01-24 18:39 ` Eli Zaretskii
2018-01-29 13:27 ` Rami Ylimäki
2018-01-29 15:59 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180123200536.26554-2-rami.ylimaki@vincit.fi \
--to=rami.ylimaki@vincit.fi \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.