GNU bug report logs - #30308
27.0.50; Support direct mode terminal definitions from latest Terminfo.

Previous Next

Package: emacs;

Reported by: Rami Ylimäki <rami.ylimaki <at> vincit.fi>

Date: Wed, 31 Jan 2018 16:22:01 UTC

Severity: wishlist

Tags: patch

Found in version 27.0.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 30308 in the body.
You can then email your comments to 30308 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#30308; Package emacs. (Wed, 31 Jan 2018 16:22:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Rami Ylimäki <rami.ylimaki <at> vincit.fi>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 31 Jan 2018 16:22:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Rami Ylimäki <rami.ylimaki <at> vincit.fi>
To: bug-gnu-emacs <at> gnu.org
Cc: Rami Ylimäki <rami.ylimaki <at> vincit.fi>
Subject: 27.0.50;
 Support direct mode terminal definitions from latest Terminfo.
Date: Wed, 31 Jan 2018 11:43:07 +0200
Direct mode terminal definitions from latest Terminfo are already
compatible with Emacs 26.1 and later, but only if Terminfo
library has been compiled to support 32-bit numerical capability
values.  Following patch adds support for Terminfo with 16-bit
numerical capabilities.

Rami Ylimäki (1):
  Support standard Terminfo direct mode terminals.

 doc/misc/efaq.texi | 45 +++++++++++++++++++++++++++------------------
 src/term.c         | 35 ++++++++++++++++++++++-------------
 src/tparam.h       |  3 ++-
 3 files changed, 51 insertions(+), 32 deletions(-)

