* update 'mu view' and 'mu cfind' to use colors in some cases

This commit is contained in:
Dirk-Jan C. Binnema
2011-05-25 22:02:24 +03:00
parent 2b56e46260
commit f1ad2ebc51
2 changed files with 69 additions and 27 deletions

View File

@ -24,6 +24,7 @@
#endif /*HAVE_CONFIG_H*/
#include <stdlib.h>
#include <stdio.h>
#include "mu-msg.h"
#include "mu-msg-part.h"
@ -64,43 +65,56 @@ get_attach_str (MuMsg *msg)
}
static void
print_field (const char* field, const char *val, gboolean color)
{
if (!val)
return;
if (color) {
mu_util_color_print (MU_COLOR_MAGENTA, field);
mu_util_color_print (MU_COLOR_BLUE, val);
} else {
fputs (field, stdout);
fputs (val, stdout);
}
fputs ("\n", stdout);
}
/* we ignore fields for now */
static gboolean
view_msg (MuMsg *msg, const gchar *fields, size_t summary_len)
view_msg (MuMsg *msg, const gchar *fields, gboolean summary,
gboolean color)
{
const char *field;
gchar *attachs;
time_t date;
const int SUMMARY_LEN = 5;
if ((field = mu_msg_get_from (msg)))
g_print ("From: %s\n", field);
print_field ("From: ", mu_msg_get_from (msg), color);
print_field ("To: ", mu_msg_get_to (msg), color);
print_field ("Cc: ", mu_msg_get_cc (msg), color);
print_field ("Bcc: ", mu_msg_get_bcc (msg), color);
print_field ("Subject: ", mu_msg_get_subject (msg), color);
if ((field = mu_msg_get_to (msg)))
g_print ("To: %s\n", field);
if ((field = mu_msg_get_cc (msg)))
g_print ("Cc: %s\n", field);
if ((field = mu_msg_get_subject (msg)))
g_print ("Subject: %s\n", field);
if ((date = mu_msg_get_date (msg)))
g_print ("Date: %s\n", mu_str_date_s ("%c", date));
if ((date = mu_msg_get_date (msg)))
print_field ("Date: ", mu_str_date_s ("%c", date),
color);
if ((attachs = get_attach_str (msg))) {
g_print ("Attachment(s): %s\n", attachs);
print_field ("Attachments: ", attachs, color);
g_free (attachs);
}
if (!(field = mu_msg_get_body_text (msg)))
return TRUE; /* no body -- nothing more to do */
if (summary_len > 0) {
if (summary) {
gchar *summ;
summ = mu_str_summarize (field, summary_len);
g_print ("Summary: %s\n", summ);
summ = mu_str_summarize (field, SUMMARY_LEN);
print_field ("Summary: ", summ, color);
g_free (summ);
} else
g_print ("\n%s\n", field);
@ -133,7 +147,7 @@ mu_cmd_view (MuConfig *opts)
g_error_free (err);
return MU_EXITCODE_ERROR;
}
if (!view_msg (msg, NULL, opts->summary_len))
if (!view_msg (msg, NULL, opts->summary, opts->color))
rv = MU_EXITCODE_ERROR;
mu_msg_unref (msg);