]> granicus.if.org Git - neomutt/commitdiff
expandos for deleted, limited, tagged
authorRichard Russon <rich@flatcap.org>
Thu, 31 Dec 2015 03:04:42 +0000 (03:04 +0000)
committerRichard Russon <rich@flatcap.org>
Mon, 4 Apr 2016 02:37:43 +0000 (03:37 +0100)
init.h
sidebar.c

diff --git a/init.h b/init.h
index 28cac31db496212e09a9c612d3937c0beefe181e..da0a17287db22f3b194302e2e71a8b5010f85cc0 100644 (file)
--- a/init.h
+++ b/init.h
@@ -2708,12 +2708,23 @@ struct option_t MuttVars[] = {
   ** sequences:
   ** .dl
   ** .dt %B  .dd Name of the mailbox
-  ** .dt %S  .dd Size of mailbox (total number of messages)
-  ** .dt %N  .dd Number of New messages in the mailbox
-  ** .dt %F  .dd Number of Flagged messages in the mailbox
-  ** .dt %!  .dd `!' : one flagged message; `!!' : two flagged messages; `n!' :
-  **             n flagged messages (for n > 2).
+  ** .dt %S  .dd * Size of mailbox (total number of messages)
+  ** .dt %N  .dd * Number of New messages in the mailbox
+  ** .dt %F  .dd * Number of Flagged messages in the mailbox
+  ** .dt %!  .dd ``!'' : one flagged message;
+  **             ``!!'' : two flagged messages;
+  **             ``n!'' : n flagged messages (for n > 2).
+  **             Otherwise prints nothing.
+  ** .dt %d  .dd * @ Number of deleted messages
+  ** .dt %L  .dd * @ Number of messages after limiting
+  ** .dt %t  .dd * @ Number of tagged messages
+  ** .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
+  ** * = Can be optionally printed if nonzero
+  ** @ = Only applicable to the current folder
   */
   { "sidebar_indentstr", DT_STR, R_BOTH, UL &SidebarIndentStr, UL "  " },
   /*
index 1b00f2abc1010d3c4d20597147ac799ae5d5eec3..773be6fe360059fbcbf3ff64a3c04203e0c067bb 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -48,9 +48,7 @@ static BUFFY *Outgoing;               /* Last mailbox in the linked list */
  */
 struct sidebar_entry {
        char         box[SHORT_STRING];
-       unsigned int size;
-       unsigned int new;
-       unsigned int flagged;
+       BUFFY       *buffy;
 };
 
 
@@ -156,6 +154,14 @@ cb_format_str (char *dest, size_t destlen, size_t col, char op, const char *src,
 
        dest[0] = 0;    /* Just in case there's nothing to do */
 
+       BUFFY *b = sbe->buffy;
+       if (!b)
+               return src;
+
+#if 1
+       int c = Context && (mutt_strcmp (Context->path, b->path) == 0);
+#endif
+
        optional = flags & M_FORMAT_OPTIONAL;
 
        switch (op) {
@@ -163,11 +169,29 @@ cb_format_str (char *dest, size_t destlen, size_t col, char op, const char *src,
                        mutt_format_s (dest, destlen, prefix, sbe->box);
                        break;
 
+               case 'd':
+                       if (!optional) {
+                               snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
+                               snprintf (dest, destlen, fmt, c ? Context->deleted : 0);
+                       } else if ((c && Context->deleted == 0) || !c) {
+                               optional = 0;
+                       }
+                       break;
+
                case 'F':
                        if (!optional) {
                                snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
-                               snprintf (dest, destlen, fmt, sbe->flagged);
-                       } else if (sbe->flagged == 0) {
+                               snprintf (dest, destlen, fmt, b->msg_flagged);
+                       } else if (b->msg_flagged == 0) {
+                               optional = 0;
+                       }
+                       break;
+
+               case 'L':
+                       if (!optional) {
+                               snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
+                               snprintf (dest, destlen, fmt, c ? Context->vcount : b->msg_count);
+                       } else if ((c && Context->vcount == b->msg_count) || !c) {
                                optional = 0;
                        }
                        break;
@@ -175,8 +199,8 @@ cb_format_str (char *dest, size_t destlen, size_t col, char op, const char *src,
                case 'N':
                        if (!optional) {
                                snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
-                               snprintf (dest, destlen, fmt, sbe->new);
-                       } else if (sbe->new == 0) {
+                               snprintf (dest, destlen, fmt, b->msg_unread);
+                       } else if (b->msg_unread == 0) {
                                optional = 0;
                        }
                        break;
@@ -184,21 +208,30 @@ cb_format_str (char *dest, size_t destlen, size_t col, char op, const char *src,
                case 'S':
                        if (!optional) {
                                snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
-                               snprintf (dest, destlen, fmt, sbe->size);
-                       } else if (sbe->size == 0) {
+                               snprintf (dest, destlen, fmt, b->msg_count);
+                       } else if (b->msg_count == 0) {
+                               optional = 0;
+                       }
+                       break;
+
+               case 't':
+                       if (!optional) {
+                               snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
+                               snprintf (dest, destlen, fmt, c ? Context->tagged : 0);
+                       } else if ((c && Context->tagged == 0) || !c) {
                                optional = 0;
                        }
                        break;
 
                case '!':
-                       if (sbe->flagged == 0) {
+                       if (b->msg_flagged == 0) {
                                mutt_format_s (dest, destlen, prefix, "");
-                       } else if (sbe->flagged == 1) {
+                       } else if (b->msg_flagged == 1) {
                                mutt_format_s (dest, destlen, prefix, "!");
-                       } else if (sbe->flagged == 2) {
+                       } else if (b->msg_flagged == 2) {
                                mutt_format_s (dest, destlen, prefix, "!!");
                        } else {
-                               snprintf (buf, sizeof (buf), "%d!", sbe->flagged);
+                               snprintf (buf, sizeof (buf), "%d!", b->msg_flagged);
                                mutt_format_s (dest, destlen, prefix, buf);
                        }
                        break;
@@ -229,17 +262,15 @@ cb_format_str (char *dest, size_t destlen, size_t col, char op, const char *src,
  */
 static void
 make_sidebar_entry (char *buf, unsigned int buflen, int width, char *box,
-       unsigned int size, unsigned int new, unsigned int flagged)
+       BUFFY *b)
 {
        struct sidebar_entry sbe;
 
-       if (!buf || !box)
+       if (!buf || !box || !b)
                return;
 
-       sbe.new = new;
-       sbe.flagged = flagged;
-       sbe.size = size;
-       strncpy (sbe.box, box, sizeof (sbe.box)-1);
+       sbe.buffy = b;
+       strncpy (sbe.box, box, sizeof (sbe.box) - 1);
 
        int box_len = strlen (box);
        sbe.box[box_len] = '\0';
@@ -712,9 +743,7 @@ draw_sidebar (int first_row, int num_rows, int div_width)
                }
                char str[SHORT_STRING];
                int w = MIN(COLS, (SidebarWidth - div_width));
-               make_sidebar_entry (str, sizeof (str), w,
-                       sidebar_folder_name, b->msg_count,
-                       b->msg_unread, b->msg_flagged);
+               make_sidebar_entry (str, sizeof (str), w, sidebar_folder_name, b);
                printw ("%s", str);
                if (sidebar_folder_depth > 0)
                        free (sidebar_folder_name);