billiob pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=196973fcd30479381c9502dc80ee1021d216aaec

commit 196973fcd30479381c9502dc80ee1021d216aaec
Author: Boris Faure <[email protected]>
Date:   Mon Jun 22 23:41:27 2020 +0200

    rewrite changing of background/foreground colors from escape codes
---
 src/bin/termio.c          | 101 +++++++++++++++++++++++++++++++++++++++++-
 src/bin/termio.h          |   8 ++++
 src/bin/termiointernals.h |   6 +++
 src/bin/termpty.c         |  31 -------------
 src/bin/termptyesc.c      | 109 ++++++++++++++++++++++++++++------------------
 src/bin/termptyops.c      |   1 +
 src/bin/tytest_common.c   |  37 +++++++++++++---
 7 files changed, 213 insertions(+), 80 deletions(-)

diff --git a/src/bin/termio.c b/src/bin/termio.c
index 3059903..64c4f57 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -76,7 +76,47 @@ termio_theme_set(Evas_Object *obj, Evas_Object *theme)
 {
    Termio *sd = evas_object_smart_data_get(obj);
    EINA_SAFETY_ON_NULL_RETURN(sd);
-   if (theme) sd->theme = theme;
+   EINA_SAFETY_ON_NULL_RETURN(sd->grid.obj);
+   EINA_SAFETY_ON_NULL_RETURN(theme);
+
+   sd->theme = theme;
+
+   termio_color_class_get(obj, "BG",
+                          &sd->saved_bg.r,
+                          &sd->saved_bg.g,
+                          &sd->saved_bg.b,
+                          &sd->saved_bg.a);
+   evas_object_textgrid_palette_get(
+      sd->grid.obj,
+      EVAS_TEXTGRID_PALETTE_STANDARD, 0,
+      &sd->saved_fg.r,
+      &sd->saved_fg.g,
+      &sd->saved_fg.b,
+      &sd->saved_fg.a);
+}
+
+void
+termio_reset_main_colors(Evas_Object *termio)
+{
+   if (termio)
+     {
+        Termio *sd = evas_object_smart_data_get(termio);
+        EINA_SAFETY_ON_NULL_RETURN(sd);
+        EINA_SAFETY_ON_NULL_RETURN(sd->grid.obj);
+
+        termio_color_class_set(termio, "BG",
+                               sd->saved_bg.r,
+                               sd->saved_bg.g,
+                               sd->saved_bg.b,
+                               sd->saved_bg.a);
+        evas_object_textgrid_palette_set(
+           sd->grid.obj,
+           EVAS_TEXTGRID_PALETTE_STANDARD, 0,
+           sd->saved_fg.r,
+           sd->saved_fg.g,
+           sd->saved_fg.b,
+           sd->saved_fg.a);
+     }
 }
 
 void
@@ -4144,3 +4184,62 @@ termio_key_down(Evas_Object *termio,
      edje_object_signal_emit(sd->cursor.obj, "key,down", "terminology");
    ev->event_flags = EVAS_EVENT_FLAG_ON_HOLD;
 }
+
+int
+termio_color_class_get(Evas_Object *termio, const char *key,
+                       int *r, int *g, int *b, int *a)
+{
+   Termio *sd = evas_object_smart_data_get(termio);
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(sd, -1);
+
+   if (sd->term)
+     {
+        Evas_Object *bg = term_bg_get(sd->term);
+        if (!edje_object_color_class_get(bg, key,
+                                         r,
+                                         g,
+                                         b,
+                                         a,
+                                         NULL, NULL, NULL, NULL,
+                                         NULL, NULL, NULL, NULL))
+          {
+             ERR("color class '%s' not found in theme", key);
+             return -1;
+          }
+     }
+   else
+     {
+        ERR("term not found");
+        return -1;
+     }
+   return 0;
+}
+
+int
+termio_color_class_set(Evas_Object *termio, const char *key,
+                       int r, int g, int b, int a)
+{
+   Termio *sd = evas_object_smart_data_get(termio);
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(sd, -1);
+
+   if (sd->term)
+     {
+        Evas_Object *bg = term_bg_get(sd->term);
+        if (!edje_object_color_class_set(bg, key,
+                                         r, g, b, a,
+                                         r, g, b, a,
+                                         r, g, b, a))
+          {
+             ERR("can not set color class '%s'", key);
+             return -1;
+          }
+     }
+   else
+     {
+        ERR("term not found");
+        return -1;
+     }
+   return 0;
+}
diff --git a/src/bin/termio.h b/src/bin/termio.h
index 9b7315d..715b107 100644
--- a/src/bin/termio.h
+++ b/src/bin/termio.h
@@ -82,4 +82,12 @@ void
 termio_block_activate(Evas_Object *obj, Termblock *blk);
 const char *
 term_preedit_str_get(Term *term);
