* make colorized output the default

- turn of with --nocolor, or by setting MU_NOCOLOR to non-empty
This commit is contained in:
djcb 2012-01-21 12:12:41 +02:00
parent 7538f20d60
commit b563128a4f
9 changed files with 144 additions and 90 deletions

View File

@ -1,4 +1,4 @@
.TH MU-EASY 1 "December 2011" "User Manuals"
.TH MU-EASY 1 "January 2012" "User Manuals"
.SH NAME
@ -19,6 +19,11 @@ that, such as \fBfind\fR), require that you store your mail in the
Maildir-format. If you don't do so, you can still use the other commands, but
you won't be able to index/search your mail.
By default, \fBmu\fR uses colorized output when your terminal is capable of
doing so. If you don't like color, you can use the \fB--nocolor\fR
command-line option, or set the \fBMU_NOCOLOR\fR environment variable to
non-empty.
.SH INDEXING YOUR E-MAIL
Before you can search e-mails, you'll first need to index them:

View File

@ -1,6 +1,6 @@
.TH MU 1 "May 2011" "User Manuals"
.TH MU 1 "January 2012" "User Manuals"
.SH NAME
.SH NAME
mu \- a set of tools to deal with Maildirs and message files, in particular to
index and search e-mail messages.
@ -98,14 +98,13 @@ for extract MIME-parts (such as attachments) from messages. See
.SH COLORS
Some \fBmu\fR sub-commands support colorized output. By default, this is
disabled, but you can use the \fI--color\fR/ option to enable it. Even that,
colors will only 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).
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 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_COLORS\fR
environment variable to non-empty to enable colors.
Instead of the \fI--color\fR/, you can also set the \fBMU_NOCOLOR\fR
environment variable to non-empty to disable colors.
Currently, \fBmu find\fR, \fBmu view\fR, \fBmu cfind\fR and \fBmu extract\fR
support colors.
@ -184,36 +183,36 @@ The various mu subcommands typically exit with 0 (zero) upon success, and
non-zero when some error occured. The table lists the various error codes.
.nf
exit code | error
exit code | error
----------+-------------------------------------------
1 | MU_ERROR
2 | MU_ERROR_IN_PARAMETERS
3 | MU_ERROR_INTERNAL
4 | MU_ERROR_NO_MATCHES
|
11 | MU_ERROR_XAPIAN
|
13 | MU_ERROR_XAPIAN_QUERY
14 | MU_ERROR_XAPIAN_DIR_NOT_ACCESSIBLE
15 | MU_ERROR_XAPIAN_NOT_UP_TO_DATE
16 | MU_ERROR_XAPIAN_MISSING_DATA
17 | MU_ERROR_XAPIAN_CORRUPTION
18 | MU_ERROR_XAPIAN_CANNOT_GET_WRITELOCK
30 | MU_ERROR_GMIME
|
50 | MU_ERROR_CONTACTS
51 | MU_ERROR_CONTACTS_CANNOT_RETRIEVE
|
70 | MU_ERROR_FILE
71 | MU_ERROR_FILE_INVALID_NAME
72 | MU_ERROR_FILE_CANNOT_LINK
73 | MU_ERROR_FILE_CANNOT_OPEN
74 | MU_ERROR_FILE_CANNOT_READ
75 | MU_ERROR_FILE_CANNOT_CREATE
76 | MU_ERROR_FILE_CANNOT_MKDIR
77 | MU_ERROR_FILE_STAT_FAILED
78 | MU_ERROR_FILE_READDIR_FAILED
79 | MU_ERROR_FILE_INVALID_SOURCE
1 | MU_ERROR
2 | MU_ERROR_IN_PARAMETERS
3 | MU_ERROR_INTERNAL
4 | MU_ERROR_NO_MATCHES
|
11 | MU_ERROR_XAPIAN
|
13 | MU_ERROR_XAPIAN_QUERY
14 | MU_ERROR_XAPIAN_DIR_NOT_ACCESSIBLE
15 | MU_ERROR_XAPIAN_NOT_UP_TO_DATE
16 | MU_ERROR_XAPIAN_MISSING_DATA
17 | MU_ERROR_XAPIAN_CORRUPTION
18 | MU_ERROR_XAPIAN_CANNOT_GET_WRITELOCK
30 | MU_ERROR_GMIME
|
50 | MU_ERROR_CONTACTS
51 | MU_ERROR_CONTACTS_CANNOT_RETRIEVE
|
70 | MU_ERROR_FILE
71 | MU_ERROR_FILE_INVALID_NAME
72 | MU_ERROR_FILE_CANNOT_LINK
73 | MU_ERROR_FILE_CANNOT_OPEN
74 | MU_ERROR_FILE_CANNOT_READ
75 | MU_ERROR_FILE_CANNOT_CREATE
76 | MU_ERROR_FILE_CANNOT_MKDIR
77 | MU_ERROR_FILE_STAT_FAILED
78 | MU_ERROR_FILE_READDIR_FAILED
79 | MU_ERROR_FILE_INVALID_SOURCE
.fi
.SH BUGS
@ -235,4 +234,4 @@ Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
.BR mu-view(1)
.BR mu-extract(1)
.BR mu-easy(1)
.BR mu-bookmarks(5)
.BR mu-bookmarks(5)

