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.
10 #include <lib-lib/lib-lib.h>
12 #include <lib-ui/curses.h>
13 #include <lib-ui/menu.h>
20 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
22 static char *get_sort_str (char *buf, ssize_t buflen, int method)
24 snprintf (buf, buflen, "%s%s%s",
25 (method & SORT_REVERSE) ? "reverse-" : "",
26 (method & SORT_LAST) ? "last-" : "",
27 mutt_getnamebyvalue (method & SORT_MASK, SortMethods));
31 /* %b = number of incoming folders with unread messages [option]
32 * %B = short mailbox path
33 * %d = number of deleted messages [option]
34 * %f = full mailbox path
35 * %F = number of flagged messages [option]
37 * %l = length of mailbox (in bytes) [option]
38 * %m = total number of messages [option]
39 * %M = number of messages shown (virutal message count when limiting) [option]
40 * %n = number of new messages [option]
41 * %p = number of postponed messages [option]
42 * %P = percent of way through index
43 * %r = readonly/wontwrite/changed flag
44 * %s = current sorting method ($sort)
45 * %S = current aux sorting method ($sort_aux)
46 * %t = # of tagged messages [option]
47 * %v = Madmutt version
48 * %V = currently active limit pattern [option] */
49 static const char *status_format_str (char *buf, ssize_t buflen, char op,
50 const char *src, const char *prefix,
52 const char *elsestring,
53 unsigned long data, format_flag flags)
55 char fmt[SHORT_STRING], tmp[SHORT_STRING];
57 int count, optional = (flags & M_FORMAT_OPTIONAL);
58 MUTTMENU *menu = (MUTTMENU *) data;
64 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
65 snprintf (buf, buflen, fmt, buffy_check (0));
67 else if (!buffy_check (0))
72 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
73 if (Context && Context->compressinfo && Context->realpath) {
74 if ((p = strrchr (Context->realpath, '/')))
75 m_strcpy(tmp, sizeof(tmp), p + 1);
77 m_strcpy(tmp, sizeof(tmp), Context->realpath);
80 if (Context && Context->path) {
81 if ((p = strrchr (Context->path, '/')))
82 m_strcpy(tmp, sizeof(tmp), p + 1);
84 m_strcpy(tmp, sizeof(tmp), Context->path);
87 m_strcpy(tmp, sizeof(tmp), _("no mailbox"));
88 snprintf (buf, buflen, fmt, tmp);
93 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
94 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
96 else if (!Context || !Context->deleted)
101 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
102 snprintf (buf, buflen, fmt, NONULL (Hostname));
106 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
107 if (Context && Context->compressinfo && Context->realpath) {
108 m_strcpy(tmp, sizeof(tmp), Context->realpath);
109 mutt_pretty_mailbox (tmp);
112 if (Context && Context->path) {
113 m_strcpy(tmp, sizeof(tmp), Context->path);
114 mutt_pretty_mailbox (tmp);
117 m_strcpy(tmp, sizeof(tmp), _("(no mailbox)"));
118 snprintf (buf, buflen, fmt, tmp);
123 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
124 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
126 else if (!Context || !Context->flagged)
132 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
133 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
134 snprintf (buf, buflen, fmt, tmp);
136 else if (!Context || !Context->size)
142 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
143 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize : 0);
144 snprintf (buf, buflen, fmt, tmp);
146 else if (!Context || !Context->pattern)
152 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
153 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
155 else if (!Context || !Context->msgcount)
161 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
162 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
164 else if (!Context || !Context->pattern)
170 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
171 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
173 else if (!Context || Context->new <= 0)
179 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
180 snprintf (buf, buflen, fmt,
181 Context ? Context->unread - Context->new : 0);
183 else if (!Context || !(Context->unread - Context->new))
188 count = mutt_num_postponed (0);
190 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
191 snprintf (buf, buflen, fmt, count);
198 if (menu->top + menu->pagelen >= menu->max)
199 cp = menu->top ? "end" : "all";
201 count = (100 * (menu->top + menu->pagelen)) / menu->max;
202 snprintf (tmp, sizeof (tmp), "%d%%", count);
205 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
206 snprintf (buf, buflen, fmt, cp);
214 /* XXX: deleted doesn't necessarily mean changed in IMAP */
215 i = option (OPTATTACHMSG) ? 3
216 : ((Context->readonly || Context->dontwrite) ? 2
217 : (Context->changed || (Context-> magic != M_IMAP && Context->
223 else if (i >= m_strlen(StChars))
233 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
234 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), Sort));
238 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
239 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), SortAux));
244 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
245 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
247 else if (!Context || !Context->tagged)
253 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
254 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
256 else if (!Context || !Context->unread)
261 m_strcpy(buf, buflen, mutt_make_version(0));
266 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
267 snprintf (buf, buflen, fmt,
268 (Context && Context->pattern) ? Context->pattern : "");
270 else if (!Context || !Context->pattern)
279 snprintf (buf, buflen, "%%%s%c", prefix, op);
284 menu_status_line (buf, buflen, menu, ifstring);
285 else if (flags & M_FORMAT_OPTIONAL)
286 menu_status_line (buf, buflen, menu, elsestring);
291 void menu_status_line (char* buf, ssize_t len, MUTTMENU* menu, const char* p) {
293 * if we have enough space for buffer, format lines to $COLS-$SidebarWidth
294 * only to not wrap past end of screen
296 int width = COLS - SW;
297 mutt_FormatString (buf, (width >= len ? len : (width + 1)),
298 p, status_format_str,
299 (unsigned long) menu, 0);