2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
15 #include "mutt_menu.h"
16 #include "mutt_curses.h"
30 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
32 static char *get_sort_str (char *buf, size_t buflen, int method)
34 snprintf (buf, buflen, "%s%s%s",
35 (method & SORT_REVERSE) ? "reverse-" : "",
36 (method & SORT_LAST) ? "last-" : "",
37 mutt_getnamebyvalue (method & SORT_MASK, SortMethods));
41 /* %b = number of incoming folders with unread messages [option]
42 * %B = short mailbox path
43 * %d = number of deleted messages [option]
44 * %f = full mailbox path
45 * %F = number of flagged messages [option]
47 * %l = length of mailbox (in bytes) [option]
48 * %m = total number of messages [option]
49 * %M = number of messages shown (virutal message count when limiting) [option]
50 * %n = number of new messages [option]
51 * %p = number of postponed messages [option]
52 * %P = percent of way through index
53 * %r = readonly/wontwrite/changed flag
54 * %s = current sorting method ($sort)
55 * %S = current aux sorting method ($sort_aux)
56 * %t = # of tagged messages [option]
57 * %v = Mutt-ng version
58 * %V = currently active limit pattern [option] */
59 static const char *status_format_str (char *buf, size_t buflen, char op,
60 const char *src, const char *prefix,
62 const char *elsestring,
63 unsigned long data, format_flag flags)
65 char fmt[SHORT_STRING], tmp[SHORT_STRING];
67 int count, optional = (flags & M_FORMAT_OPTIONAL);
68 MUTTMENU *menu = (MUTTMENU *) data;
74 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
75 snprintf (buf, buflen, fmt, buffy_check (0));
77 else if (!buffy_check (0))
82 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
84 if (Context && Context->compressinfo && Context->realpath) {
85 if ((p = strrchr (Context->realpath, '/')))
86 strfcpy (tmp, p + 1, sizeof (tmp));
88 strfcpy (tmp, Context->realpath, sizeof (tmp));
92 if (Context && Context->path) {
93 if ((p = strrchr (Context->path, '/')))
94 strfcpy (tmp, p + 1, sizeof (tmp));
96 strfcpy (tmp, Context->path, sizeof (tmp));
99 strfcpy (tmp, _("no mailbox"), sizeof (tmp));
100 snprintf (buf, buflen, fmt, tmp);
105 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
106 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
108 else if (!Context || !Context->deleted)
113 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
114 snprintf (buf, buflen, fmt, NONULL (Hostname));
118 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
119 #ifdef USE_COMPRESSED
120 if (Context && Context->compressinfo && Context->realpath) {
121 strfcpy (tmp, Context->realpath, sizeof (tmp));
122 mutt_pretty_mailbox (tmp);
126 if (Context && Context->path) {
127 strfcpy (tmp, Context->path, sizeof (tmp));
128 mutt_pretty_mailbox (tmp);
131 strfcpy (tmp, _("(no mailbox)"), sizeof (tmp));
132 snprintf (buf, buflen, fmt, tmp);
137 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
138 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
140 else if (!Context || !Context->flagged)
146 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
147 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
148 snprintf (buf, buflen, fmt, tmp);
150 else if (!Context || !Context->size)
156 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
157 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize : 0);
158 snprintf (buf, buflen, fmt, tmp);
160 else if (!Context || !Context->pattern)
166 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
167 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
169 else if (!Context || !Context->msgcount)
175 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
176 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
178 else if (!Context || !Context->pattern)
184 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
185 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
187 else if (!Context || Context->new <= 0)
193 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
194 snprintf (buf, buflen, fmt,
195 Context ? Context->unread - Context->new : 0);
197 else if (!Context || !(Context->unread - Context->new))
202 count = mutt_num_postponed (0);
204 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
205 snprintf (buf, buflen, fmt, count);
212 if (menu->top + menu->pagelen >= menu->max)
213 cp = menu->top ? "end" : "all";
215 count = (100 * (menu->top + menu->pagelen)) / menu->max;
216 snprintf (tmp, sizeof (tmp), "%d%%", count);
219 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
220 snprintf (buf, buflen, fmt, cp);
228 i = option (OPTATTACHMSG) ? 3 : ((Context->readonly ||
229 Context->dontwrite) ? 2 : (Context->
233 /* deleted doesn't necessarily mean changed in IMAP */
247 else if (i >= str_len (StChars))
257 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
258 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), Sort));
262 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
263 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), SortAux));
268 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
269 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
271 else if (!Context || !Context->tagged)
277 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
278 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
280 else if (!Context || !Context->unread)
285 strncpy (buf, mutt_make_version (0), buflen);
290 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
291 snprintf (buf, buflen, fmt,
292 (Context && Context->pattern) ? Context->pattern : "");
294 else if (!Context || !Context->pattern)
303 snprintf (buf, buflen, "%%%s%c", prefix, op);
308 menu_status_line (buf, buflen, menu, ifstring);
309 else if (flags & M_FORMAT_OPTIONAL)
310 menu_status_line (buf, buflen, menu, elsestring);
315 void menu_status_line (char* buf, size_t len, MUTTMENU* menu, const char* p) {
317 * if we have enough space for buffer, format lines to $COLS-$SidebarWidth
318 * only to not wrap past end of screen
320 int width = COLS - SW;
321 mutt_FormatString (buf, (width >= len ? len : (width + 1)),
322 p, status_format_str,
323 (unsigned long) menu, 0);