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>
17 #include <lib-lib/mapping.h>
19 #include <lib-ui/curses.h>
20 #include <lib-ui/menu.h>
32 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
34 static char *get_sort_str (char *buf, size_t buflen, int method)
36 snprintf (buf, buflen, "%s%s%s",
37 (method & SORT_REVERSE) ? "reverse-" : "",
38 (method & SORT_LAST) ? "last-" : "",
39 mutt_getnamebyvalue (method & SORT_MASK, SortMethods));
43 /* %b = number of incoming folders with unread messages [option]
44 * %B = short mailbox path
45 * %d = number of deleted messages [option]
46 * %f = full mailbox path
47 * %F = number of flagged messages [option]
49 * %l = length of mailbox (in bytes) [option]
50 * %m = total number of messages [option]
51 * %M = number of messages shown (virutal message count when limiting) [option]
52 * %n = number of new messages [option]
53 * %p = number of postponed messages [option]
54 * %P = percent of way through index
55 * %r = readonly/wontwrite/changed flag
56 * %s = current sorting method ($sort)
57 * %S = current aux sorting method ($sort_aux)
58 * %t = # of tagged messages [option]
59 * %v = Madmutt version
60 * %V = currently active limit pattern [option] */
61 static const char *status_format_str (char *buf, size_t buflen, char op,
62 const char *src, const char *prefix,
64 const char *elsestring,
65 unsigned long data, format_flag flags)
67 char fmt[SHORT_STRING], tmp[SHORT_STRING];
69 int count, optional = (flags & M_FORMAT_OPTIONAL);
70 MUTTMENU *menu = (MUTTMENU *) data;
76 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
77 snprintf (buf, buflen, fmt, buffy_check (0));
79 else if (!buffy_check (0))
84 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
85 if (Context && Context->compressinfo && Context->realpath) {
86 if ((p = strrchr (Context->realpath, '/')))
87 m_strcpy(tmp, sizeof(tmp), p + 1);
89 m_strcpy(tmp, sizeof(tmp), Context->realpath);
92 if (Context && Context->path) {
93 if ((p = strrchr (Context->path, '/')))
94 m_strcpy(tmp, sizeof(tmp), p + 1);
96 m_strcpy(tmp, sizeof(tmp), Context->path);
99 m_strcpy(tmp, sizeof(tmp), _("no mailbox"));
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 if (Context && Context->compressinfo && Context->realpath) {
120 m_strcpy(tmp, sizeof(tmp), Context->realpath);
121 mutt_pretty_mailbox (tmp);
124 if (Context && Context->path) {
125 m_strcpy(tmp, sizeof(tmp), Context->path);
126 mutt_pretty_mailbox (tmp);
129 m_strcpy(tmp, sizeof(tmp), _("(no mailbox)"));
130 snprintf (buf, buflen, fmt, tmp);
135 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
136 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
138 else if (!Context || !Context->flagged)
144 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
145 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
146 snprintf (buf, buflen, fmt, tmp);
148 else if (!Context || !Context->size)
154 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
155 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize : 0);
156 snprintf (buf, buflen, fmt, tmp);
158 else if (!Context || !Context->pattern)
164 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
165 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
167 else if (!Context || !Context->msgcount)
173 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
174 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
176 else if (!Context || !Context->pattern)
182 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
183 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
185 else if (!Context || Context->new <= 0)
191 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
192 snprintf (buf, buflen, fmt,
193 Context ? Context->unread - Context->new : 0);
195 else if (!Context || !(Context->unread - Context->new))
200 count = mutt_num_postponed (0);
202 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
203 snprintf (buf, buflen, fmt, count);
210 if (menu->top + menu->pagelen >= menu->max)
211 cp = menu->top ? "end" : "all";
213 count = (100 * (menu->top + menu->pagelen)) / menu->max;
214 snprintf (tmp, sizeof (tmp), "%d%%", count);
217 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
218 snprintf (buf, buflen, fmt, cp);
226 /* XXX: deleted doesn't necessarily mean changed in IMAP */
227 i = option (OPTATTACHMSG) ? 3
228 : ((Context->readonly || Context->dontwrite) ? 2
229 : (Context->changed || (Context-> magic != M_IMAP && Context->
235 else if (i >= m_strlen(StChars))
245 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
246 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), Sort));
250 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
251 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), SortAux));
256 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
257 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
259 else if (!Context || !Context->tagged)
265 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
266 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
268 else if (!Context || !Context->unread)
273 m_strcpy(buf, buflen, mutt_make_version(0));
278 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
279 snprintf (buf, buflen, fmt,
280 (Context && Context->pattern) ? Context->pattern : "");
282 else if (!Context || !Context->pattern)
291 snprintf (buf, buflen, "%%%s%c", prefix, op);
296 menu_status_line (buf, buflen, menu, ifstring);
297 else if (flags & M_FORMAT_OPTIONAL)
298 menu_status_line (buf, buflen, menu, elsestring);
303 void menu_status_line (char* buf, size_t len, MUTTMENU* menu, const char* p) {
305 * if we have enough space for buffer, format lines to $COLS-$SidebarWidth
306 * only to not wrap past end of screen
308 int width = COLS - SW;
309 mutt_FormatString (buf, (width >= len ? len : (width + 1)),
310 p, status_format_str,
311 (unsigned long) menu, 0);