+int
+termio_color_class_get(Evas_Object *termio, const char *key,
+                       int *r, int *g, int *b, int *a);
+int
+termio_color_class_set(Evas_Object *termio, const char *key,
+                       int r, int g, int b, int a);
+void
+termio_reset_main_colors(Evas_Object *termio);
 #endif
diff --git a/src/bin/termiointernals.h b/src/bin/termiointernals.h
index 4c6196e..3aacc21 100644
--- a/src/bin/termiointernals.h
+++ b/src/bin/termiointernals.h
@@ -59,6 +59,12 @@ struct _Termio
       unsigned long long total, size;
       Eina_Bool active : 1;
    } sendfile;
+   struct {
+        int r;
+        int g;
+        int b;
+        int a;
+   } saved_bg, saved_fg;
    Evas_Object *ctxpopup;
    int zoom_fontsize_start;
    int scroll;
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 32405e1..841ae47 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -1778,34 +1778,3 @@ term_link_free(Termpty *ty, Term_Link *link)
    /* Remove from bitmap */
    hl_bitmap_clear_bit(ty, id);
 }
-#if !defined(BINARY_TYFUZZ) && !defined(BINARY_TYTEST)
-int
-termpty_color_class_get(Termpty *ty, const char *key,
-                        int *r, int *g, int *b, int *a)
-{
-   Term *term;
-
-   term = termio_term_get(ty->obj);
-   if (term)
-     {
-        Evas_Object *bg = term_bg_get(term);
-        if (!edje_object_color_class_get(bg, key,
-                                         r,
-                                         g,
-                                         b,
-                                         a,
-                                         NULL, NULL, NULL, NULL,
-                                         NULL, NULL, NULL, NULL))
-          {
-             ERR("color class BG not found in theme");
-             return -1;
-          }
-     }
-   else
-     {
-        ERR("term not found");
-        return -1;
-     }
-   return 0;
-}
-#endif
diff --git a/src/bin/termptyesc.c b/src/bin/termptyesc.c
index 3cb9359..0d02afe 100644
--- a/src/bin/termptyesc.c
+++ b/src/bin/termptyesc.c
@@ -3880,28 +3880,77 @@ _handle_xterm_777_command(Termpty *ty,
 }
 
 static void
-_handle_xterm_11_command(Termpty *ty, Eina_Unicode *p)
+_handle_xterm_10_command(Termpty *ty, Eina_Unicode *p, int len)
 {
-   int r = 0, g = 0, b = 0;
-   char buf[32];
-   size_t l;
-
-   if (!*p)
+   if (!p || !*p)
      goto err;
+   if (*p == '?')
+     {
+        int r, g, b;
+        char bf[7];
+#if !defined(BINARY_TYFUZZ) && !defined(BINARY_TYTEST)
+        evas_object_textgrid_palette_get(
+           termio_textgrid_get(ty->obj),
+           EVAS_TEXTGRID_PALETTE_STANDARD, 0,
+           &r, &g, &b, NULL);
+#else
+        Config *config = termio_config_get(ty->obj);
+        r = config->colors[0].r;
+        g = config->colors[0].g;
+        b = config->colors[0].b;
+#endif
+        TERMPTY_WRITE_STR("\033]10;#");
+        snprintf(bf, sizeof(bf), "%.2X%.2X%.2X", r, g, b);
+        termpty_write(ty, bf, 6);
+        TERMPTY_WRITE_STR("\007");
+     }
+   else
+     {
+        unsigned char r, g, b;
+        if (_xterm_parse_color(ty, &p, &r, &g, &b, len) < 0)
+          goto err;
+#if !defined(BINARY_TYFUZZ) && !defined(BINARY_TYTEST)
+        evas_object_textgrid_palette_set(
+           termio_textgrid_get(ty->obj),
+           EVAS_TEXTGRID_PALETTE_STANDARD, 0,
+           r, g, b, 0xff);
+#endif
+     }
+   return;
+err:
+   ty->decoding_error = EINA_TRUE;
+}
 
