]> granicus.if.org Git - mutt/commitdiff
Make formatting of query menu configurable via $query_format (closes #170).
authorRocco Rutte <pdmef@gmx.net>
Tue, 15 Jan 2008 09:49:41 +0000 (10:49 +0100)
committerRocco Rutte <pdmef@gmx.net>
Tue, 15 Jan 2008 09:49:41 +0000 (10:49 +0100)
UPDATING
globals.h
init.h
query.c

index b41d4a5b13560a4cea0eb976eae5a8654d8ec5ea..254a368f3eb03606eccc0dc1e63935485f1ba19a 100644 (file)
--- 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.
index eda098703b5c9509e51d7b132796eec9b4ab82a7..2588270580bfb851fbb5ef2838c522c7b7e49bb5 100644 (file)
--- 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 42b914ee0207baf1fb56518f85972f0438a981ba..ec9348e84d341f70771128d584186c993fa34555 100644 (file)
--- 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 248394b0957b481010ec18491d8cda3c36d4495e..787af78e75e74f66dc858c1b2b78485721d3cc8e 100644 (file)
--- 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)