[Xfce4-commits] [apps/xfce4-terminal] 01/01: Add command line options for setting text (foreground) and backround colors

noreply at xfce.org noreply at xfce.org
Sun Apr 15 03:57:23 CEST 2018


This is an automated email from the git hooks/post-receive script.

f   2   4   0   4       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-terminal.

commit ea503ad545b815f8f9642f53d404cf082c3ed55d
Author: Igor <f2404 at yandex.ru>
Date:   Sat Apr 14 21:51:45 2018 -0400

    Add command line options for setting text (foreground) and backround colors
    
    The options are --color-text and --color-bg, respectively.
    The options parameters should describe a color per the following specification:
    https://developer.gnome.org/gdk3/stable/gdk3-RGBA-Colors.html#gdk-rgba-parse
    
    Fixes bug #4887
---
 terminal/terminal-options.c | 42 +++++++++++++++++++++++++++++++++++++++++-
 terminal/terminal-options.h |  2 ++
 terminal/terminal-screen.c  | 25 ++++++++++++++++++++++---
 3 files changed, 65 insertions(+), 4 deletions(-)

diff --git a/terminal/terminal-options.c b/terminal/terminal-options.c
index 9b9f3df..b3dd63f 100644
--- a/terminal/terminal-options.c
+++ b/terminal/terminal-options.c
@@ -137,6 +137,8 @@ terminal_tab_attr_free (TerminalTabAttr *attr)
   g_free (attr->directory);
   g_free (attr->title);
   g_free (attr->initial_title);
+  g_free (attr->color_text);
+  g_free (attr->color_bg);
   g_slice_free (TerminalTabAttr, attr);
 }
 
@@ -355,13 +357,51 @@ terminal_window_attr_parse (gint              argc,
         {
           tab_attr->active = TRUE;
         }
+      else if (terminal_option_cmp ("color-text", 0, argc, argv, &n, &s))
+        {
+          GdkRGBA color;
+          if (G_UNLIKELY (s == NULL))
+            {
+              g_set_error (error, G_SHELL_ERROR, G_SHELL_ERROR_FAILED,
+                           _("Option \"--color-text\" requires specifying "
+                             "the color as its parameter"));
+              goto failed;
+            }
+          else if (!gdk_rgba_parse (&color, s))
+            {
+              g_set_error (error, G_SHELL_ERROR, G_SHELL_ERROR_FAILED,
+                           _("Unable to parse color: %s"), s);
+              goto failed;
+            }
+          g_free (tab_attr->color_text);
+          tab_attr->color_text = g_strdup (s);
+        }
+      else if (terminal_option_cmp ("color-bg", 0, argc, argv, &n, &s))
+        {
+          GdkRGBA color;
+          if (G_UNLIKELY (s == NULL))
+            {
+              g_set_error (error, G_SHELL_ERROR, G_SHELL_ERROR_FAILED,
+                           _("Option \"--color-bg\" requires specifying "
+                             "the color as its parameter"));
+              goto failed;
+            }
+          else if (!gdk_rgba_parse (&color, s))
+            {
+              g_set_error (error, G_SHELL_ERROR, G_SHELL_ERROR_FAILED,
+                           _("Unable to parse color: %s"), s);
+              goto failed;
+            }
+          g_free (tab_attr->color_bg);
+          tab_attr->color_bg = g_strdup (s);
+        }
       else if (terminal_option_cmp ("display", 0, argc, argv, &n, &s))
         {
           if (G_UNLIKELY (s == NULL))
             {
               g_set_error (error, G_SHELL_ERROR, G_SHELL_ERROR_FAILED,
                            _("Option \"--display\" requires specifying "
-                             "the X display as its parameters"));
+                             "the X display as its parameter"));
               goto failed;
             }
           else
diff --git a/terminal/terminal-options.h b/terminal/terminal-options.h
index d4d676c..2358382 100644
--- a/terminal/terminal-options.h
+++ b/terminal/terminal-options.h
@@ -58,6 +58,8 @@ typedef struct
   gchar        *directory;
   gchar        *title;
   gchar        *initial_title;
+  gchar        *color_text;
+  gchar        *color_bg;
   TerminalTitle dynamic_title_mode;
   guint         hold : 1;
   guint         active : 1;
diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c
index fe03ce3..63e868d 100644
--- a/terminal/terminal-screen.c
+++ b/terminal/terminal-screen.c
@@ -186,6 +186,9 @@ struct _TerminalScreen
   gchar               *custom_title;
   gchar               *initial_title;
 
+  gchar               *custom_fg_color;
+  gchar               *custom_bg_color;
+
   TerminalTitle        dynamic_title_mode;
   guint                hold : 1;
 #if !VTE_CHECK_VERSION (0, 51, 1)
@@ -371,6 +374,8 @@ terminal_screen_finalize (GObject *object)
   g_free (screen->working_directory);
   g_free (screen->custom_title);
   g_free (screen->initial_title);
+  g_free (screen->custom_fg_color);
+  g_free (screen->custom_bg_color);
 
   (*G_OBJECT_CLASS (terminal_screen_parent_class)->finalize) (object);
 }
@@ -1043,11 +1048,18 @@ terminal_screen_update_colors (TerminalScreen *screen)
       valid_palette = (n == 16);
     }
 
-  has_bg = terminal_preferences_get_color (screen->preferences, "color-background", &bg);
-  has_fg = terminal_preferences_get_color (screen->preferences, "color-foreground", &fg);
+  if (G_LIKELY (screen->custom_bg_color == NULL))
+    has_bg = terminal_preferences_get_color (screen->preferences, "color-background", &bg);
+  else
+    has_bg = gdk_rgba_parse (&bg, screen->custom_bg_color);
+
+  if (G_LIKELY (screen->custom_fg_color == NULL))
+    has_fg = terminal_preferences_get_color (screen->preferences, "color-foreground", &fg);
+  else
+    has_fg = gdk_rgba_parse (&fg, screen->custom_fg_color);
 
   /* we pick a random hue value to keep readability */
-  if (vary_bg && has_bg)
+  if (G_LIKELY (screen->custom_bg_color == NULL) && vary_bg && has_bg)
     {
       gtk_rgb_to_hsv (bg.red, bg.green, bg.blue,
                       NULL, &hsv[HSV_SATURATION], &hsv[HSV_VALUE]);
@@ -1755,6 +1767,13 @@ terminal_screen_new (TerminalTabAttr *attr,
   screen->hold = attr->hold;
   vte_terminal_set_size (VTE_TERMINAL (screen->terminal), columns, rows);
 
+  if (attr->color_text != NULL)
+    screen->custom_fg_color = g_strdup (attr->color_text);
+  if (attr->color_bg != NULL)
+    screen->custom_bg_color = g_strdup (attr->color_bg);
+  if (attr->color_text != NULL || attr->color_bg != NULL)
+    terminal_screen_update_colors (screen);
+
   return screen;
 }
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list