From a4c07c9b90007bbacd2362d0ff2b145907761fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Emre=20=C3=87epo=C4=9Flu?= Date: Thu, 23 Jan 2014 18:26:05 +0200 Subject: [PATCH 1/4] removed 'nocolor' option. Added 'color' option that takes (auto|never|always) instead. --- mu/mu-config.c | 27 ++++++++++++++++++++++----- mu/mu-config.h | 10 ++++++++-- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/mu/mu-config.c b/mu/mu-config.c index 5af1ccb72..573f5fee9 100644 --- a/mu/mu-config.c +++ b/mu/mu-config.c @@ -79,13 +79,30 @@ set_group_mu_defaults (void) /* check for the MU_NOCOLOR env var; but in any case don't * use colors unless we're writing to a tty */ - if (g_getenv (MU_NOCOLOR) != NULL) - MU_CONFIG.nocolor = TRUE; - if (!isatty(fileno(stdout)) || !isatty(fileno(stderr))) + if( MU_CONFIG.color == MuColorOpt_always) + MU_CONFIG.nocolor= FALSE; + else if( MU_CONFIG.color == MuColorOpt_never) + MU_CONFIG.nocolor = TRUE; + else if (!isatty(fileno(stdout)) || !isatty(fileno(stderr))) + MU_CONFIG.nocolor = TRUE; + else if (g_getenv (MU_NOCOLOR) != NULL) MU_CONFIG.nocolor = TRUE; } +static gboolean config_options_set_color (const gchar *option_name, const gchar *value, gpointer data, GError **error) +{ + if( g_strcmp0( value, "never") == 0) + MU_CONFIG.color = MuColorOpt_never; + else if( g_strcmp0( value, "auto") == 0) + MU_CONFIG.color = MuColorOpt_auto; + else if( g_strcmp0( value, "always") == 0) + MU_CONFIG.color = MuColorOpt_always; + else + return FALSE; + return TRUE; +} + static GOptionGroup* config_options_group_mu (void) { @@ -101,8 +118,8 @@ config_options_group_mu (void) "specify an alternative mu directory", ""}, {"log-stderr", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.log_stderr, "log to standard error (false)", NULL}, - {"nocolor", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.nocolor, - "don't use ANSI-colors in output (false)", NULL}, + {"color", 0, 0, G_OPTION_ARG_CALLBACK, &config_options_set_color, + "colorize output (never|auto|always)", ""}, {"verbose", 'v', 0, G_OPTION_ARG_NONE, &MU_CONFIG.verbose, "verbose output (false)", NULL}, diff --git a/mu/mu-config.h b/mu/mu-config.h index a45072a52..d30c2cda3 100644 --- a/mu/mu-config.h +++ b/mu/mu-config.h @@ -86,6 +86,12 @@ typedef enum _MuConfigCmd MuConfigCmd; ((C) > MU_CONFIG_CMD_UNKNOWN && (C) < MU_CONFIG_CMD_NONE) +enum MuColorOpt { + MuColorOpt_auto, + MuColorOpt_never, + MuColorOpt_always +}; + /* struct with all configuration options for mu; it will be filled * from the config file, and/or command line arguments */ @@ -102,8 +108,8 @@ struct _MuConfig { gboolean version; /* request mu version */ gboolean log_stderr; /* log to stderr (not logfile) */ gchar** params; /* parameters (for querying) */ - gboolean nocolor; /* don't use use ansi-colors - * in some output */ + enum MuColorOpt color; /* colorize output (enum)*/ + gboolean nocolor; /* colorize output (boolean)*/ gboolean verbose; /* verbose output */ /* options for indexing */ From cd6e21bfab10141270896416c7593839d746b2b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Emre=20=C3=87epo=C4=9Flu?= Date: Thu, 30 Jan 2014 14:29:48 +0200 Subject: [PATCH 2/4] main man page updated --- man/mu.1 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/man/mu.1 b/man/mu.1 index 105694861..c41ecd11f 100644 --- a/man/mu.1 +++ b/man/mu.1 @@ -111,13 +111,14 @@ for extract MIME-parts (such as attachments) from messages. See .SH COLORS -Some \fBmu\fR sub-commands support colorized output. If you don't want this, -you can use the \fI--nocolor\fR/ option to disable it. Even then, colors will -only be shown when output goes to a sufficiently capable terminal (this roughly -mirrors the \fI--color=auto\fR of the GNU-version of the \fBls\fR-command). - -Instead of the \fI--color\fR/, you can also set the \fBMU_NOCOLOR\fR -environment variable to non-empty to disable colors. +Some \fBmu\fR sub-commands support colorized output using the \fB--color\fR option. This option mimics the +behaviour of same option in the GNU-version of \fBls\fR-command : +With \fI"--color=auto"\fR, output is colorized only when stardard output is +connected to a terminal. +\fI--color=never\fR doesn't print colorized output in any case, +and \fI--color=always\fR will always print colors. + +The default value is \fI--color=always\fR. Currently, \fBmu find\fR, \fBmu view\fR, \fBmu cfind\fR and \fBmu extract\fR support colors. From 321bf4946003c118773bba573502ee82b017f45b Mon Sep 17 00:00:00 2001 From: ahmet emre Date: Thu, 30 Jan 2014 19:05:59 +0200 Subject: [PATCH 3/4] 'color' variable no longer used. Default color value is 'always'. --- mu/mu-config.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/mu/mu-config.c b/mu/mu-config.c index 573f5fee9..e48f22a08 100644 --- a/mu/mu-config.c +++ b/mu/mu-config.c @@ -76,28 +76,20 @@ set_group_mu_defaults (void) g_free(MU_CONFIG.muhome); MU_CONFIG.muhome = exp; } - - /* check for the MU_NOCOLOR env var; but in any case don't - * use colors unless we're writing to a tty */ - - if( MU_CONFIG.color == MuColorOpt_always) - MU_CONFIG.nocolor= FALSE; - else if( MU_CONFIG.color == MuColorOpt_never) - MU_CONFIG.nocolor = TRUE; - else if (!isatty(fileno(stdout)) || !isatty(fileno(stderr))) - MU_CONFIG.nocolor = TRUE; - else if (g_getenv (MU_NOCOLOR) != NULL) - MU_CONFIG.nocolor = TRUE; } -static gboolean config_options_set_color (const gchar *option_name, const gchar *value, gpointer data, GError **error) +static gboolean +config_options_set_color (const gchar *option_name, + const gchar *value, + gpointer data, + GError **error) { if( g_strcmp0( value, "never") == 0) - MU_CONFIG.color = MuColorOpt_never; - else if( g_strcmp0( value, "auto") == 0) - MU_CONFIG.color = MuColorOpt_auto; + MU_CONFIG.nocolor = TRUE; + else if( g_strcmp0( value, "auto") == 0) + MU_CONFIG.nocolor = (!isatty(fileno(stdout)) || !isatty(fileno(stderr))); else if( g_strcmp0( value, "always") == 0) - MU_CONFIG.color = MuColorOpt_always; + MU_CONFIG.nocolor = FALSE; else return FALSE; return TRUE; From 9eeec082007889c672363afdf4163fd0056acf2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Emre=20=C3=87epo=C4=9Flu?= Date: Fri, 31 Jan 2014 10:39:51 +0200 Subject: [PATCH 4/4] color var removed entirely --- mu/mu-config.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mu/mu-config.h b/mu/mu-config.h index d30c2cda3..f14ad73a6 100644 --- a/mu/mu-config.h +++ b/mu/mu-config.h @@ -86,12 +86,6 @@ typedef enum _MuConfigCmd MuConfigCmd; ((C) > MU_CONFIG_CMD_UNKNOWN && (C) < MU_CONFIG_CMD_NONE) -enum MuColorOpt { - MuColorOpt_auto, - MuColorOpt_never, - MuColorOpt_always -}; - /* struct with all configuration options for mu; it will be filled * from the config file, and/or command line arguments */ @@ -108,8 +102,8 @@ struct _MuConfig { gboolean version; /* request mu version */ gboolean log_stderr; /* log to stderr (not logfile) */ gchar** params; /* parameters (for querying) */ - enum MuColorOpt color; /* colorize output (enum)*/ - gboolean nocolor; /* colorize output (boolean)*/ + gboolean nocolor; /* don't use use ansi-colors + * in some output */ gboolean verbose; /* verbose output */ /* options for indexing */