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/lib-lib.h>
16 #include <lib-ui/curses.h>
17 #include <lib-ui/menu.h>
29 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
31 static char *get_sort_str (char *buf, ssize_t buflen, int method)
33 snprintf (buf, buflen, "%s%s%s",
34 (method & SORT_REVERSE) ? "reverse-" : "",
35 (method & SORT_LAST) ? "last-" : "",
36 mutt_getnamebyvalue (method & SORT_MASK, SortMethods));
40 /* %b = number of incoming folders with unread messages [option]
41 * %B = short mailbox path
42 * %d = number of deleted messages [option]
43 * %f = full mailbox path
44 * %F = number of flagged messages [option]
46 * %l = length of mailbox (in bytes) [option]
47 * %m = total number of messages [option]
48 * %M = number of messages shown (virutal message count when limiting) [option]
49 * %n = number of new messages [option]
50 * %p = number of postponed messages [option]
51 * %P = percent of way through index
52 * %r = readonly/wontwrite/changed flag
53 * %s = current sorting method ($sort)
54 * %S = current aux sorting method ($sort_aux)
55 * %t = # of tagged messages [option]
56 * %v = Madmutt version
57 * %V = currently active limit pattern [option] */
58 static const char *status_format_str (char *buf, ssize_t buflen, char op,
59 const char *src, const char *prefix,
61 const char *elsestring,
62 unsigned long data, format_flag flags)
64 char fmt[SHORT_STRING], tmp[SHORT_STRING];
66 int count, optional = (flags & M_FORMAT_OPTIONAL);
67 MUTTMENU *menu = (MUTTMENU *) data;
73 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
74 snprintf (buf, buflen, fmt, buffy_check (0));
76 else if (!buffy_check (0))
81 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
82 if (Context && Context->compressinfo && Context->realpath) {
83 if ((p = strrchr (Context->realpath, '/')))
84 m_strcpy(tmp, sizeof(tmp), p + 1);
86 m_strcpy(tmp, sizeof(tmp), Context->realpath);
89 if (Context && Context->path) {
90 if ((p = strrchr (Context->path, '/')))
91 m_strcpy(tmp, sizeof(tmp), p + 1);
93 m_strcpy(tmp, sizeof(tmp), Context->path);
96 m_strcpy(tmp, sizeof(tmp), _("no mailbox"));
97 snprintf (buf, buflen, fmt, tmp);
102 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
103 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
105 else if (!Context || !Context->deleted)
110 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
111 snprintf (buf, buflen, fmt, NONULL (Hostname));
115 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
116 if (Context && Context->compressinfo && Context->realpath) {
117 m_strcpy(tmp, sizeof(tmp), Context->realpath);
118 mutt_pretty_mailbox (tmp);
121 if (Context && Context->path) {
122 m_strcpy(tmp, sizeof(tmp), Context->path);
123 mutt_pretty_mailbox (tmp);
126 m_strcpy(tmp, sizeof(tmp), _("(no mailbox)"));
127 snprintf (buf, buflen, fmt, tmp);
132 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
133 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
135 else if (!Context || !Context->flagged)
141 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
142 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
143 snprintf (buf, buflen, fmt, tmp);
145 else if (!Context || !Context->size)
151 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
152 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize : 0);
153 snprintf (buf, buflen, fmt, tmp);
155 else if (!Context || !Context->pattern)
161 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
162 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
164 else if (!Context || !Context->msgcount)
170 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
171 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
173 else if (!Context || !Context->pattern)
179 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
180 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
182 else if (!Context || Context->new <= 0)
188 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
189 snprintf (buf, buflen, fmt,
190 Context ? Context->unread - Context->new : 0);
192 else if (!Context || !(Context->unread - Context->new))
197 count = mutt_num_postponed (0);
199 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
200 snprintf (buf, buflen, fmt, count);
207 if (menu->top + menu->pagelen >= menu->max)
208 cp = menu->top ? "end" : "all";
210 count = (100 * (menu->top + menu->pagelen)) / menu->max;
211 snprintf (tmp, sizeof (tmp), "%d%%", count);
214 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
215 snprintf (buf, buflen, fmt, cp);
223 /* XXX: deleted doesn't necessarily mean changed in IMAP */
224 i = option (OPTATTACHMSG) ? 3
225 : ((Context->readonly || Context->dontwrite) ? 2
226 : (Context->changed || (Context-> magic != M_IMAP && Context->
232 else if (i >= m_strlen(StChars))
242 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
243 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), Sort));
247 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
248 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), SortAux));
253 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
254 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
256 else if (!Context || !Context->tagged)
262 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
263 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
265 else if (!Context || !Context->unread)
270 m_strcpy(buf, buflen, mutt_make_version(0));
275 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
276 snprintf (buf, buflen, fmt,
277 (Context && Context->pattern) ? Context->pattern : "");
279 else if (!Context || !Context->pattern)
288 snprintf (buf, buflen, "%%%s%c", prefix, op);
293 menu_status_line (buf, buflen, menu, ifstring);
294 else if (flags & M_FORMAT_OPTIONAL)
295 menu_status_line (buf, buflen, menu, elsestring);
300 void menu_status_line (char* buf, ssize_t len, MUTTMENU* menu, const char* p) {
302 * if we have enough space for buffer, format lines to $COLS-$SidebarWidth
303 * only to not wrap past end of screen
305 int width = COLS - SW;
306 mutt_FormatString (buf, (width >= len ? len : (width + 1)),
307 p, status_format_str,
308 (unsigned long) menu, 0);