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>
20 #include "mutt_menu.h"
21 #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 = Madmutt 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);
84 if (Context && Context->compressinfo && Context->realpath) {
85 if ((p = strrchr (Context->realpath, '/')))
86 m_strcpy(tmp, sizeof(tmp), p + 1);
88 m_strcpy(tmp, sizeof(tmp), Context->realpath);
91 if (Context && Context->path) {
92 if ((p = strrchr (Context->path, '/')))
93 m_strcpy(tmp, sizeof(tmp), p + 1);
95 m_strcpy(tmp, sizeof(tmp), Context->path);
98 m_strcpy(tmp, sizeof(tmp), _("no mailbox"));
99 snprintf (buf, buflen, fmt, tmp);
104 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
105 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
107 else if (!Context || !Context->deleted)
112 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
113 snprintf (buf, buflen, fmt, NONULL (Hostname));
117 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
118 if (Context && Context->compressinfo && Context->realpath) {
119 m_strcpy(tmp, sizeof(tmp), Context->realpath);
120 mutt_pretty_mailbox (tmp);
123 if (Context && Context->path) {
124 m_strcpy(tmp, sizeof(tmp), Context->path);
125 mutt_pretty_mailbox (tmp);
128 m_strcpy(tmp, sizeof(tmp), _("(no mailbox)"));
129 snprintf (buf, buflen, fmt, tmp);
134 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
135 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
137 else if (!Context || !Context->flagged)
143 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
144 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
145 snprintf (buf, buflen, fmt, tmp);
147 else if (!Context || !Context->size)
153 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
154 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize : 0);
155 snprintf (buf, buflen, fmt, tmp);
157 else if (!Context || !Context->pattern)
163 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
164 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
166 else if (!Context || !Context->msgcount)
172 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
173 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
175 else if (!Context || !Context->pattern)
181 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
182 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
184 else if (!Context || Context->new <= 0)
190 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
191 snprintf (buf, buflen, fmt,
192 Context ? Context->unread - Context->new : 0);
194 else if (!Context || !(Context->unread - Context->new))
199 count = mutt_num_postponed (0);
201 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
202 snprintf (buf, buflen, fmt, count);
209 if (menu->top + menu->pagelen >= menu->max)
210 cp = menu->top ? "end" : "all";
212 count = (100 * (menu->top + menu->pagelen)) / menu->max;
213 snprintf (tmp, sizeof (tmp), "%d%%", count);
216 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
217 snprintf (buf, buflen, fmt, cp);
225 /* XXX: deleted doesn't necessarily mean changed in IMAP */
226 i = option (OPTATTACHMSG) ? 3
227 : ((Context->readonly || Context->dontwrite) ? 2
228 : (Context->changed || (Context-> magic != M_IMAP && Context->
234 else if (i >= m_strlen(StChars))
244 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
245 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), Sort));
249 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
250 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), SortAux));
255 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
256 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
258 else if (!Context || !Context->tagged)
264 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
265 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
267 else if (!Context || !Context->unread)
272 m_strcpy(buf, buflen, mutt_make_version(0));
277 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
278 snprintf (buf, buflen, fmt,
279 (Context && Context->pattern) ? Context->pattern : "");
281 else if (!Context || !Context->pattern)
290 snprintf (buf, buflen, "%%%s%c", prefix, op);
295 menu_status_line (buf, buflen, menu, ifstring);
296 else if (flags & M_FORMAT_OPTIONAL)
297 menu_status_line (buf, buflen, menu, elsestring);
302 void menu_status_line (char* buf, size_t len, MUTTMENU* menu, const char* p) {
304 * if we have enough space for buffer, format lines to $COLS-$SidebarWidth
305 * only to not wrap past end of screen
307 int width = COLS - SW;
308 mutt_FormatString (buf, (width >= len ? len : (width + 1)),
309 p, status_format_str,
310 (unsigned long) menu, 0);