]> granicus.if.org Git - mutt/commitdiff
Removed hardcoded pager progress indicator and add %P format code to $pager_status...
authorMichael Elkins <me@sigpipe.org>
Sun, 15 Apr 2007 22:43:57 +0000 (15:43 -0700)
committerMichael Elkins <me@sigpipe.org>
Sun, 15 Apr 2007 22:43:57 +0000 (15:43 -0700)
Append "%> -- (%P)" to $pager_status to emulate old behavior.

Closes #2087.

hdrline.c
init.h
pager.c
protos.h

index 43bb679ba3ce6962de8b52546f1446c54fd131a0..a4cfb263c503d5fa2cca1105fffb5bd2add13a19 100644 (file)
--- a/hdrline.c
+++ b/hdrline.c
@@ -216,6 +216,7 @@ int mutt_user_is_recipient (HEADER *h)
  * %n = name of author
  * %N = score
  * %O = like %L, except using address instead of name
+ * %P = progress indicator for builtin pager
  * %s = subject
  * %S = short message status (e.g., N/O/D/!/r/-)
  * %t = `to:' field (recipients)
@@ -227,12 +228,6 @@ int mutt_user_is_recipient (HEADER *h)
  * %Y = `x-label:' field (if present, tree unfolded, and != parent's x-label)
  * %Z = status flags   */
 
-struct hdr_format_info
-{
-  CONTEXT *ctx;
-  HEADER *hdr;
-};
-
 static const char *
 hdr_format_str (char *dest,
                size_t destlen,
@@ -547,6 +542,10 @@ hdr_format_str (char *dest,
       }
       break;
 
+    case 'P':
+      strfcpy(dest, NONULL(hfi->pager_progress), destlen);
+      break;
+
     case 's':
       
       if (flags & M_FORMAT_TREE && !hdr->collapsed)
@@ -732,6 +731,13 @@ _mutt_make_string (char *dest, size_t destlen, const char *s, CONTEXT *ctx, HEAD
 
   hfi.hdr = hdr;
   hfi.ctx = ctx;
+  hfi.pager_progress = 0;
 
   mutt_FormatString (dest, destlen, 0, s, hdr_format_str, (unsigned long) &hfi, flags);
 }
+
+void
+mutt_make_string_info (char *dst, size_t dstlen, const char *s, struct hdr_format_info *hfi, format_flag flags)
+{
+  mutt_FormatString (dst, dstlen, 0, s, hdr_format_str, (unsigned long) hfi, flags);
+}
diff --git a/init.h b/init.h
index 28d264b6b4aedee466e66ad54137cb61dcd083b8..2674bef8d06ef6f850f3999011757b5db9b55b3e 100644 (file)
--- a/init.h
+++ b/init.h
@@ -1009,6 +1009,7 @@ struct option_t MuttVars[] = {
   ** .dt %n .dd author's real name (or address if missing)
   ** .dt %O .dd (_O_riginal save folder)  Where mutt would formerly have
   **            stashed the message: list name or recipient name if no list
+  ** .dt %P .dd progress indicator for the builtin pager (how much of the file has been displayed)
   ** .dt %s .dd subject of the message
   ** .dt %S .dd status of the message (N/D/d/!/r/\(as)
   ** .dt %t .dd `to:' field (recipients)
@@ -1351,7 +1352,7 @@ struct option_t MuttVars[] = {
   ** default, Mutt will display the line after the last one on the screen
   ** at the top of the next page (0 lines of context).
   */
-  { "pager_format",    DT_STR,  R_PAGER, UL &PagerFmt, UL "-%Z- %C/%m: %-20.20n   %s" },
+  { "pager_format",    DT_STR,  R_PAGER, UL &PagerFmt, UL "-%Z- %C/%m: %-20.20n   %s%> -- (%P)" },
   /*
   ** .pp
   ** This variable controls the format of the one-line message ``status''
diff --git a/pager.c b/pager.c
index 533339d5914d0b09c4daa2821bdf144030c600c4..67bc0b4f1c0d1f77fc599b51a0c809b60371c695 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -1735,31 +1735,36 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra)
 
     if (redraw & REDRAW_STATUS)
     {
+      struct hdr_format_info hfi;
+      char pager_progress_str[4];
+
+      hfi.ctx = Context;
+      hfi.pager_progress = pager_progress_str;
+
+      if (last_pos < sb.st_size - 1)
+       snprintf(pager_progress_str, sizeof(pager_progress_str), "%lld%%", (100 * last_offset / sb.st_size));
+      else
+       strfcpy(pager_progress_str, (topline == 0) ? "all" : "end", sizeof(pager_progress_str));
+
       /* print out the pager status bar */
       SETCOLOR (MT_COLOR_STATUS);
       BKGDSET (MT_COLOR_STATUS);
       CLEARLINE (statusoffset);
       if (IsHeader (extra))
       {
-       size_t l1 = (COLS - 9) * MB_LEN_MAX;
+       size_t l1 = COLS * MB_LEN_MAX;
        size_t l2 = sizeof (buffer);
-       _mutt_make_string (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt),
-                          Context, extra->hdr, M_FORMAT_MAKEPRINT);
+       hfi.hdr = extra->hdr;
+       mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
       }
       else if (IsMsgAttach (extra))
       {
-       size_t l1 = (COLS - 9) * MB_LEN_MAX;
+       size_t l1 = COLS * MB_LEN_MAX;
        size_t l2 = sizeof (buffer);
-       _mutt_make_string (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt),
-                          Context, extra->bdy->hdr, M_FORMAT_MAKEPRINT);
+       hfi.hdr = extra->bdy->hdr;
+       mutt_make_string_info (buffer, l1 < l2 ? l1 : l2, NONULL (PagerFmt), &hfi, M_FORMAT_MAKEPRINT);
       }
-      mutt_paddstr (COLS-10, IsHeader (extra) || IsMsgAttach (extra) ?
-                   buffer : banner);
-      addstr (" -- (");
-      if (last_pos < sb.st_size - 1)
-       printw ("%d%%)", (int) (100 * last_offset / sb.st_size));
-      else
-       addstr (topline == 0 ? "all)" : "end)");
+      mutt_paddstr (COLS, IsHeader (extra) || IsMsgAttach (extra) ?  buffer : banner);
       BKGDSET (MT_COLOR_NORMAL);
       SETCOLOR (MT_COLOR_NORMAL);
     }
index c4d20a9416926826b182adcccef8a45c82894563..2b944e4002b3e2ab4e7cfa204bd26083eb884bdd 100644 (file)
--- a/protos.h
+++ b/protos.h
 void _mutt_make_string (char *, size_t, const char *, CONTEXT *,
        HEADER *, format_flag);
 
+struct hdr_format_info
+{
+  CONTEXT *ctx;
+  HEADER *hdr;
+  const char *pager_progress;
+};
+
+void mutt_make_string_info (char *, size_t, const char *, struct hdr_format_info *, format_flag);
+
 int mutt_extract_token (BUFFER *, BUFFER *, int);
 BUFFER * mutt_buffer_init (BUFFER *);
 BUFFER * mutt_buffer_from (BUFFER *, char *);