From: Michael Elkins Date: Sun, 15 Apr 2007 22:43:57 +0000 (-0700) Subject: Removed hardcoded pager progress indicator and add %P format code to $pager_status... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=79985c786a0c3968af6510f1e4b9b3bace87fbcc;p=neomutt Removed hardcoded pager progress indicator and add %P format code to $pager_status which contains the same information. Append "%> -- (%P)" to $pager_status to emulate old behavior. Closes #2087. --- diff --git a/hdrline.c b/hdrline.c index 43bb679ba..a4cfb263c 100644 --- 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 28d264b6b..2674bef8d 100644 --- 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 533339d59..67bc0b4f1 100644 --- 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); } diff --git a/protos.h b/protos.h index c4d20a941..2b944e400 100644 --- a/protos.h +++ b/protos.h @@ -29,6 +29,15 @@ 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 *);