View File

@ -1,5 +1,5 @@
/*
** Copyright (C) 2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2011-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -239,6 +239,6 @@ mu_cmd_cfind (MuConfig *opts, GError **err)
return MU_ERROR_IN_PARAMETERS;
}
return run_cmd_cfind (opts->params[1], opts->format, opts->color,
err);
return run_cmd_cfind (opts->params[1], opts->format,
!opts->nocolor, err);
}

View File

@ -1,7 +1,7 @@
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/*
** Copyright (C) 2010-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2010-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -345,7 +345,7 @@ show_parts (const char* path, MuConfig *opts, GError **err)
mu_msg_part_foreach
(msg,(MuMsgPartForeachFunc)each_part_show,
GUINT_TO_POINTER(opts->color));
GUINT_TO_POINTER(!opts->nocolor));
mu_msg_unref (msg);

View File

@ -1,7 +1,7 @@
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/*
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -100,7 +100,7 @@ output_query_results (MuMsgIter *iter, MuConfig *opts, GError **err)
return output_links (iter, opts->linksdir, opts->clearlinks, err);
case MU_CONFIG_FORMAT_PLAIN:
return output_plain (iter, opts->fields, opts->summary,
opts->threads, opts->color,
opts->threads, !opts->nocolor,
opts->include_unreadable, err);
case MU_CONFIG_FORMAT_XML:
return output_xml (iter, opts->include_unreadable, err);

View File

@ -1,7 +1,7 @@
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/*
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -148,9 +148,8 @@ backspace (unsigned u)
}
static void
print_stats (MuIndexStats* stats, gboolean clear)
print_stats (MuIndexStats* stats, gboolean clear, gboolean color)
{
const char *kars="-\\|/";
char output[120];
@ -161,25 +160,49 @@ print_stats (MuIndexStats* stats, gboolean clear)
if (clear)
backspace (len);
len = (unsigned)snprintf (output, sizeof(output),
"%c processing mail; processed: %u; "
"updated/new: %u, cleaned-up: %u",
(unsigned)kars[++i % 4],
(unsigned)stats->_processed,
(unsigned)stats->_updated,
(unsigned)stats->_cleaned_up);
if (color)
len = (unsigned)snprintf
(output, sizeof(output),
MU_COLOR_BLUE "%c " MU_COLOR_DEFAULT
"processing mail; processed: "
MU_COLOR_GREEN "%u; " MU_COLOR_DEFAULT
"updated/new: "
MU_COLOR_GREEN "%u" MU_COLOR_DEFAULT
", cleaned-up: "
MU_COLOR_GREEN "%u" MU_COLOR_DEFAULT,
(unsigned)kars[++i % 4],
(unsigned)stats->_processed,
(unsigned)stats->_updated,
(unsigned)stats->_cleaned_up);
else
len = (unsigned)snprintf
(output, sizeof(output),
"%c "
"processing mail; processed: %u; "
"updated/new: %u, cleaned-up: %u",
(unsigned)kars[++i % 4],
(unsigned)stats->_processed,
(unsigned)stats->_updated,
(unsigned)stats->_cleaned_up);
fputs (output, stdout);
fflush (stdout);
}
struct _IndexData {
gboolean color;
};
typedef struct _IndexData IndexData;
static MuError
index_msg_cb (MuIndexStats* stats, void *user_data)
index_msg_cb (MuIndexStats* stats, IndexData *idata)
{
if (stats->_processed % 25)
return MU_OK;
print_stats (stats, TRUE);
print_stats (stats, TRUE, idata->color);
return MU_CAUGHT_SIGNAL ? MU_STOP: MU_OK;
}
@ -217,13 +240,28 @@ database_version_check_and_update (MuStore *store, MuConfig *opts,
static void
show_time (unsigned t, unsigned processed)
show_time (unsigned t, unsigned processed, gboolean color)
{
if (t)
g_message ("elapsed: %u second(s), ~ %u msg/s",
t, processed/t);
else
g_message ("elapsed: %u second(s)", t);
if (color) {
if (t)
g_message ("elapsed: "
MU_COLOR_GREEN "%u" MU_COLOR_DEFAULT
" second(s), ~ "
MU_COLOR_GREEN "%u" MU_COLOR_DEFAULT
" msg/s",
t, processed/t);
else
g_message ("elapsed: "
MU_COLOR_GREEN "%u" MU_COLOR_DEFAULT
" second(s)", t);
} else {
if (t)
g_message ("elapsed: %u second(s), ~ %u msg/s",
t, processed/t);
else
g_message ("elapsed: %u second(s)", t);
}
}
@ -234,6 +272,7 @@ cleanup_missing (MuIndex *midx, MuConfig *opts, MuIndexStats *stats,
{
MuError rv;
time_t t;
IndexData idata;
g_message ("cleaning up messages [%s]",
mu_runtime_path (MU_RUNTIME_PATH_XAPIANDB));
@ -241,13 +280,19 @@ cleanup_missing (MuIndex *midx, MuConfig *opts, MuIndexStats *stats,
mu_index_stats_clear (stats);
t = time (NULL);
rv = mu_index_cleanup (midx, stats,
show_progress ? index_msg_cb : index_msg_silent_cb,
NULL, err);
idata.color = !opts->nocolor;
rv = mu_index_cleanup
(midx, stats,
show_progress ?
(MuIndexCleanupDeleteCallback)index_msg_cb :
(MuIndexCleanupDeleteCallback)index_msg_silent_cb,
&idata, err);
if (!opts->quiet) {
print_stats (stats, TRUE);
print_stats (stats, TRUE, !opts->nocolor);
g_print ("\n");
show_time ((unsigned)(time(NULL)-t),stats->_processed);
show_time ((unsigned)(time(NULL)-t),stats->_processed,
!opts->nocolor);
}
return (rv == MU_OK || rv == MU_STOP) ? MU_OK: MU_G_ERROR_CODE(err);
@ -259,6 +304,7 @@ static MuError
cmd_index (MuIndex *midx, MuConfig *opts, MuIndexStats *stats,
gboolean show_progress, GError **err)
{
IndexData idata;
MuError rv;
time_t t;
@ -266,14 +312,18 @@ cmd_index (MuIndex *midx, MuConfig *opts, MuIndexStats *stats,
mu_runtime_path (MU_RUNTIME_PATH_XAPIANDB));
t = time (NULL);
idata.color = !opts->nocolor;
rv = mu_index_run (midx, opts->maildir, opts->reindex, stats,
show_progress ? index_msg_cb:index_msg_silent_cb,
NULL, NULL);
show_progress ?
(MuIndexMsgCallback)index_msg_cb :
(MuIndexMsgCallback)index_msg_silent_cb,
NULL, &idata);
if (!opts->quiet) {
print_stats (stats, TRUE);
print_stats (stats, TRUE, !opts->nocolor);
g_print ("\n");
show_time ((unsigned)(time(NULL)-t),stats->_processed);
show_time ((unsigned)(time(NULL)-t),
stats->_processed, !opts->nocolor);
}
if (rv == MU_OK || rv == MU_STOP)
@ -348,4 +398,3 @@ mu_cmd_index (MuStore *store, MuConfig *opts, GError **err)
return rv;
}

View File

@ -1,6 +1,6 @@
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/*
** Copyright (C) 2010-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2010-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -180,7 +180,8 @@ handle_msg (const char *fname, MuConfig *opts, GError **err)
switch (opts->format) {
case MU_CONFIG_FORMAT_PLAIN:
rv = view_msg_plain (msg, NULL, opts->summary, opts->color);
rv = view_msg_plain (msg, NULL, opts->summary,
!opts->nocolor);
break;
case MU_CONFIG_FORMAT_SEXP:
rv = view_msg_sexp (msg);

View File

@ -1,7 +1,7 @@
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/*
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -80,14 +80,13 @@ set_group_mu_defaults (MuConfig *opts)
opts->muhome = exp;
}
/* check for the MU_COLORS env var; but in any case don't use
* colors unless we're writing to a tty */
if (g_getenv (MU_COLORS) != NULL)
opts->color = TRUE;
/* 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)
opts->nocolor = TRUE;
if (!isatty(fileno(stdout)))
opts->color = FALSE;
opts->nocolor = TRUE;
}
@ -106,8 +105,8 @@ config_options_group_mu (MuConfig *opts)
"specify an alternative mu directory", NULL},
{"log-stderr", 0, 0, G_OPTION_ARG_NONE, &opts->log_stderr,
"log to standard error (false)", NULL},
{"color", 0, 0, G_OPTION_ARG_NONE, &opts->color,
"use ANSI-colors in some output (false)", NULL},
{"nocolor", 0, 0, G_OPTION_ARG_NONE, &opts->nocolor,
"don't use ANSI-colors in some output (false)", NULL},
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY,
&opts->params, "parameters", NULL},

View File

@ -1,7 +1,7 @@
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
/*
** Copyright (C) 2008-2011 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** Copyright (C) 2008-2012 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
**
** This program is free software; you can redistribute it and/or modify it
** under the terms of the GNU General Public License as published by the
@ -29,8 +29,8 @@
G_BEGIN_DECLS
/* env var; if non-empty, color are enabled for some commands */
#define MU_COLORS "MU_COLORS"
/* env var; if non-empty, color are disabled */
#define MU_NOCOLOR "MU_NOCOLOR"
enum _MuConfigFormat {
@ -93,7 +93,8 @@ struct _MuConfig {
gboolean version; /* request mu version */
gboolean log_stderr; /* log to stderr (not logfile) */
gchar** params; /* parameters (for querying) */
gboolean color; /* use ansi-colors in some output */
gboolean nocolor; /* don't use use ansi-colors
* in some output */
/* options for indexing */
char *maildir; /* where the mails are */