all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [RFC] Add tty True Color support.
@ 2013-10-15 17:24 Rüdiger Sonderfeld
  2013-10-16 19:45 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Rüdiger Sonderfeld @ 2013-10-15 17:24 UTC (permalink / raw)
  To: emacs-devel

Some terminals support True Color (24bit RGB) values.  At least KDE's
Konsole, st, and iTerm2 support it.  This patch makes True Color
support available in Emacs.

So far there is no reliable way to detect True Color support in
terminals and the terminfo database lacks support.  I started a
discussion on the ncurses mailing list[1].  So far only Konsole is
supported by detecting the KONSOLE_DBUS_SESSION environment variable.
But this should be replaced by a more reliable method.

[1] https://lists.gnu.org/archive/html/bug-ncurses/2013-10/msg00007.html

* src/term.c (turn_on_face): Support True Color.
  (default_set_rgb_foreground): New variable.
  (default_set_rgb_background): New variable.
  (tty_default_color_capabilities): Save/restore set_rgb_*ground
  variables.
  (tty_setup_colors): Add support for True Color (16777216).
  (init_tty): Detect terminal True Color support.

* src/termchar.h (struct tty_display_info): Add TS_set_rgb_foreground,
  TS_set_rgb_background.

* src/xfaces.c (tty_lookup_color): Encode colors as True Color if
  supported on frame.

Signed-off-by: Rüdiger Sonderfeld <ruediger@c-plusplus.de>
---
 src/term.c     | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 src/termchar.h |   4 ++
 src/xfaces.c   | 103 ++++++++++++++++++++++++++++++--------------------
 3 files changed, 169 insertions(+), 54 deletions(-)

diff --git a/src/term.c b/src/term.c
index ee81c59..a71e8f9 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1960,21 +1960,57 @@ struct fkey_table {
       const char *ts;
       char *p;
 
-      ts = tty->standout_mode ? tty->TS_set_background : tty->TS_set_foreground;
-      if (fg >= 0 && ts)
-	{
-          p = tparam (ts, NULL, 0, fg, 0, 0, 0);
-	  OUTPUT (tty, p);
-	  xfree (p);
-	}
+      if (fg > 0 && fg & (1 << 24)) /* RGB color */
+        {
+          ts = tty->standout_mode ? tty->TS_set_rgb_background
+            : tty->TS_set_rgb_foreground;
+          if (ts)
+            {
+              const unsigned char r = (fg & 0xFF0000) >> 16,
+                g = (fg & 0x00FF00) >> 8,
+                b = (fg & 0x0000FF);
+              p = tparam (ts, NULL, 0, r, g, b, 0);
+              OUTPUT (tty, p);
+              xfree (p);
+            }
+        }
+      else
+        {
+          ts = tty->standout_mode ? tty->TS_set_background
+            : tty->TS_set_foreground;
+          if (fg >= 0 && ts)
+            {
+              p = tparam (ts, NULL, 0, fg, 0, 0, 0);
+              OUTPUT (tty, p);
+              xfree (p);
+            }
+        }
 
-      ts = tty->standout_mode ? tty->TS_set_foreground : tty->TS_set_background;
-      if (bg >= 0 && ts)
-	{
-          p = tparam (ts, NULL, 0, bg, 0, 0, 0);
-	  OUTPUT (tty, p);
-	  xfree (p);
-	}
+      if (bg > 0 && bg & (1 << 24)) /* RGB color */
+        {
+          ts = tty->standout_mode ? tty->TS_set_rgb_foreground
+            : tty->TS_set_rgb_background;
+          if (ts)
+            {
+              const unsigned char r = (bg & 0xFF0000) >> 16,
+                g = (bg & 0x00FF00) >> 8,
+                b = (bg & 0x0000FF);
+              p = tparam (ts, NULL, 0, r, g, b, 0);
+              OUTPUT (tty, p);
+              xfree (p);
+            }
+        }
+      else
+        {
+          ts = tty->standout_mode ? tty->TS_set_foreground
+            : tty->TS_set_background;
+          if (bg >= 0 && ts)
+            {
+              p = tparam (ts, NULL, 0, bg, 0, 0, 0);
+              OUTPUT (tty, p);
+              xfree (p);
+            }
+        }
     }
 }
 
