* add --summary-len option for mu find and mu view, and document it
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
.TH MU FIND 1 "December 2011" "User Manuals"
|
.TH MU FIND 1 "April 2012" "User Manuals"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
|
|
||||||
@ -340,6 +340,10 @@ choice, but for dates it may be more useful to sort in the opposite direction.
|
|||||||
\fB\-\-summary\fR
|
\fB\-\-summary\fR
|
||||||
output a summary based upon the first lines of the message.
|
output a summary based upon the first lines of the message.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
\fB\-\-summary-len=<number>\fR
|
||||||
|
Number of lines to use for the summary. Default: 5.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-include\-unreadable\fR
|
\fB\-\-include\-unreadable\fR
|
||||||
normally, \fBmu find\fR does not include messages that are unreadable,
|
normally, \fBmu find\fR does not include messages that are unreadable,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
.TH MU VIEW 1 "July 2011" "User Manuals"
|
.TH MU VIEW 1 "April 2012" "User Manuals"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
|
|
||||||
@ -25,6 +25,11 @@ any).
|
|||||||
instead of displaying the full message, output a summary based upon the first
|
instead of displaying the full message, output a summary based upon the first
|
||||||
lines of the message.
|
lines of the message.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
\fB\-\-summary-len=<number>\fR
|
||||||
|
Number of lines to use for the summary. Default: 5.
|
||||||
|
|
||||||
|
|
||||||
\fB\-\-terminate\fR
|
\fB\-\-terminate\fR
|
||||||
terminate messaages with a \\f (\fIform-feed\fR) characters when displaying
|
terminate messaages with a \\f (\fIform-feed\fR) characters when displaying
|
||||||
them. This is useful when you want to further process them.
|
them. This is useful when you want to further process them.
|
||||||
|
|||||||
@ -53,7 +53,8 @@ static gboolean output_sexp (MuMsgIter *iter, gboolean threads,
|
|||||||
static gboolean output_xml (MuMsgIter *iter,gboolean include_unreadable,
|
static gboolean output_xml (MuMsgIter *iter,gboolean include_unreadable,
|
||||||
GError **err);
|
GError **err);
|
||||||
static gboolean output_plain (MuMsgIter *iter, const char *fields,
|
static gboolean output_plain (MuMsgIter *iter, const char *fields,
|
||||||
gboolean summary,gboolean threads,
|
gboolean summary, int summary_len,
|
||||||
|
gboolean threads,
|
||||||
gboolean color, gboolean include_unreadable,
|
gboolean color, gboolean include_unreadable,
|
||||||
GError **err);
|
GError **err);
|
||||||
|
|
||||||
@ -99,7 +100,8 @@ output_query_results (MuMsgIter *iter, MuConfig *opts, GError **err)
|
|||||||
case MU_CONFIG_FORMAT_LINKS:
|
case MU_CONFIG_FORMAT_LINKS:
|
||||||
return output_links (iter, opts->linksdir, opts->clearlinks, err);
|
return output_links (iter, opts->linksdir, opts->clearlinks, err);
|
||||||
case MU_CONFIG_FORMAT_PLAIN:
|
case MU_CONFIG_FORMAT_PLAIN:
|
||||||
return output_plain (iter, opts->fields, opts->summary,
|
return output_plain (iter, opts->fields,
|
||||||
|
opts->summary, opts->summary_len,
|
||||||
opts->threads, !opts->nocolor,
|
opts->threads, !opts->nocolor,
|
||||||
opts->include_unreadable, err);
|
opts->include_unreadable, err);
|
||||||
case MU_CONFIG_FORMAT_XML:
|
case MU_CONFIG_FORMAT_XML:
|
||||||
@ -267,6 +269,7 @@ query_params_valid (MuConfig *opts, GError **err)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gchar*
|
static gchar*
|
||||||
resolve_bookmark (MuConfig *opts, GError **err)
|
resolve_bookmark (MuConfig *opts, GError **err)
|
||||||
{
|
{
|
||||||
@ -566,13 +569,11 @@ display_field (MuMsg *msg, MuMsgFieldId mfid)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_summary (MuMsg *msg)
|
print_summary (MuMsg *msg, int summary_len)
|
||||||
{
|
{
|
||||||
char *summ;
|
char *summ;
|
||||||
|
summ = mu_str_summarize (mu_msg_get_body_text(msg),
|
||||||
const guint SUMMARY_LEN = 5; /* summary based on first 5
|
(unsigned)summary_len);
|
||||||
* lines */
|
|
||||||
summ = mu_str_summarize (mu_msg_get_body_text(msg), SUMMARY_LEN);
|
|
||||||
g_print ("Summary: %s\n", summ ? summ : "<none>");
|
g_print ("Summary: %s\n", summ ? summ : "<none>");
|
||||||
g_free (summ);
|
g_free (summ);
|
||||||
}
|
}
|
||||||
@ -648,7 +649,7 @@ output_plain_fields (MuMsg *msg, const char *fields,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
output_plain (MuMsgIter *iter, const char *fields, gboolean summary,
|
output_plain (MuMsgIter *iter, const char *fields, gboolean summary, int summary_len,
|
||||||
gboolean threads, gboolean color, gboolean include_unreadable,
|
gboolean threads, gboolean color, gboolean include_unreadable,
|
||||||
GError **err)
|
GError **err)
|
||||||
{
|
{
|
||||||
@ -658,6 +659,12 @@ output_plain (MuMsgIter *iter, const char *fields, gboolean summary,
|
|||||||
g_return_val_if_fail (iter, FALSE);
|
g_return_val_if_fail (iter, FALSE);
|
||||||
g_return_val_if_fail (fields, FALSE);
|
g_return_val_if_fail (fields, FALSE);
|
||||||
|
|
||||||
|
if (summary && summary_len < 1) {
|
||||||
|
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
|
||||||
|
"summary must be >= 1");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
for (myiter = iter, count = 0; !mu_msg_iter_is_done (myiter);
|
for (myiter = iter, count = 0; !mu_msg_iter_is_done (myiter);
|
||||||
mu_msg_iter_next (myiter)) {
|
mu_msg_iter_next (myiter)) {
|
||||||
|
|
||||||
@ -680,7 +687,7 @@ output_plain (MuMsgIter *iter, const char *fields, gboolean summary,
|
|||||||
output_plain_fields (msg, fields, color, threads);
|
output_plain_fields (msg, fields, color, threads);
|
||||||
|
|
||||||
if (summary)
|
if (summary)
|
||||||
print_summary (msg);
|
print_summary (msg, summary_len);
|
||||||
|
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
|
|||||||
26
src/mu-cmd.c
26
src/mu-cmd.c
@ -108,19 +108,19 @@ print_field (const char* field, const char *val, gboolean color)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* a summary_len of 0 mean 'don't show summary, show body */
|
||||||
static void
|
static void
|
||||||
body_or_summary (MuMsg *msg, gboolean summary, gboolean color)
|
body_or_summary (MuMsg *msg, unsigned summary_len, gboolean color)
|
||||||
{
|
{
|
||||||
const char* field;
|
const char* field;
|
||||||
const int SUMMARY_LEN = 5;
|
|
||||||
|
|
||||||
field = mu_msg_get_body_text (msg);
|
field = mu_msg_get_body_text (msg);
|
||||||
if (!field)
|
if (!field)
|
||||||
return; /* no body -- nothing more to do */
|
return; /* no body -- nothing more to do */
|
||||||
|
|
||||||
if (summary) {
|
if (summary_len != 0) {
|
||||||
gchar *summ;
|
gchar *summ;
|
||||||
summ = mu_str_summarize (field, SUMMARY_LEN);
|
summ = mu_str_summarize (field, summary_len);
|
||||||
print_field ("Summary", summ, color);
|
print_field ("Summary", summ, color);
|
||||||
g_free (summ);
|
g_free (summ);
|
||||||
} else {
|
} else {
|
||||||
@ -132,8 +132,9 @@ body_or_summary (MuMsg *msg, gboolean summary, gboolean color)
|
|||||||
|
|
||||||
|
|
||||||
/* we ignore fields for now */
|
/* we ignore fields for now */
|
||||||
|
/* summary_len == 0 means "no summary */
|
||||||
static gboolean
|
static gboolean
|
||||||
view_msg_plain (MuMsg *msg, const gchar *fields, gboolean summary,
|
view_msg_plain (MuMsg *msg, const gchar *fields, unsigned summary_len,
|
||||||
gboolean color)
|
gboolean color)
|
||||||
{
|
{
|
||||||
gchar *attachs;
|
gchar *attachs;
|
||||||
@ -162,7 +163,7 @@ view_msg_plain (MuMsg *msg, const gchar *fields, gboolean summary,
|
|||||||
g_free (attachs);
|
g_free (attachs);
|
||||||
}
|
}
|
||||||
|
|
||||||
body_or_summary (msg, summary, color);
|
body_or_summary (msg, summary_len, color);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -181,8 +182,10 @@ handle_msg (const char *fname, MuConfig *opts, GError **err)
|
|||||||
|
|
||||||
switch (opts->format) {
|
switch (opts->format) {
|
||||||
case MU_CONFIG_FORMAT_PLAIN:
|
case MU_CONFIG_FORMAT_PLAIN:
|
||||||
rv = view_msg_plain (msg, NULL, opts->summary,
|
rv = view_msg_plain
|
||||||
!opts->nocolor);
|
(msg, NULL,
|
||||||
|
opts->summary ? opts->summary_len : 0,
|
||||||
|
!opts->nocolor);
|
||||||
break;
|
break;
|
||||||
case MU_CONFIG_FORMAT_SEXP:
|
case MU_CONFIG_FORMAT_SEXP:
|
||||||
rv = view_msg_sexp (msg);
|
rv = view_msg_sexp (msg);
|
||||||
@ -202,7 +205,7 @@ view_params_valid (MuConfig *opts, GError **err)
|
|||||||
{
|
{
|
||||||
/* note: params[0] will be 'view' */
|
/* note: params[0] will be 'view' */
|
||||||
if (!opts->params[0] || !opts->params[1]) {
|
if (!opts->params[0] || !opts->params[1]) {
|
||||||
g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_IN_PARAMETERS,
|
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
|
||||||
"error in parameters");
|
"error in parameters");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -212,7 +215,7 @@ view_params_valid (MuConfig *opts, GError **err)
|
|||||||
case MU_CONFIG_FORMAT_SEXP:
|
case MU_CONFIG_FORMAT_SEXP:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_IN_PARAMETERS,
|
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
|
||||||
"invalid output format");
|
"invalid output format");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -438,7 +441,8 @@ check_params (MuConfig *opts, GError **err)
|
|||||||
{
|
{
|
||||||
if (!opts->params||!opts->params[0]) {/* no command? */
|
if (!opts->params||!opts->params[0]) {/* no command? */
|
||||||
show_usage ();
|
show_usage ();
|
||||||
g_set_error (err, MU_ERROR_DOMAIN, MU_ERROR_IN_PARAMETERS, "error in parameters");
|
mu_util_g_set_error (err, MU_ERROR_IN_PARAMETERS,
|
||||||
|
"error in parameters");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,8 @@
|
|||||||
|
|
||||||
static MuConfig MU_CONFIG;
|
static MuConfig MU_CONFIG;
|
||||||
|
|
||||||
|
#define DEFAULT_SUMMARY_LEN 5
|
||||||
|
|
||||||
|
|
||||||
static MuConfigFormat
|
static MuConfigFormat
|
||||||
get_output_format (const char *formatstr)
|
get_output_format (const char *formatstr)
|
||||||
@ -192,6 +194,10 @@ set_group_find_defaults (void)
|
|||||||
else
|
else
|
||||||
g_free(old);
|
g_free(old);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((MU_CONFIG.summary && !MU_CONFIG.summary_len)||
|
||||||
|
(MU_CONFIG.summary_len < 1))
|
||||||
|
MU_CONFIG.summary_len = DEFAULT_SUMMARY_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GOptionGroup*
|
static GOptionGroup*
|
||||||
@ -211,6 +217,8 @@ config_options_group_find (void)
|
|||||||
"sort in reverse (descending) order (z -> a)", NULL},
|
"sort in reverse (descending) order (z -> a)", NULL},
|
||||||
{"summary", 'k', 0, G_OPTION_ARG_NONE, &MU_CONFIG.summary,
|
{"summary", 'k', 0, G_OPTION_ARG_NONE, &MU_CONFIG.summary,
|
||||||
"include a short summary of the message (false)", NULL},
|
"include a short summary of the message (false)", NULL},
|
||||||
|
{"summary-len", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.summary_len,
|
||||||
|
"use up to <n> lines for the summary (5)", NULL},
|
||||||
{"linksdir", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.linksdir,
|
{"linksdir", 0, 0, G_OPTION_ARG_STRING, &MU_CONFIG.linksdir,
|
||||||
"output as symbolic links to a target maildir", NULL},
|
"output as symbolic links to a target maildir", NULL},
|
||||||
{"clearlinks", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.clearlinks,
|
{"clearlinks", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.clearlinks,
|
||||||
@ -292,6 +300,10 @@ set_group_view_defaults (void)
|
|||||||
MU_CONFIG.format = MU_CONFIG_FORMAT_PLAIN;
|
MU_CONFIG.format = MU_CONFIG_FORMAT_PLAIN;
|
||||||
else
|
else
|
||||||
MU_CONFIG.format = get_output_format (MU_CONFIG.formatstr);
|
MU_CONFIG.format = get_output_format (MU_CONFIG.formatstr);
|
||||||
|
|
||||||
|
if ((MU_CONFIG.summary && !MU_CONFIG.summary_len)||
|
||||||
|
(MU_CONFIG.summary_len < 1))
|
||||||
|
MU_CONFIG.summary_len = DEFAULT_SUMMARY_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GOptionGroup *
|
static GOptionGroup *
|
||||||
@ -301,6 +313,8 @@ config_options_group_view (void)
|
|||||||
GOptionEntry entries[] = {
|
GOptionEntry entries[] = {
|
||||||
{"summary", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.summary,
|
{"summary", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.summary,
|
||||||
"only show a short summary of the message (false)", NULL},
|
"only show a short summary of the message (false)", NULL},
|
||||||
|
{"summary-len", 0, 0, G_OPTION_ARG_INT, &MU_CONFIG.summary_len,
|
||||||
|
"use up to <n> lines for the summary (5)", NULL},
|
||||||
{"terminate", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.terminator,
|
{"terminate", 0, 0, G_OPTION_ARG_NONE, &MU_CONFIG.terminator,
|
||||||
"terminate messages with ascii-0x07 (\\f, form-feed)", NULL},
|
"terminate messages with ascii-0x07 (\\f, form-feed)", NULL},
|
||||||
{"format", 'o', 0, G_OPTION_ARG_STRING, &MU_CONFIG.formatstr,
|
{"format", 'o', 0, G_OPTION_ARG_STRING, &MU_CONFIG.formatstr,
|
||||||
|
|||||||
@ -113,7 +113,10 @@ struct _MuConfig {
|
|||||||
char *sortfield; /* field to sort by (string) */
|
char *sortfield; /* field to sort by (string) */
|
||||||
gboolean reverse; /* sort in revers order (z->a) */
|
gboolean reverse; /* sort in revers order (z->a) */
|
||||||
gboolean threads; /* show message threads */
|
gboolean threads; /* show message threads */
|
||||||
|
|
||||||
gboolean summary; /* include a summary? */
|
gboolean summary; /* include a summary? */
|
||||||
|
int summary_len; /* max # of lines for summary */
|
||||||
|
|
||||||
char *bookmark; /* use bookmark */
|
char *bookmark; /* use bookmark */
|
||||||
char *formatstr; /* output type for find
|
char *formatstr; /* output type for find
|
||||||
* (plain,links,xml,json,sexp)
|
* (plain,links,xml,json,sexp)
|
||||||
|
|||||||
Reference in New Issue
Block a user