* update 'mu view' and 'mu cfind' to use colors in some cases
This commit is contained in:
@ -22,6 +22,7 @@
|
|||||||
#endif /*HAVE_CONFIG_H*/
|
#endif /*HAVE_CONFIG_H*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "mu-cmd.h"
|
#include "mu-cmd.h"
|
||||||
#include "mu-util.h"
|
#include "mu-util.h"
|
||||||
@ -138,12 +139,37 @@ each_contact_org_contact (const char *email, const char *name)
|
|||||||
name, email);
|
name, email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_plain (const char *email, const char *name, gboolean color)
|
||||||
|
{
|
||||||
|
if (name) {
|
||||||
|
if (color)
|
||||||
|
mu_util_color_print (MU_COLOR_MAGENTA, name);
|
||||||
|
else
|
||||||
|
fputs (name, stdout);
|
||||||
|
|
||||||
|
fputs (" ", stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (color)
|
||||||
|
mu_util_color_print (MU_COLOR_GREEN, email);
|
||||||
|
else
|
||||||
|
fputs (email, stdout);
|
||||||
|
|
||||||
|
fputs ("\n", stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct _ECData {
|
||||||
|
OutputFormat format;
|
||||||
|
gboolean color;
|
||||||
|
};
|
||||||
|
typedef struct _ECData ECData;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
each_contact (const char *email, const char *name, time_t tstamp,
|
each_contact (const char *email, const char *name, time_t tstamp, ECData *ecdata)
|
||||||
OutputFormat format)
|
|
||||||
{
|
{
|
||||||
switch (format) {
|
switch (ecdata->format) {
|
||||||
case FORMAT_MUTT_ALIAS: each_contact_mutt_alias (email, name); break;
|
case FORMAT_MUTT_ALIAS: each_contact_mutt_alias (email, name); break;
|
||||||
case FORMAT_MUTT_AB:
|
case FORMAT_MUTT_AB:
|
||||||
g_print ("%s\t%s\t\n", email, name ? name : ""); break;
|
g_print ("%s\t%s\t\n", email, name ? name : ""); break;
|
||||||
@ -155,17 +181,19 @@ each_contact (const char *email, const char *name, time_t tstamp,
|
|||||||
g_print ("%s,%s\n", name ? name : "", email);
|
g_print ("%s,%s\n", name ? name : "", email);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
g_print ("%s%s%s\n", name ? name : "", name ? " " : "", email);
|
print_plain (email, name, ecdata->color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static MuExitCode
|
static MuExitCode
|
||||||
run_cmd_cfind (const char* pattern, OutputFormat format)
|
run_cmd_cfind (const char* pattern, OutputFormat format,
|
||||||
|
gboolean color)
|
||||||
{
|
{
|
||||||
gboolean rv;
|
gboolean rv;
|
||||||
MuContacts *contacts;
|
MuContacts *contacts;
|
||||||
size_t num;
|
size_t num;
|
||||||
|
ECData ecdata = {format, color};
|
||||||
|
|
||||||
contacts = mu_contacts_new (mu_runtime_path(MU_RUNTIME_PATH_CONTACTS));
|
contacts = mu_contacts_new (mu_runtime_path(MU_RUNTIME_PATH_CONTACTS));
|
||||||
if (!contacts) {
|
if (!contacts) {
|
||||||
@ -176,7 +204,7 @@ run_cmd_cfind (const char* pattern, OutputFormat format)
|
|||||||
print_header (format);
|
print_header (format);
|
||||||
rv = mu_contacts_foreach (contacts,
|
rv = mu_contacts_foreach (contacts,
|
||||||
(MuContactsForeachFunc)each_contact,
|
(MuContactsForeachFunc)each_contact,
|
||||||
GINT_TO_POINTER(format), pattern, &num);
|
&ecdata, pattern, &num);
|
||||||
|
|
||||||
mu_contacts_destroy (contacts);
|
mu_contacts_destroy (contacts);
|
||||||
|
|
||||||
@ -208,10 +236,10 @@ mu_cmd_cfind (MuConfig *opts)
|
|||||||
|
|
||||||
/* only one pattern allowed */
|
/* only one pattern allowed */
|
||||||
if (opts->params[1] && opts->params[2]) {
|
if (opts->params[1] && opts->params[2]) {
|
||||||
g_warning ("usage: mu cfind [OPTIONS] [<ptrn>]");
|
g_warning ("usage: mu cfind [options] [<ptrn>]");
|
||||||
return MU_EXITCODE_ERROR;
|
return MU_EXITCODE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return run_cmd_cfind (opts->params[1], format);
|
return run_cmd_cfind (opts->params[1], format, opts->color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
50
src/mu-cmd.c
50
src/mu-cmd.c
@ -24,6 +24,7 @@
|
|||||||
#endif /*HAVE_CONFIG_H*/
|
#endif /*HAVE_CONFIG_H*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "mu-msg.h"
|
#include "mu-msg.h"
|
||||||
#include "mu-msg-part.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 */
|
/* we ignore fields for now */
|
||||||
static gboolean
|
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;
|
const char *field;
|
||||||
gchar *attachs;
|
gchar *attachs;
|
||||||
time_t date;
|
time_t date;
|
||||||
|
const int SUMMARY_LEN = 5;
|
||||||
|
|
||||||
if ((field = mu_msg_get_from (msg)))
|
print_field ("From: ", mu_msg_get_from (msg), color);
|
||||||
g_print ("From: %s\n", field);
|
print_field ("To: ", mu_msg_get_to (msg), color);
|
||||||
|
print_field ("Cc: ", mu_msg_get_cc (msg), color);
|
||||||
if ((field = mu_msg_get_to (msg)))
|
print_field ("Bcc: ", mu_msg_get_bcc (msg), color);
|
||||||
g_print ("To: %s\n", field);
|
print_field ("Subject: ", mu_msg_get_subject (msg), color);
|
||||||
|
|
||||||
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)))
|
if ((date = mu_msg_get_date (msg)))
|
||||||
g_print ("Date: %s\n", mu_str_date_s ("%c", date));
|
print_field ("Date: ", mu_str_date_s ("%c", date),
|
||||||
|
color);
|
||||||
|
|
||||||
if ((attachs = get_attach_str (msg))) {
|
if ((attachs = get_attach_str (msg))) {
|
||||||
g_print ("Attachment(s): %s\n", attachs);
|
print_field ("Attachments: ", attachs, color);
|
||||||
g_free (attachs);
|
g_free (attachs);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(field = mu_msg_get_body_text (msg)))
|
if (!(field = mu_msg_get_body_text (msg)))
|
||||||
return TRUE; /* no body -- nothing more to do */
|
return TRUE; /* no body -- nothing more to do */
|
||||||
|
|
||||||
if (summary_len > 0) {
|
if (summary) {
|
||||||
gchar *summ;
|
gchar *summ;
|
||||||
summ = mu_str_summarize (field, summary_len);
|
summ = mu_str_summarize (field, SUMMARY_LEN);
|
||||||
g_print ("Summary: %s\n", summ);
|
print_field ("Summary: ", summ, color);
|
||||||
g_free (summ);
|
g_free (summ);
|
||||||
} else
|
} else
|
||||||
g_print ("\n%s\n", field);
|
g_print ("\n%s\n", field);
|
||||||
@ -133,7 +147,7 @@ mu_cmd_view (MuConfig *opts)
|
|||||||
g_error_free (err);
|
g_error_free (err);
|
||||||
return MU_EXITCODE_ERROR;
|
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;
|
rv = MU_EXITCODE_ERROR;
|
||||||
|
|
||||||
mu_msg_unref (msg);
|
mu_msg_unref (msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user