@@ -2090,6 +2126,8 @@ struct fkey_table {
 static char *default_orig_pair;
 static char *default_set_foreground;
 static char *default_set_background;
+static char *default_set_rgb_foreground;
+static char *default_set_rgb_background;
 
 /* Save or restore the default color-related capabilities of this
    terminal.  */
@@ -2110,6 +2148,16 @@ struct fkey_table {
       default_set_background = tty->TS_set_background ? xstrdup (tty->TS_set_background)
 			       : NULL;
 
+      xfree (default_set_rgb_foreground);
+      default_set_rgb_foreground = tty->TS_set_rgb_foreground
+                                   ? xstrdup (tty->TS_set_rgb_foreground)
+                                   : NULL;
+
+      xfree (default_set_rgb_background);
+      default_set_rgb_foreground = tty->TS_set_rgb_background
+                                   ? xstrdup (tty->TS_set_rgb_background)
+                                   : NULL;
+
       default_max_colors = tty->TN_max_colors;
       default_max_pairs = tty->TN_max_pairs;
       default_no_color_video = tty->TN_no_color_video;
@@ -2119,6 +2167,8 @@ struct fkey_table {
       tty->TS_orig_pair = default_orig_pair;
       tty->TS_set_foreground = default_set_foreground;
       tty->TS_set_background = default_set_background;
+      tty->TS_set_rgb_foreground = default_set_rgb_foreground;
+      tty->TS_set_rgb_background = default_set_rgb_background;
       tty->TN_max_colors = default_max_colors;
       tty->TN_max_pairs = default_max_pairs;
       tty->TN_no_color_video = default_no_color_video;
@@ -2143,6 +2193,7 @@ struct fkey_table {
 	tty->TN_max_pairs = 0;
 	tty->TN_no_color_video = 0;
 	tty->TS_set_foreground = tty->TS_set_background = tty->TS_orig_pair = NULL;
+        tty->TS_set_rgb_foreground = tty->TS_set_rgb_background = NULL;
 	break;
       case 0:	 /* default colors, if any */
       default:
@@ -2157,10 +2208,29 @@ struct fkey_table {
 	tty->TS_set_foreground = "\033[3%dm";
 	tty->TS_set_background = "\033[4%dm";
 #endif
+        tty->TS_set_rgb_foreground = NULL;
+        tty->TS_set_rgb_background = NULL;
 	tty->TN_max_colors = 8;
 	tty->TN_max_pairs = 64;
 	tty->TN_no_color_video = 0;
 	break;
+      case 16777216: /* RGB colors */
+        tty->TS_orig_pair = "\033[0m";
+#ifdef TERMINFO
+	tty->TS_set_foreground = "\033[3%p1%dm";
+	tty->TS_set_background = "\033[4%p1%dm";
+        tty->TS_set_rgb_foreground = "\E[38;2;%p1%d;%p2%d;%p3%dm";
+        tty->TS_set_rgb_background = "\E[48;2;%p1%d;%p2%d;%p3%dm";
+#else
+	tty->TS_set_foreground = "\033[3%dm";
+	tty->TS_set_background = "\033[4%dm";
+        tty->TS_set_rgb_foreground = "\E[38;2;%d;%d;%dm";
+        tty->TS_set_rgb_background = "\E[48;2;%d;%d;%dm";
+#endif
+        tty->TN_max_colors = 16777216;
+        /*tty->TN_max_pairs = 64; TODO */
+	tty->TN_no_color_video = 0;
+        break;
     }
 }
 
@@ -4227,6 +4297,24 @@ struct terminal *
       tty->TN_no_color_video = tgetnum ("NC");
       if (tty->TN_no_color_video == -1)
         tty->TN_no_color_video = 0;
+
+      /* TODO Reliable way to detect: Konsole, iTerm2, st */
+      if (getenv ("KONSOLE_DBUS_SESSION"))
+        {
+          /* TODO This should be extracted from terminfo/termcap. */
+#ifdef TERMINFO
+          tty->TS_set_rgb_foreground = "\E[38;2;%p1%d;%p2%d;%p3%dm";
+          tty->TS_set_rgb_background = "\E[48;2;%p1%d;%p2%d;%p3%dm";
+#else
+          tty->TS_set_rgb_foreground = "\E[38;2;%d;%d;%dm";
+          tty->TS_set_rgb_background = "\E[48;2;%d;%d;%dm";
+#endif
+        }
+      else
+        {
+          tty->TS_set_rgb_foreground = NULL;
+          tty->TS_set_rgb_background = NULL;
+        }
     }
 
   tty_default_color_capabilities (tty, 1);
diff --git a/src/termchar.h b/src/termchar.h
index feb89e0..6ef0c16 100644
--- a/src/termchar.h
+++ b/src/termchar.h
@@ -156,6 +156,10 @@ struct tty_display_info
   const char *TS_set_foreground;
   const char *TS_set_background;
 
+  /* Support for 24bit RGB color terminals. */
+  const char *TS_set_rgb_foreground;
+  const char *TS_set_rgb_background;
+
   int TF_hazeltine;             /* termcap hz flag. */
   int TF_insmode_motion;        /* termcap mi flag: can move while in insert mode. */
   int TF_standout_motion;       /* termcap mi flag: can move while in standout mode. */
diff --git a/src/xfaces.c b/src/xfaces.c
index 828788b..3d53563 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -960,54 +960,77 @@ static struct face *realize_non_ascii_face (struct frame *, Lisp_Object,
   if (!STRINGP (color) || NILP (Ffboundp (Qtty_color_desc)))
     return 0;
 
-  XSETFRAME (frame, f);
-
-  color_desc = call2 (Qtty_color_desc, color, frame);
-  if (CONSP (color_desc) && CONSP (XCDR (color_desc)))
+  if (f->output_method == output_termcap
+      && f->output_data.tty->display_info->TS_set_rgb_foreground
+      && !NILP (Ffboundp (Qtty_color_standard_values)))
     {
-      Lisp_Object rgb;
-
-      if (! INTEGERP (XCAR (XCDR (color_desc))))
-	return 0;
+      /* Terminal supports 3 byte RGB colors. */
+      color_desc = call1 (Qtty_color_standard_values, color);
+      if (! parse_rgb_list (color_desc, tty_color))
+        return 0;
 
-      tty_color->pixel = XINT (XCAR (XCDR (color_desc)));
+      /* Map XColor to 3 byte values. */
+      tty_color->pixel = 1 << 24 /* Set bit 24 to mark RGB values. */
+                         | (tty_color->red / 257) << 16
+                         | (tty_color->green / 257) << 8
+                         | (tty_color->blue / 257);
 
-      rgb = XCDR (XCDR (color_desc));
-      if (! parse_rgb_list (rgb, tty_color))
-	return 0;
-
-      /* Should we fill in STD_COLOR too?  */
       if (std_color)
-	{
-	  /* Default STD_COLOR to the same as TTY_COLOR.  */
-	  *std_color = *tty_color;
-
-	  /* Do a quick check to see if the returned descriptor is
-	     actually _exactly_ equal to COLOR, otherwise we have to
-	     lookup STD_COLOR separately.  If it's impossible to lookup
-	     a standard color, we just give up and use TTY_COLOR.  */
-	  if ((!STRINGP (XCAR (color_desc))
-	       || NILP (Fstring_equal (color, XCAR (color_desc))))
-	      && !NILP (Ffboundp (Qtty_color_standard_values)))
-	    {
-	      /* Look up STD_COLOR separately.  */
-	      rgb = call1 (Qtty_color_standard_values, color);
-	      if (! parse_rgb_list (rgb, std_color))
-		return 0;
-	    }
-	}
+        *std_color = *tty_color;
 
       return 1;
     }
-  else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
-    /* We were called early during startup, and the colors are not
-       yet set up in tty-defined-color-alist.  Don't return a failure
-       indication, since this produces the annoying "Unable to
-       load color" messages in the *Messages* buffer.  */
-    return 1;
   else
-    /* tty-color-desc seems to have returned a bad value.  */
-    return 0;
+    {
+      XSETFRAME (frame, f);
+
+      color_desc = call2 (Qtty_color_desc, color, frame);
+      if (CONSP (color_desc) && CONSP (XCDR (color_desc)))
+        {
+          Lisp_Object rgb;
+
+          if (! INTEGERP (XCAR (XCDR (color_desc))))
+            return 0;
+
+          tty_color->pixel = XINT (XCAR (XCDR (color_desc)));
+
+          rgb = XCDR (XCDR (color_desc));
+          if (! parse_rgb_list (rgb, tty_color))
+            return 0;
+
+          /* Should we fill in STD_COLOR too?  */
+          if (std_color)
+            {
+              /* Default STD_COLOR to the same as TTY_COLOR.  */
+              *std_color = *tty_color;
+
+              /* Do a quick check to see if the returned descriptor is
+                 actually _exactly_ equal to COLOR, otherwise we have to
+                 lookup STD_COLOR separately.  If it's impossible to lookup
+                 a standard color, we just give up and use TTY_COLOR.  */
+              if ((!STRINGP (XCAR (color_desc))
+                   || NILP (Fstring_equal (color, XCAR (color_desc))))
+                  && !NILP (Ffboundp (Qtty_color_standard_values)))
+                {
+                  /* Look up STD_COLOR separately.  */
+                  rgb = call1 (Qtty_color_standard_values, color);
+                  if (! parse_rgb_list (rgb, std_color))
+                    return 0;
+                }
+            }
+
+          return 1;
+        }
+      else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
+        /* We were called early during startup, and the colors are not
+           yet set up in tty-defined-color-alist.  Don't return a failure
+           indication, since this produces the annoying "Unable to
+           load color" messages in the *Messages* buffer.  */
+        return 1;
+      else
+        /* tty-color-desc seems to have returned a bad value.  */
+        return 0;
+    }
 }
 
 /* A version of defined_color for non-X frames.  */
-- 
1.8.4




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [RFC] Add tty True Color support.
  2013-10-15 17:24 [RFC] Add tty True Color support Rüdiger Sonderfeld
@ 2013-10-16 19:45 ` Eli Zaretskii
  2013-10-16 22:39   ` [RFC-2] " Rüdiger Sonderfeld
  2014-01-07 21:02 ` [RFC] " egmont
  2014-07-02 13:38 ` Judge_Dredd
  2 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2013-10-16 19:45 UTC (permalink / raw)
  To: Rüdiger Sonderfeld; +Cc: emacs-devel

> From: Rüdiger Sonderfeld <ruediger@c-plusplus.de>
> Date: Tue, 15 Oct 2013 19:24:49 +0200
> 
> Some terminals support True Color (24bit RGB) values.  At least KDE's
> Konsole, st, and iTerm2 support it.  This patch makes True Color
> support available in Emacs.
> 
> So far there is no reliable way to detect True Color support in
> terminals and the terminfo database lacks support.  I started a
> discussion on the ncurses mailing list[1].  So far only Konsole is
> supported by detecting the KONSOLE_DBUS_SESSION environment variable.
> But this should be replaced by a more reliable method.

Thanks.

I might be missing something, but it looks like you didn't make any
changes aimed at having display-color-cells report the correct number
of colors for this type of terminal.  If that is true, please add some
code to fix that, otherwise various parts in Emacs might behave
incorrectly; for starters, defface's that define colors based on how
many colors are available will use the wrong colors.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [RFC-2] Add tty True Color support.
  2013-10-16 19:45 ` Eli Zaretskii
@ 2013-10-16 22:39   ` Rüdiger Sonderfeld
  2013-10-17 16:56     ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Rüdiger Sonderfeld @ 2013-10-16 22:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Hello,

> I might be missing something, but it looks like you didn't make any
> changes aimed at having display-color-cells report the correct number
> of colors for this type of terminal.  If that is true, please add some
> code to fix that, otherwise various parts in Emacs might behave
> incorrectly; for starters, defface's that define colors based on how
> many colors are available will use the wrong colors.

I changed `tty-display-color-cells' to return the correct number.  See the
updated patch below.

Do you have any suggestion how to do the terminal detection?  So far Thomas
Dickey seems to be reluctant to add support to terminfo.  Maybe there could
be a lisp function to detect it, which could be easily adjusted by the user.
But then again `init_tty' can be called very early in the start up process.

Regards,
Rüdiger

-- 8< --------------------------------------------------------- >8 --

Some terminals support True Color (24bit RGB) values.  At leas KDE's
Konsole, st, and iTerm2 support it.  This patch makes True Color
support available in Emacs.

So far there is no reliable way to detect True Color support in
terminals and the terminfo database lacks support.  I started a
discussion on the ncurses mailing list[1].  So far only Konsole is
supported by detecting the KONSOLE_DBUS_SESSION environment variable.
But this should be replaced by a more reliable method.

[1] https://lists.gnu.org/archive/html/bug-ncurses/2013-10/msg00007.html

* src/term.c (turn_on_face): Support True Color.
  (default_set_rgb_foreground): New variable.
  (default_set_rgb_background): New variable.
  (tty_default_color_capabilities): Save/restore set_rgb_*ground
  variables.
  (tty_setup_colors): Add support for True Color (16777216).
  (init_tty): Detect terminal True Color support.
  (Ftty_display_color_cells): Return correct number for True Color
  terms.

* src/termchar.h (struct tty_display_info): Add TS_set_rgb_foreground,
  TS_set_rgb_background.

* src/xfaces.c (tty_lookup_color): Encode colors as True Color if
  supported on frame.

Signed-off-by: Rüdiger Sonderfeld <ruediger@c-plusplus.de>
---
 src/term.c     | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
 src/termchar.h |   4 ++
 src/xfaces.c   | 103 ++++++++++++++++++++++++++++++-------------------
 3 files changed, 171 insertions(+), 54 deletions(-)

diff --git a/src/term.c b/src/term.c
index ee81c59..f9a398f 100644
--- a/src/term.c
+++ b/src/term.c
@@ -1960,21 +1960,57 @@ struct fkey_table {
       const char *ts;
       char *p;
 
-      ts = tty->standout_mode ? tty->TS_set_background : tty->TS_set_foreground;
-      if (fg >= 0 && ts)
-	{
-          p = tparam (ts, NULL, 0, fg, 0, 0, 0);
-	  OUTPUT (tty, p);
-	  xfree (p);
-	}
+      if (fg > 0 && fg & (1 << 24)) /* RGB color */
+        {
+          ts = tty->standout_mode ? tty->TS_set_rgb_background
+            : tty->TS_set_rgb_foreground;
+          if (ts)
+            {
+              const unsigned char r = (fg & 0xFF0000) >> 16,
+                g = (fg & 0x00FF00) >> 8,
+                b = (fg & 0x0000FF);
+              p = tparam (ts, NULL, 0, r, g, b, 0);
+              OUTPUT (tty, p);
+              xfree (p);
+            }
+        }
+      else
+        {
+          ts = tty->standout_mode ? tty->TS_set_background
+            : tty->TS_set_foreground;
+          if (fg >= 0 && ts)
+            {
+              p = tparam (ts, NULL, 0, fg, 0, 0, 0);
+              OUTPUT (tty, p);
+              xfree (p);
+            }
+        }
 
-      ts = tty->standout_mode ? tty->TS_set_foreground : tty->TS_set_background;
-      if (bg >= 0 && ts)
-	{
-          p = tparam (ts, NULL, 0, bg, 0, 0, 0);
-	  OUTPUT (tty, p);
-	  xfree (p);
-	}
+      if (bg > 0 && bg & (1 << 24)) /* RGB color */
+        {
+          ts = tty->standout_mode ? tty->TS_set_rgb_foreground
+            : tty->TS_set_rgb_background;
+          if (ts)
+            {
+              const unsigned char r = (bg & 0xFF0000) >> 16,
+                g = (bg & 0x00FF00) >> 8,
+                b = (bg & 0x0000FF);
+              p = tparam (ts, NULL, 0, r, g, b, 0);
+              OUTPUT (tty, p);
+              xfree (p);
+            }
+        }
+      else
+        {
+          ts = tty->standout_mode ? tty->TS_set_foreground
+            : tty->TS_set_background;
+          if (bg >= 0 && ts)
+            {
+              p = tparam (ts, NULL, 0, bg, 0, 0, 0);
+              OUTPUT (tty, p);
+              xfree (p);
+            }
+        }
     }
 }
 
@@ -2075,6 +2111,8 @@ struct fkey_table {
   struct terminal *t = get_tty_terminal (terminal, 0);
   if (!t)
     return make_number (0);
+  else if (t->display_info.tty->TS_set_rgb_foreground)
+    return make_number (16777216); /* 24 bit True Color */
   else
     return make_number (t->display_info.tty->TN_max_colors);
 }
@@ -2090,6 +2128,8 @@ struct fkey_table {
 static char *default_orig_pair;
 static char *default_set_foreground;
 static char *default_set_background;
+static char *default_set_rgb_foreground;
+static char *default_set_rgb_background;
 
 /* Save or restore the default color-related capabilities of this
    terminal.  */
@@ -2110,6 +2150,16 @@ struct fkey_table {
       default_set_background = tty->TS_set_background ? xstrdup (tty->TS_set_background)
 			       : NULL;
 
+      xfree (default_set_rgb_foreground);
+      default_set_rgb_foreground = tty->TS_set_rgb_foreground
+                                   ? xstrdup (tty->TS_set_rgb_foreground)
+                                   : NULL;
+
+      xfree (default_set_rgb_background);
+      default_set_rgb_foreground = tty->TS_set_rgb_background
+                                   ? xstrdup (tty->TS_set_rgb_background)
+                                   : NULL;
+
       default_max_colors = tty->TN_max_colors;
       default_max_pairs = tty->TN_max_pairs;
       default_no_color_video = tty->TN_no_color_video;
@@ -2119,6 +2169,8 @@ struct fkey_table {
       tty->TS_orig_pair = default_orig_pair;
       tty->TS_set_foreground = default_set_foreground;
       tty->TS_set_background = default_set_background;
+      tty->TS_set_rgb_foreground = default_set_rgb_foreground;
+      tty->TS_set_rgb_background = default_set_rgb_background;
       tty->TN_max_colors = default_max_colors;
       tty->TN_max_pairs = default_max_pairs;
       tty->TN_no_color_video = default_no_color_video;
@@ -2143,6 +2195,7 @@ struct fkey_table {
 	tty->TN_max_pairs = 0;
 	tty->TN_no_color_video = 0;
 	tty->TS_set_foreground = tty->TS_set_background = tty->TS_orig_pair = NULL;
+        tty->TS_set_rgb_foreground = tty->TS_set_rgb_background = NULL;
 	break;
       case 0:	 /* default colors, if any */
       default:
@@ -2157,10 +2210,29 @@ struct fkey_table {
 	tty->TS_set_foreground = "\033[3%dm";
 	tty->TS_set_background = "\033[4%dm";
 #endif
+        tty->TS_set_rgb_foreground = NULL;
+        tty->TS_set_rgb_background = NULL;
 	tty->TN_max_colors = 8;
 	tty->TN_max_pairs = 64;
 	tty->TN_no_color_video = 0;
 	break;
+      case 16777216: /* RGB colors */
+        tty->TS_orig_pair = "\033[0m";
+#ifdef TERMINFO
+	tty->TS_set_foreground = "\033[3%p1%dm";
+	tty->TS_set_background = "\033[4%p1%dm";
+        tty->TS_set_rgb_foreground = "\E[38;2;%p1%d;%p2%d;%p3%dm";
+        tty->TS_set_rgb_background = "\E[48;2;%p1%d;%p2%d;%p3%dm";
+#else
+	tty->TS_set_foreground = "\033[3%dm";
+	tty->TS_set_background = "\033[4%dm";
+        tty->TS_set_rgb_foreground = "\E[38;2;%d;%d;%dm";
+        tty->TS_set_rgb_background = "\E[48;2;%d;%d;%dm";
+#endif
+        tty->TN_max_colors = 16777216;
+        /*tty->TN_max_pairs = 64; TODO */
+	tty->TN_no_color_video = 0;
+        break;
     }
 }
 
@@ -4227,6 +4299,24 @@ struct terminal *
       tty->TN_no_color_video = tgetnum ("NC");
       if (tty->TN_no_color_video == -1)
         tty->TN_no_color_video = 0;
+
+      /* TODO Reliable way to detect: Konsole, iTerm2, st */
+      if (getenv ("KONSOLE_DBUS_SESSION"))
+        {
+          /* TODO This should be extracted from terminfo/termcap. */
+#ifdef TERMINFO
+          tty->TS_set_rgb_foreground = "\E[38;2;%p1%d;%p2%d;%p3%dm";
+          tty->TS_set_rgb_background = "\E[48;2;%p1%d;%p2%d;%p3%dm";
+#else
+          tty->TS_set_rgb_foreground = "\E[38;2;%d;%d;%dm";
+          tty->TS_set_rgb_background = "\E[48;2;%d;%d;%dm";
+#endif
+        }
+      else
+        {
+          tty->TS_set_rgb_foreground = NULL;
+          tty->TS_set_rgb_background = NULL;
+        }
     }
 
   tty_default_color_capabilities (tty, 1);
diff --git a/src/termchar.h b/src/termchar.h
index feb89e0..6ef0c16 100644
--- a/src/termchar.h
+++ b/src/termchar.h
@@ -156,6 +156,10 @@ struct tty_display_info
   const char *TS_set_foreground;
   const char *TS_set_background;
 
+  /* Support for 24bit RGB color terminals. */
+  const char *TS_set_rgb_foreground;
+  const char *TS_set_rgb_background;
+
   int TF_hazeltine;             /* termcap hz flag. */
   int TF_insmode_motion;        /* termcap mi flag: can move while in insert mode. */
   int TF_standout_motion;       /* termcap mi flag: can move while in standout mode. */
diff --git a/src/xfaces.c b/src/xfaces.c
index 828788b..3d53563 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -960,54 +960,77 @@ static struct face *realize_non_ascii_face (struct frame *, Lisp_Object,
   if (!STRINGP (color) || NILP (Ffboundp (Qtty_color_desc)))
     return 0;
 
-  XSETFRAME (frame, f);
-
-  color_desc = call2 (Qtty_color_desc, color, frame);
-  if (CONSP (color_desc) && CONSP (XCDR (color_desc)))
+  if (f->output_method == output_termcap
+      && f->output_data.tty->display_info->TS_set_rgb_foreground
+      && !NILP (Ffboundp (Qtty_color_standard_values)))
     {
-      Lisp_Object rgb;
-
-      if (! INTEGERP (XCAR (XCDR (color_desc))))
-	return 0;
+      /* Terminal supports 3 byte RGB colors. */
+      color_desc = call1 (Qtty_color_standard_values, color);
+      if (! parse_rgb_list (color_desc, tty_color))
+        return 0;
 
-      tty_color->pixel = XINT (XCAR (XCDR (color_desc)));
+      /* Map XColor to 3 byte values. */
+      tty_color->pixel = 1 << 24 /* Set bit 24 to mark RGB values. */
+                         | (tty_color->red / 257) << 16
+                         | (tty_color->green / 257) << 8
+                         | (tty_color->blue / 257);
 
-      rgb = XCDR (XCDR (color_desc));
-      if (! parse_rgb_list (rgb, tty_color))
-	return 0;
-
-      /* Should we fill in STD_COLOR too?  */
       if (std_color)
-	{
-	  /* Default STD_COLOR to the same as TTY_COLOR.  */
-	  *std_color = *tty_color;
-
-	  /* Do a quick check to see if the returned descriptor is
-	     actually _exactly_ equal to COLOR, otherwise we have to
-	     lookup STD_COLOR separately.  If it's impossible to lookup
-	     a standard color, we just give up and use TTY_COLOR.  */
-	  if ((!STRINGP (XCAR (color_desc))
-	       || NILP (Fstring_equal (color, XCAR (color_desc))))
-	      && !NILP (Ffboundp (Qtty_color_standard_values)))
-	    {
-	      /* Look up STD_COLOR separately.  */
-	      rgb = call1 (Qtty_color_standard_values, color);
-	      if (! parse_rgb_list (rgb, std_color))
-		return 0;
-	    }
-	}
+        *std_color = *tty_color;
 
       return 1;
     }
-  else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
-    /* We were called early during startup, and the colors are not
-       yet set up in tty-defined-color-alist.  Don't return a failure
-       indication, since this produces the annoying "Unable to
-       load color" messages in the *Messages* buffer.  */
-    return 1;
   else
-    /* tty-color-desc seems to have returned a bad value.  */
-    return 0;
+    {
+      XSETFRAME (frame, f);
+
+      color_desc = call2 (Qtty_color_desc, color, frame);
+      if (CONSP (color_desc) && CONSP (XCDR (color_desc)))
+        {
+          Lisp_Object rgb;
+
+          if (! INTEGERP (XCAR (XCDR (color_desc))))
+            return 0;
+
+          tty_color->pixel = XINT (XCAR (XCDR (color_desc)));
+
+          rgb = XCDR (XCDR (color_desc));
+          if (! parse_rgb_list (rgb, tty_color))
+            return 0;
+
+          /* Should we fill in STD_COLOR too?  */
+          if (std_color)
+            {
+              /* Default STD_COLOR to the same as TTY_COLOR.  */
+              *std_color = *tty_color;
+
+              /* Do a quick check to see if the returned descriptor is
+                 actually _exactly_ equal to COLOR, otherwise we have to
+                 lookup STD_COLOR separately.  If it's impossible to lookup
+                 a standard color, we just give up and use TTY_COLOR.  */
+              if ((!STRINGP (XCAR (color_desc))
+                   || NILP (Fstring_equal (color, XCAR (color_desc))))
+                  && !NILP (Ffboundp (Qtty_color_standard_values)))
+                {
+                  /* Look up STD_COLOR separately.  */
+                  rgb = call1 (Qtty_color_standard_values, color);
+                  if (! parse_rgb_list (rgb, std_color))
+                    return 0;
+                }
+            }
+
+          return 1;
+        }
+      else if (NILP (Fsymbol_value (intern ("tty-defined-color-alist"))))
+        /* We were called early during startup, and the colors are not
+           yet set up in tty-defined-color-alist.  Don't return a failure
+           indication, since this produces the annoying "Unable to
+           load color" messages in the *Messages* buffer.  */
+        return 1;
+      else
+        /* tty-color-desc seems to have returned a bad value.  */
+        return 0;
+    }
 }
 
 /* A version of defined_color for non-X frames.  */
-- 
1.8.4




^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [RFC-2] Add tty True Color support.
  2013-10-16 22:39   ` [RFC-2] " Rüdiger Sonderfeld
@ 2013-10-17 16:56     ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2013-10-17 16:56 UTC (permalink / raw)
  To: Rüdiger Sonderfeld; +Cc: emacs-devel

> From: Rüdiger Sonderfeld <ruediger@c-plusplus.de>
> Cc: emacs-devel@gnu.org
> Date: Thu, 17 Oct 2013 00:39:23 +0200
> 
> > I might be missing something, but it looks like you didn't make any
> > changes aimed at having display-color-cells report the correct number
> > of colors for this type of terminal.  If that is true, please add some
> > code to fix that, otherwise various parts in Emacs might behave
> > incorrectly; for starters, defface's that define colors based on how
> > many colors are available will use the wrong colors.
> 
> I changed `tty-display-color-cells' to return the correct number.  See the
> updated patch below.

Thanks.

> Do you have any suggestion how to do the terminal detection?  So far Thomas
> Dickey seems to be reluctant to add support to terminfo.  Maybe there could
> be a lisp function to detect it, which could be easily adjusted by the user.
> But then again `init_tty' can be called very early in the start up process.

Can you do something similar to what terminal-init-xterm does for
xterm?




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] Add tty True Color support.
  2013-10-15 17:24 [RFC] Add tty True Color support Rüdiger Sonderfeld
  2013-10-16 19:45 ` Eli Zaretskii
@ 2014-01-07 21:02 ` egmont
  2014-01-07 23:18   ` Rüdiger Sonderfeld
  2014-07-02 13:38 ` Judge_Dredd
  2 siblings, 1 reply; 8+ messages in thread
From: egmont @ 2014-01-07 21:02 UTC (permalink / raw)
  To: Emacs-devel

Hi Rüdiger,

How's your patch going? I'd love to see true color support getting widely
adopted, in order to get there we'd need support from quite a few terminals
and killer apps.

Gnome-terminal is expected to get true color support in a couple of days,
see https://bugzilla.gnome.org/show_bug.cgi?id=704449 for progress. As long
as there's no proper terminfo support, you can check for $VTE_VERSION which
should contain 3600 or higher.

thanks,
egmont



--
View this message in context: http://emacs.1067599.n5.nabble.com/RFC-Add-tty-True-Color-support-tp299962p308962.html
Sent from the Emacs - Dev mailing list archive at Nabble.com.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] Add tty True Color support.
  2014-01-07 21:02 ` [RFC] " egmont
@ 2014-01-07 23:18   ` Rüdiger Sonderfeld
  2015-06-23 11:47     ` Judge_Dredd
  0 siblings, 1 reply; 8+ messages in thread
From: Rüdiger Sonderfeld @ 2014-01-07 23:18 UTC (permalink / raw)
  To: emacs-devel; +Cc: egmont, Emacs-devel

Hi Egmont,

I still plan on finishing this patch.  But while Emacs is in Feature Freeze 
for the 24.4 release the development of this patch is frozen as well.  I still 
have to figure out some details about where to reliably detect true color 
support.

Thanks for the interest in the patch and writing the Gnome-terminal support!

Regards,
Rüdiger

On Tuesday 07 January 2014 13:02:05 egmont wrote:
> Hi Rüdiger,
> 
> How's your patch going? I'd love to see true color support getting widely
> adopted, in order to get there we'd need support from quite a few terminals
> and killer apps.
> 
> Gnome-terminal is expected to get true color support in a couple of days,
> see https://bugzilla.gnome.org/show_bug.cgi?id=704449 for progress. As long
> as there's no proper terminfo support, you can check for $VTE_VERSION which
> should contain 3600 or higher.
> 
> thanks,
> egmont
> 
> 
> 
> --
> View this message in context:
> http://emacs.1067599.n5.nabble.com/RFC-Add-tty-True-Color-support-tp299962p
> 308962.html Sent from the Emacs - Dev mailing list archive at Nabble.com.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] Add tty True Color support.
  2013-10-15 17:24 [RFC] Add tty True Color support Rüdiger Sonderfeld
  2013-10-16 19:45 ` Eli Zaretskii
  2014-01-07 21:02 ` [RFC] " egmont
@ 2014-07-02 13:38 ` Judge_Dredd
  2 siblings, 0 replies; 8+ messages in thread
From: Judge_Dredd @ 2014-07-02 13:38 UTC (permalink / raw)
  To: Emacs-devel

Thank you for your work, I'd like to see tty true color support in emacs very
much!



--
View this message in context: http://emacs.1067599.n5.nabble.com/RFC-Add-tty-True-Color-support-tp299962p325950.html
Sent from the Emacs - Dev mailing list archive at Nabble.com.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] Add tty True Color support.
  2014-01-07 23:18   ` Rüdiger Sonderfeld
@ 2015-06-23 11:47     ` Judge_Dredd
  0 siblings, 0 replies; 8+ messages in thread
From: Judge_Dredd @ 2015-06-23 11:47 UTC (permalink / raw)
  To: Emacs-devel

Hello. What's the status of true color for Emacs? More and more programs and
terminals are supporting true color these days:
https://gist.github.com/XVilka/8346728



--
View this message in context: http://emacs.1067599.n5.nabble.com/RFC-Add-tty-True-Color-support-tp299962p361622.html
Sent from the Emacs - Dev mailing list archive at Nabble.com.



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-06-23 11:47 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-15 17:24 [RFC] Add tty True Color support Rüdiger Sonderfeld
2013-10-16 19:45 ` Eli Zaretskii
2013-10-16 22:39   ` [RFC-2] " Rüdiger Sonderfeld
2013-10-17 16:56     ` Eli Zaretskii
2014-01-07 21:02 ` [RFC] " egmont
2014-01-07 23:18   ` Rüdiger Sonderfeld
2015-06-23 11:47     ` Judge_Dredd
2014-07-02 13:38 ` Judge_Dredd

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.