[gnome-online-accounts] Add --no-color option to suppress color output



commit d9efcec55a3173cc9647b74d8f5c7e0a0954e08c
Author: Stef Walter <stefw gnome org>
Date:   Tue Jan 22 13:10:31 2013 +0100

    Add --no-color option to suppress color output
    
    https://bugzilla.gnome.org/show_bug.cgi?id=692284

 src/daemon/main.c           |    3 +++
 src/goabackend/goalogging.c |   15 ++++++++-------
 src/goabackend/goalogging.h |    2 ++
 3 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/src/daemon/main.c b/src/daemon/main.c
index 4eeaafc..73068fd 100644
--- a/src/daemon/main.c
+++ b/src/daemon/main.c
@@ -38,10 +38,12 @@
 static GMainLoop *loop = NULL;
 static gboolean opt_replace = FALSE;
 static gboolean opt_no_sigint = FALSE;
+static gboolean opt_no_color = FALSE;
 static GOptionEntry opt_entries[] =
 {
   {"replace", 0, 0, G_OPTION_ARG_NONE, &opt_replace, "Replace existing daemon", NULL},
   {"no-sigint", 0, 0, G_OPTION_ARG_NONE, &opt_no_sigint, "Do not handle SIGINT for controlled shutdown", NULL},
+  {"no-color", 0, 0, G_OPTION_ARG_NONE, &opt_no_color, "Do not display colors in output", NULL},
   {NULL }
 };
 static GoaDaemon *the_daemon = NULL;
@@ -107,6 +109,7 @@ main (int    argc,
       goto out;
     }
 
+  goa_log_init (opt_no_color);
   goa_notice ("goa-daemon version %s starting", PACKAGE_VERSION);
 
   loop = g_main_loop_new (NULL, FALSE);
diff --git a/src/goabackend/goalogging.c b/src/goabackend/goalogging.c
index 2f39eb8..c1b6acd 100644
--- a/src/goabackend/goalogging.c
+++ b/src/goabackend/goalogging.c
@@ -69,16 +69,19 @@ typedef enum
   _COLOR_BG_WHITE
 } _Color;
 
-static gboolean _color_stdin_is_tty = FALSE;
+static gboolean _color_output = FALSE;
 static gboolean _color_initialized = FALSE;
 
-static void
-_color_init (void)
+void
+goa_log_init (gboolean no_color)
 {
   if (_color_initialized)
     return;
   _color_initialized = TRUE;
-  _color_stdin_is_tty = (isatty (STDIN_FILENO) != 0 && isatty (STDOUT_FILENO) != 0);
+  if (no_color)
+    _color_output = FALSE;
+  else
+    _color_output = (isatty (STDIN_FILENO) != 0 && isatty (STDOUT_FILENO) != 0);
 }
 
 static const gchar *
@@ -86,9 +89,7 @@ _color_get (_Color color)
 {
   const gchar *str;
 
-  _color_init ();
-
-  if (!_color_stdin_is_tty)
+  if (!_color_output)
     return "";
 
   str = NULL;
diff --git a/src/goabackend/goalogging.h b/src/goabackend/goalogging.h
index b07c7b1..a7edff1 100644
--- a/src/goabackend/goalogging.h
+++ b/src/goabackend/goalogging.h
@@ -31,6 +31,8 @@
 
 G_BEGIN_DECLS
 
+void goa_log_init (gboolean no_colors);
+
 void goa_log (GoaLogLevel     level,
               const gchar    *function,
               const gchar    *location,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]