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.
14 #include <lib-lib/mem.h>
15 #include <lib-lib/str.h>
16 #include <lib-lib/macros.h>
19 #include "mutt_menu.h"
20 #include "mutt_curses.h"
31 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
33 static char *get_sort_str (char *buf, size_t buflen, int method)
35 snprintf (buf, buflen, "%s%s%s",
36 (method & SORT_REVERSE) ? "reverse-" : "",
37 (method & SORT_LAST) ? "last-" : "",
38 mutt_getnamebyvalue (method & SORT_MASK, SortMethods));
42 /* %b = number of incoming folders with unread messages [option]
43 * %B = short mailbox path
44 * %d = number of deleted messages [option]
45 * %f = full mailbox path
46 * %F = number of flagged messages [option]
48 * %l = length of mailbox (in bytes) [option]
49 * %m = total number of messages [option]
50 * %M = number of messages shown (virutal message count when limiting) [option]
51 * %n = number of new messages [option]
52 * %p = number of postponed messages [option]
53 * %P = percent of way through index
54 * %r = readonly/wontwrite/changed flag
55 * %s = current sorting method ($sort)
56 * %S = current aux sorting method ($sort_aux)
57 * %t = # of tagged messages [option]
58 * %v = Mutt-ng version
59 * %V = currently active limit pattern [option] */
60 static const char *status_format_str (char *buf, size_t buflen, char op,
61 const char *src, const char *prefix,
63 const char *elsestring,
64 unsigned long data, format_flag flags)
66 char fmt[SHORT_STRING], tmp[SHORT_STRING];
68 int count, optional = (flags & M_FORMAT_OPTIONAL);
69 MUTTMENU *menu = (MUTTMENU *) data;
75 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
76 snprintf (buf, buflen, fmt, buffy_check (0));
78 else if (!buffy_check (0))
83 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
85 if (Context && Context->compressinfo && Context->realpath) {
86 if ((p = strrchr (Context->realpath, '/')))
87 strfcpy (tmp, p + 1, sizeof (tmp));
89 strfcpy (tmp, Context->realpath, sizeof (tmp));
93 if (Context && Context->path) {
94 if ((p = strrchr (Context->path, '/')))
95 strfcpy (tmp, p + 1, sizeof (tmp));
97 strfcpy (tmp, Context->path, sizeof (tmp));
100 strfcpy (tmp, _("no mailbox"), sizeof (tmp));
101 snprintf (buf, buflen, fmt, tmp);
106 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
107 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
109 else if (!Context || !Context->deleted)
114 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
115 snprintf (buf, buflen, fmt, NONULL (Hostname));
119 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
120 #ifdef USE_COMPRESSED
121 if (Context && Context->compressinfo && Context->realpath) {
122 strfcpy (tmp, Context->realpath, sizeof (tmp));
123 mutt_pretty_mailbox (tmp);
127 if (Context && Context->path) {
128 strfcpy (tmp, Context->path, sizeof (tmp));
129 mutt_pretty_mailbox (tmp);
132 strfcpy (tmp, _("(no mailbox)"), sizeof (tmp));
133 snprintf (buf, buflen, fmt, tmp);
138 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
139 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
141 else if (!Context || !Context->flagged)
147 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
148 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
149 snprintf (buf, buflen, fmt, tmp);
151 else if (!Context || !Context->size)
157 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
158 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize : 0);
159 snprintf (buf, buflen, fmt, tmp);
161 else if (!Context || !Context->pattern)
167 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
168 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
170 else if (!Context || !Context->msgcount)
176 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
177 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
179 else if (!Context || !Context->pattern)
185 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
186 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
188 else if (!Context || Context->new <= 0)
194 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
195 snprintf (buf, buflen, fmt,
196 Context ? Context->unread - Context->new : 0);
198 else if (!Context || !(Context->unread - Context->new))
203 count = mutt_num_postponed (0);
205 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
206 snprintf (buf, buflen, fmt, count);
213 if (menu->top + menu->pagelen >= menu->max)
214 cp = menu->top ? "end" : "all";
216 count = (100 * (menu->top + menu->pagelen)) / menu->max;
217 snprintf (tmp, sizeof (tmp), "%d%%", count);
220 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
221 snprintf (buf, buflen, fmt, cp);
229 i = option (OPTATTACHMSG) ? 3 : ((Context->readonly ||
230 Context->dontwrite) ? 2 : (Context->
234 /* deleted doesn't necessarily mean changed in IMAP */
248 else if (i >= m_strlen(StChars))
258 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
259 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), Sort));
263 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
264 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), SortAux));
269 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
270 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
272 else if (!Context || !Context->tagged)
278 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
279 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
281 else if (!Context || !Context->unread)
286 m_strcpy(buf, buflen, mutt_make_version(0));
291 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
292 snprintf (buf, buflen, fmt,
293 (Context && Context->pattern) ? Context->pattern : "");
295 else if (!Context || !Context->pattern)
304 snprintf (buf, buflen, "%%%s%c", prefix, op);
309 menu_status_line (buf, buflen, menu, ifstring);
310 else if (flags & M_FORMAT_OPTIONAL)
311 menu_status_line (buf, buflen, menu, elsestring);
316 void menu_status_line (char* buf, size_t len, MUTTMENU* menu, const char* p) {
318 * if we have enough space for buffer, format lines to $COLS-$SidebarWidth
319 * only to not wrap past end of screen
321 int width = COLS - SW;
322 mutt_FormatString (buf, (width >= len ? len : (width + 1)),
323 p, status_format_str,
324 (unsigned long) menu, 0);