From 23b20c9ea0cde35a4c79e511b3b9510771be889a Mon Sep 17 00:00:00 2001 From: Rocco Rutte Date: Tue, 15 Jan 2008 10:49:41 +0100 Subject: [PATCH] Make formatting of query menu configurable via $query_format (closes #170). --- UPDATING | 1 + globals.h | 1 + init.h | 21 ++++++++++++++ query.c | 87 ++++++++++++++++++++++++++++++++++++------------------- 4 files changed, 80 insertions(+), 30 deletions(-) diff --git a/UPDATING b/UPDATING index b41d4a5b..254a368f 100644 --- a/UPDATING +++ b/UPDATING @@ -4,6 +4,7 @@ mutt. Please read this file carefully when upgrading your installation. The keys used are: !: modified feature, -: deleted feature, +: new feature + + $query_format (customize external query menu) ! inode sorting is always enabled + $time_inc suppresses progress updates less than $time_inc milliseconds apart. diff --git a/globals.h b/globals.h index eda09870..25882705 100644 --- a/globals.h +++ b/globals.h @@ -111,6 +111,7 @@ WHERE char *Postponed; WHERE char *Prefix; WHERE char *PrintCmd; WHERE char *QueryCmd; +WHERE char *QueryFormat; WHERE char *Realname; WHERE char *SendCharset; WHERE char *Sendmail; diff --git a/init.h b/init.h index 42b914ee..ec9348e8 100644 --- a/init.h +++ b/init.h @@ -2270,6 +2270,27 @@ struct option_t MuttVars[] = { ** with the query string the user types. See ``$query'' for more ** information. */ + { "query_format", DT_STR, R_NONE, UL &QueryFormat, UL "%4c %t %-25.25a %-25.25n %?e?(%e)?" }, + /* + ** .pp + ** This variable describes the format of the `query' menu. The + ** following printf-style sequences are understood: + ** .pp + ** .dl + ** .dt %a .dd destination address + ** .dt %c .dd current entry number + ** .dt %e .dd extra information * + ** .dt %n .dd destination name + ** .dt %t .dd ``*'' if current entry is tagged, a space otherwise + ** .dt %>X .dd right justify the rest of the string and pad with "X" + ** .dt %|X .dd pad to the end of the line with "X" + ** .dt %*X .dd soft-fill with character "X" as pad + ** .de + ** .pp + ** For an explanation of `soft-fill', see the ``$$index_format'' documentation. + ** .pp + ** * = can be optionally printed if nonzero, see the ``$$status_format'' documentation. + */ { "quit", DT_QUAD, R_NONE, OPT_QUIT, M_YES }, /* ** .pp diff --git a/query.c b/query.c index 248394b0..787af78e 100644 --- a/query.c +++ b/query.c @@ -32,6 +32,7 @@ typedef struct query { + int num; ADDRESS *addr; char *name; char *other; @@ -180,41 +181,67 @@ static int query_search (MUTTMENU *m, regex_t *re, int n) return REG_NOMATCH; } -/* This is the callback routine from mutt_menuLoop() which is used to generate - * a menu entry for the requested item number. - */ -#define QUERY_MIN_COLUMN_LENGHT 20 /* Must be < 70/2 */ -static void query_entry (char *s, size_t slen, MUTTMENU *m, int num) +static const char * query_format_str (char *dest, size_t destlen, size_t col, + char op, const char *src, + const char *fmt, const char *ifstring, + const char *elsestring, + unsigned long data, format_flag flags) { - ENTRY *table = (ENTRY *) m->data; - char buf2[SHORT_STRING], buf[SHORT_STRING] = ""; + ENTRY *entry = (ENTRY *)data; + QUERY *query = entry->data; + char tmp[SHORT_STRING]; + char buf2[STRING] = ""; + int optional = (flags & M_FORMAT_OPTIONAL); - /* need a query format ... hard coded constants are not good */ - while (FirstColumn + SecondColumn > 70) + switch (op) { - FirstColumn = FirstColumn * 3 / 4; - SecondColumn = SecondColumn * 3 / 4; - if (FirstColumn < QUERY_MIN_COLUMN_LENGHT) - FirstColumn = QUERY_MIN_COLUMN_LENGHT; - if (SecondColumn < QUERY_MIN_COLUMN_LENGHT) - SecondColumn = QUERY_MIN_COLUMN_LENGHT; + case 'a': + rfc822_write_address (buf2, sizeof (buf2), query->addr, 1); + snprintf (tmp, sizeof (tmp), "%%%ss", fmt); + snprintf (dest, destlen, tmp, buf2); + break; + case 'c': + snprintf (tmp, sizeof (tmp), "%%%sd", fmt); + snprintf (dest, destlen, tmp, query->num); + break; + case 'e': + if (!optional) + { + snprintf (tmp, sizeof (tmp), "%%%ss", fmt); + snprintf (dest, destlen, tmp, NONULL (query->other)); + } + else if (!query->other || !*query->other) + optional = 0; + break; + case 'n': + snprintf (tmp, sizeof (tmp), "%%%ss", fmt); + snprintf (dest, destlen, tmp, NONULL (query->name)); + break; + case 't': + snprintf (tmp, sizeof (tmp), "%%%sc", fmt); + snprintf (dest, destlen, tmp, entry->tagged ? '*' : ' '); + break; + default: + snprintf (tmp, sizeof (tmp), "%%%sc", fmt); + snprintf (dest, destlen, tmp, op); + break; } - rfc822_write_address (buf, sizeof (buf), table[num].data->addr, 1); - - mutt_format_string (buf2, sizeof (buf2), - FirstColumn + 2, FirstColumn + 2, - FMT_LEFT, ' ', table[num].data->name, - mutt_strlen (table[num].data->name), 0); - - snprintf (s, slen, " %c %3d %s %-*.*s %s", - table[num].tagged ? '*':' ', - num+1, - buf2, - SecondColumn+2, - SecondColumn+2, - buf, - NONULL (table[num].data->other)); + if (optional) + mutt_FormatString (dest, destlen, col, ifstring, query_format_str, data, 0); + else if (flags & M_FORMAT_OPTIONAL) + mutt_FormatString (dest, destlen, col, elsestring, query_format_str, data, 0); + + return src; +} + +static void query_entry (char *s, size_t slen, MUTTMENU *m, int num) +{ + ENTRY *entry = &((ENTRY *) m->data)[num]; + + entry->data->num = num; + mutt_FormatString (s, slen, 0, NONULL (QueryFormat), query_format_str, + (unsigned long) entry, M_FORMAT_ARROWCURSOR); } static int query_tag (MUTTMENU *menu, int n, int m) -- 2.40.0