-- 
2.14.1





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30308; Package emacs. (Wed, 31 Jan 2018 16:37:02 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Rami Ylimäki <rami.ylimaki <at> vincit.fi>
To: bug-gnu-emacs <at> gnu.org
Cc: Rami Ylimäki <rami.ylimaki <at> vincit.fi>
Subject: [PATCH 1/1] Support standard Terminfo direct mode terminals.
Date: Wed, 31 Jan 2018 11:43:08 +0200
Latest Terminfo introduces terminal definitions that support direct
color mode.  The "Co"/"colors" capability is set to 0x1000000 on these
terminals and Emacs is already compatible with them.

However, if used Terminfo library hasn't been compiled with 32-bit
value support, "Co"/"colors" is truncated to 0x7fff.  In this case
direct color mode support can be detected from the "RGB" capability
flag.

There are some minor problems if the color count isn't corrected from
0x7fff.  First eight standard colors defined in xterm-standard-colors
are shown correctly.  However, their RGB values match the terminal
settings, not the RGB values defined in xterm-standard-colors.  Bright
versions of these colors are shown incorrectly.  They are interpreted
as pixels #000008 - #000015, which are very dark shades of blue.

* src/term.c (init_tty): Force terminal color count to 0x1000000 if
  "RGB" capability is present.
* src/tparam.h: Define prototype for tigetflag.

* doc/misc/efaq.texi (Colors on a TTY): Add information about direct
  mode terminals supported by Terminfo.
---
 doc/misc/efaq.texi | 45 +++++++++++++++++++++++++++------------------
 src/term.c         | 35 ++++++++++++++++++++++-------------
 src/tparam.h       |  3 ++-
 3 files changed, 51 insertions(+), 32 deletions(-)

diff --git a/doc/misc/efaq.texi b/doc/misc/efaq.texi
index 3e67438ab9..fef9b1051b 100644
--- a/doc/misc/efaq.texi
+++ b/doc/misc/efaq.texi
@@ -1496,32 +1496,41 @@ Colors on a TTY
 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.
+Standard terminal definitions don't support these capabilities and
+therefore custom definition is needed.
 
 @example
-$ cat terminfo-24bit.src
+$ cat terminfo-custom.src
 
-# Use colon separators.
-xterm-24bit|xterm with 24-bit direct color mode,
+xterm-emacs|xterm with 24-bit direct color mode for Emacs,
   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,
+  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-custom.src
+
+$ TERM=xterm-emacs emacs -nw
+@end example
+
+Emacs 27.1 and later support Terminfo capability @samp{RGB} for
+detecting 24-bit direct color mode.  Multiple standard terminal
+definitions support this capability.
+
+@example
+$ TERM=xterm-direct infocmp | grep seta[bf]
 
-$ tic -x -o ~/.terminfo terminfo-24bit.src
+  setab=\E[%?%p1%@{8@}%<%t4%p1%d%e48\:2\:\:%p1%@{65536@}%/%d\:%p1%@{256@}%/%@{255@}%&%d\:%p1%@{255@}%&%d%;m,
+  setaf=\E[%?%p1%@{8@}%<%t3%p1%d%e38\:2\:\:%p1%@{65536@}%/%d\:%p1%@{256@}%/%@{255@}%&%d\:%p1%@{255@}%&%d%;m,
 
-$ TERM=xterm-24bit emacs -nw
+$ TERM=xterm-direct 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.
+Terminals with @samp{RGB} capability treat pixels #000001 - #000007 as
+indexed colors to maintain backward compatibility with applications
+that are unaware of direct color mode.  Therefore the seven darkest
+blue shades may not be available.  If this is a problem, you can
+always use custom terminal definition with @samp{setb24} and
+@samp{setf24}.
 
 @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..5e41ca5f6b 100644
--- a/src/term.c
+++ b/src/term.c
@@ -4144,19 +4144,28 @@ 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;
-	  }
-      }
+      /* Non-standard support for 24-bit colors.  */
+      if (tigetflag ("RGB") < 1)
+        {
+          const char *fg = tigetstr ("setf24");
+          const char *bg = tigetstr ("setb24");
+          const bool has_fg = fg && (fg != (char *) (intptr_t) -1);
+          const bool has_bg = bg && (bg != (char *) (intptr_t) -1);
+          if (has_fg && has_bg)
+            {
+              tty->TS_set_foreground = fg;
+              tty->TS_set_background = bg;
+              tty->TN_max_colors = 16777216;
+            }
+        }
+      /* Standard support for 24-bit colors.  */
+      else
+        {
+          /* If the used Terminfo library supports only 16-bit signed
+             values, tgetnum("Co") and tigetnum("colors") could return
+             32767.  */
+          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.14.1





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30308; Package emacs. (Wed, 31 Jan 2018 17:01:01 GMT) Full text and rfc822 format available.

Message #11 received at 30308 <at> debbugs.gnu.org (full text, mbox):

From: Rami Ylimäki <rami.ylimaki <at> vincit.fi>
To: 30308 <at> debbugs.gnu.org
Subject: Re: bug#30308: [PATCH 1/1] Support standard Terminfo direct mode
 terminals.
Date: Wed, 31 Jan 2018 19:00:50 +0200
[Message part 1 (text/plain, inline)]
I'll send a second revision of this patch, because the current revision
doesn't allow one to use "RGB" and set[bf]24 at the same time.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#30308; Package emacs. (Thu, 01 Feb 2018 09:43:02 GMT) Full text and rfc822 format available.

Message #14 received at 30308 <at> debbugs.gnu.org (full text, mbox):

From: Rami Ylimäki <rami.ylimaki <at> vincit.fi>
To: 30308 <at> debbugs.gnu.org
Subject: [PATCH v2] Support standard Terminfo direct mode terminals.
Date: Thu,  1 Feb 2018 11:41:33 +0200
Latest Terminfo introduces terminal definitions that support direct
color mode.  The "Co"/"colors" capability is set to 0x1000000 on these
terminals and Emacs is already compatible with them.

However, if used Terminfo library hasn't been compiled with 32-bit
value support, "Co"/"colors" is truncated to 0x7fff.  In this case
direct color mode support can be detected from the "RGB" capability
flag.

There are some minor problems if the color count isn't corrected from
0x7fff.  First eight standard colors defined in xterm-standard-colors
are shown correctly.  However, their RGB values match the terminal
settings, not the RGB values defined in xterm-standard-colors.  Bright
versions of these colors are shown incorrectly.  They are interpreted
as pixels #000008 - #000015, which are very dark shades of blue.

* src/term.c (init_tty): Force terminal color count to 0x1000000 if
  "RGB" capability is present.
* src/tparam.h: Define prototype for tigetflag.

* doc/misc/efaq.texi (Colors on a TTY): Add information about direct
  mode terminals supported by Terminfo.
---
 doc/misc/efaq.texi | 45 +++++++++++++++++++++++++++------------------
 src/term.c         | 10 +++++++++-
 src/tparam.h       |  3 ++-
 3 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/doc/misc/efaq.texi b/doc/misc/efaq.texi
index 3e67438ab9..fef9b1051b 100644
--- a/doc/misc/efaq.texi
+++ b/doc/misc/efaq.texi
@@ -1496,32 +1496,41 @@ Colors on a TTY
 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.
+Standard terminal definitions don't support these capabilities and
+therefore custom definition is needed.
 
 @example
-$ cat terminfo-24bit.src
+$ cat terminfo-custom.src
 
-# Use colon separators.
-xterm-24bit|xterm with 24-bit direct color mode,
+xterm-emacs|xterm with 24-bit direct color mode for Emacs,
   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,
+  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-custom.src
+
+$ TERM=xterm-emacs emacs -nw
+@end example
+
+Emacs 27.1 and later support Terminfo capability @samp{RGB} for
+detecting 24-bit direct color mode.  Multiple standard terminal
+definitions support this capability.
+
+@example
+$ TERM=xterm-direct infocmp | grep seta[bf]
 
-$ tic -x -o ~/.terminfo terminfo-24bit.src
+  setab=\E[%?%p1%@{8@}%<%t4%p1%d%e48\:2\:\:%p1%@{65536@}%/%d\:%p1%@{256@}%/%@{255@}%&%d\:%p1%@{255@}%&%d%;m,
+  setaf=\E[%?%p1%@{8@}%<%t3%p1%d%e38\:2\:\:%p1%@{65536@}%/%d\:%p1%@{256@}%/%@{255@}%&%d\:%p1%@{255@}%&%d%;m,
 
-$ TERM=xterm-24bit emacs -nw
+$ TERM=xterm-direct 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.
+Terminals with @samp{RGB} capability treat pixels #000001 - #000007 as
+indexed colors to maintain backward compatibility with applications
+that are unaware of direct color mode.  Therefore the seven darkest
+blue shades may not be available.  If this is a problem, you can
+always use custom terminal definition with @samp{setb24} and
+@samp{setf24}.
 
 @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..64a2b7e551 100644
--- a/src/term.c
+++ b/src/term.c
@@ -4144,10 +4144,10 @@ 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");
+	/* Non-standard support for 24-bit colors. */
 	if (fg && bg
 	    && fg != (char *) (intptr_t) -1
 	    && bg != (char *) (intptr_t) -1)
@@ -4156,6 +4156,14 @@ use the Bourne shell command 'TERM=...; export TERM' (C-shell:\n\
 	    tty->TS_set_background = bg;
 	    tty->TN_max_colors = 16777216;
 	  }
+	/* Standard support for 24-bit colors.  */
+	else if (tigetflag ("RGB") > 0)
+	  {
+	    /* If the used Terminfo library supports only 16-bit
+	       signed values, tgetnum("Co") and tigetnum("colors")
+	       could return 32767.  */
+	    tty->TN_max_colors = 16777216;
+	  }
       }
 #endif
 
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.14.1





Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sat, 10 Feb 2018 11:35:03 GMT) Full text and rfc822 format available.

Notification sent to Rami Ylimäki <rami.ylimaki <at> vincit.fi>:
bug acknowledged by developer. (Sat, 10 Feb 2018 11:35:03 GMT) Full text and rfc822 format available.

Message #19 received at 30308-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Rami Ylimäki <rami.ylimaki <at> vincit.fi>
Cc: 30308-done <at> debbugs.gnu.org
Subject: Re: bug#30308: [PATCH v2] Support standard Terminfo direct mode
 terminals.
Date: Sat, 10 Feb 2018 13:33:39 +0200
> From: Rami Ylimäki <rami.ylimaki <at> vincit.fi>
> Date: Thu,  1 Feb 2018 11:41:33 +0200
> 
> Latest Terminfo introduces terminal definitions that support direct
> color mode.  The "Co"/"colors" capability is set to 0x1000000 on these
> terminals and Emacs is already compatible with them.
> 
> However, if used Terminfo library hasn't been compiled with 32-bit
> value support, "Co"/"colors" is truncated to 0x7fff.  In this case
> direct color mode support can be detected from the "RGB" capability
> flag.
> 
> There are some minor problems if the color count isn't corrected from
> 0x7fff.  First eight standard colors defined in xterm-standard-colors
> are shown correctly.  However, their RGB values match the terminal
> settings, not the RGB values defined in xterm-standard-colors.  Bright
> versions of these colors are shown incorrectly.  They are interpreted
> as pixels #000008 - #000015, which are very dark shades of blue.
> 
> * src/term.c (init_tty): Force terminal color count to 0x1000000 if
>   "RGB" capability is present.
> * src/tparam.h: Define prototype for tigetflag.
> 
> * doc/misc/efaq.texi (Colors on a TTY): Add information about direct
>   mode terminals supported by Terminfo.

Thanks, pushed to the master branch.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 10 Mar 2018 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 163 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.