-   /* only support query mode for the moment */
-   if (*p != '?')
+static void
+_handle_xterm_11_command(Termpty *ty, Eina_Unicode *p, int len)
+{
+
+   if (!*p || !*p)
      goto err;
 
-   if (termpty_color_class_get(ty, "BG", &r, &g, &b, NULL) != 0)
+   if (*p == '?')
      {
-        ERR("error getting color class 'BG'");
+        int r = 0, g = 0, b = 0;
+        char buf[32];
+        size_t l;
+
+        if (termio_color_class_get(ty->obj, "BG", &r, &g, &b, NULL) != 0)
+          {
+             ERR("error getting color class 'BG'");
+          }
+        TERMPTY_WRITE_STR("\033]11;rgb:");
+        l = snprintf(buf, sizeof(buf), "%.2x%.2x/%.2x%.2x/%.2x%.2x",
+                     r, r, g, g, b, b);
+        termpty_write(ty, buf, l);
+        TERMPTY_WRITE_STR("\033\\");
+     }
+   else
+     {
+        unsigned char r, g, b;
+        if (_xterm_parse_color(ty, &p, &r, &g, &b, len) < 0)
+          goto err;
+        termio_color_class_set(ty->obj, "BG", r, g, b, 0xff);
      }
-   TERMPTY_WRITE_STR("\033]11;rgb:");
-   l = snprintf(buf, sizeof(buf), "%.2x%.2x/%.2x%.2x/%.2x%.2x",
-                r, r, g, g, b, b);
-   termpty_write(ty, buf, l);
-   TERMPTY_WRITE_STR("\033\\");
 
    return;
 err:
@@ -4026,38 +4075,12 @@ _handle_esc_osc(Termpty *ty, const Eina_Unicode *c, 
const Eina_Unicode *ce)
         _handle_hyperlink(ty, s, len);
         break;
       case 10:
-        if (!p || !*p)
-          goto err;
-        if (*p == '?')
-          {
-             char bf[7];
-             Config *config = termio_config_get(ty->obj);
-             TERMPTY_WRITE_STR("\033]10;#");
-             snprintf(bf, sizeof(bf), "%.2X%.2X%.2X",
-                      config->colors[0].r,
-                      config->colors[0].g,
-                      config->colors[0].b);
-             termpty_write(ty, bf, 6);
-             TERMPTY_WRITE_STR("\007");
-          }
-        else
-          {
-             unsigned char r, g, b;
-             len = cc - c - (p - buf);
-             if (_xterm_parse_color(ty, &p, &r, &g, &b, len) < 0)
-               goto err;
-#if !defined(BINARY_TYFUZZ) && !defined(BINARY_TYTEST)
-             evas_object_textgrid_palette_set(
-                termio_textgrid_get(ty->obj),
-                EVAS_TEXTGRID_PALETTE_STANDARD, 0,
-                r, g, b, 0xff);
-#endif
-          }
+        _handle_xterm_10_command(ty, p, cc - c - (p - buf));
         break;
       case 11:
         if (!p || !*p)
           goto err;
-        _handle_xterm_11_command(ty, p);
+        _handle_xterm_11_command(ty, p, cc - c - (p - buf));
         break;
       case 50:
         DBG("xterm font support");
diff --git a/src/bin/termptyops.c b/src/bin/termptyops.c
index 5bcbe7b..5ef0cb2 100644
--- a/src/bin/termptyops.c
+++ b/src/bin/termptyops.c
@@ -455,6 +455,7 @@ termpty_soft_reset_state(Termpty *ty)
    ty->mouse_ext = MOUSE_EXT_NONE;
    ty->bracketed_paste = 0;
 
+   termio_reset_main_colors(ty->obj);
    termpty_clear_tabs_on_screen(ty);
    for (i = 0; i < ty->w; i += TAB_WIDTH)
      {
diff --git a/src/bin/tytest_common.c b/src/bin/tytest_common.c
index e4a28cc..6cbfa91 100644
--- a/src/bin/tytest_common.c
+++ b/src/bin/tytest_common.c
@@ -43,6 +43,10 @@ static Termio _sd = {
      .pty = &_ty,
      .config = NULL,
 };
+static int _bg_r = 131;
+static int _bg_g = 132;
+static int _bg_b = 133;
+static int _bg_a = 134;
 static const char *_cursor_shape = "undefined";
 #if defined(BINARY_TYTEST)
 static Evas_Textgrid_Cell *_cells;
@@ -270,23 +274,46 @@ termio_set_cursor_shape(Evas_Object *obj EINA_UNUSED,
 
 
 int
-termpty_color_class_get(Termpty *ty EINA_UNUSED, const char *key,
+termio_color_class_get(Evas_Object *termio EINA_UNUSED, const char *key,
                         int *r, int *g, int *b, int *a)
 {
    if (strncmp(key, "BG", strlen("BG")) == 0)
      {
         if (r)
-          *r = 131;
+          *r = _bg_r;
         if (g)
-          *g = 132;
+          *g = _bg_g;
         if (b)
-          *b = 133;
+          *b = _bg_b;
         if (a)
-          *a = 134;
+          *a = _bg_a;
         return 0;
      }
    return -1;
 }
+int
+termio_color_class_set(Evas_Object *termio EINA_UNUSED, const char *key,
+                       int r, int g, int b, int a)
+{
+   if (strncmp(key, "BG", strlen("BG")) == 0)
+     {
+        _bg_r = r;
+        _bg_g = g;
+        _bg_b = b;
+        _bg_a = a;
+        return 0;
+     }
+   return -1;
+}
+
+void
+termio_reset_main_colors(Evas_Object *termio EINA_UNUSED)
+{
+   _bg_r = 131;
+   _bg_g = 132;
+   _bg_b = 133;
+   _bg_a = 134;
+}
 
 Evas_Object *
 termio_textgrid_get(const Evas_Object *obj EINA_UNUSED)

-- 


Reply via email to