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-ui/lib-ui.h>
12 #include <lib-ui/menu.h>
13 #include <lib-mx/mx.h>
19 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
21 static char *get_sort_str (char *buf, ssize_t buflen, int method)
23 snprintf (buf, buflen, "%s%s%s",
24 (method & SORT_REVERSE) ? "reverse-" : "",
25 (method & SORT_LAST) ? "last-" : "",
26 mutt_getnamebyvalue (method & SORT_MASK, SortMethods));
30 /* %b = number of incoming folders with unread messages [option]
31 * %B = short mailbox path
32 * %d = number of deleted messages [option]
33 * %f = full mailbox path
34 * %F = number of flagged messages [option]
36 * %l = length of mailbox (in bytes) [option]
37 * %m = total number of messages [option]
38 * %M = number of messages shown (virutal message count when limiting) [option]
39 * %n = number of new messages [option]
40 * %p = number of postponed messages [option]
41 * %P = percent of way through index
42 * %r = readonly/wontwrite/changed flag
43 * %s = current sorting method ($sort)
44 * %S = current aux sorting method ($sort_aux)
45 * %t = # of tagged messages [option]
46 * %v = Madmutt version
47 * %V = currently active limit pattern [option] */
49 status_format_str(char *buf, ssize_t buflen, char op, const char *src,
50 const char *prefix, const char *ifstr, const char *elstr,
51 anytype data, format_flag flags)
53 char fmt[STRING], tmp[STRING];
55 int count, optional = (flags & M_FORMAT_OPTIONAL);
56 MUTTMENU *menu = data.ptr;
62 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
63 snprintf (buf, buflen, fmt, buffy_check (0));
65 else if (!buffy_check (0))
70 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
71 if (Context && Context->cinfo && Context->realpath) {
72 if ((p = strrchr (Context->realpath, '/')))
73 m_strcpy(tmp, sizeof(tmp), p + 1);
75 m_strcpy(tmp, sizeof(tmp), Context->realpath);
78 if (Context && Context->path) {
79 if ((p = strrchr (Context->path, '/')))
80 m_strcpy(tmp, sizeof(tmp), p + 1);
82 m_strcpy(tmp, sizeof(tmp), Context->path);
85 m_strcpy(tmp, sizeof(tmp), _("no mailbox"));
86 snprintf (buf, buflen, fmt, tmp);
91 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
92 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
94 else if (!Context || !Context->deleted)
99 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
100 snprintf (buf, buflen, fmt, NONULL (mod_core.shorthost));
104 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
105 if (Context && Context->cinfo && Context->realpath) {
106 m_strcpy(tmp, sizeof(tmp), Context->realpath);
107 mutt_pretty_mailbox (tmp);
109 if (Context && Context->path) {
110 m_strcpy(tmp, sizeof(tmp), Context->path);
111 mutt_pretty_mailbox (tmp);
113 m_strcpy(tmp, sizeof(tmp), _("(no mailbox)"));
115 snprintf (buf, buflen, fmt, tmp);
120 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
121 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
123 else if (!Context || !Context->flagged)
129 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
130 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
131 snprintf (buf, buflen, fmt, tmp);
133 else if (!Context || !Context->size)
139 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
140 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize : 0);
141 snprintf (buf, buflen, fmt, tmp);
143 else if (!Context || !Context->pattern)
149 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
150 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
152 else if (!Context || !Context->msgcount)
158 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
159 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
161 else if (!Context || !Context->pattern)
167 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
168 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
170 else if (!Context || Context->new <= 0)
176 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
177 snprintf (buf, buflen, fmt,
178 Context ? Context->unread - Context->new : 0);
180 else if (!Context || !(Context->unread - Context->new))
185 count = mutt_num_postponed (0);
187 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
188 snprintf (buf, buflen, fmt, count);
195 if (menu->top + menu->pagelen >= menu->max)
196 cp = menu->top ? "end" : "all";
198 count = (100 * (menu->top + menu->pagelen)) / menu->max;
199 snprintf (tmp, sizeof (tmp), "%d%%", count);
202 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
203 snprintf (buf, buflen, fmt, cp);
211 /* XXX: deleted doesn't necessarily mean changed in IMAP */
212 i = option (OPTATTACHMSG) ? 3
213 : ((Context->readonly || Context->dontwrite) ? 2
214 : (Context->changed || (Context-> magic != M_IMAP && Context->
220 else if (i >= m_strlen(StChars))
230 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
231 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), Sort));
235 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
236 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), SortAux));
241 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
242 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
244 else if (!Context || !Context->tagged)
250 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
251 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
253 else if (!Context || !Context->unread)
258 m_strcpy(buf, buflen, mutt_make_version());
263 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
264 snprintf (buf, buflen, fmt,
265 (Context && Context->pattern) ? Context->pattern : "");
267 else if (!Context || !Context->pattern)
280 if (flags & M_FORMAT_OPTIONAL)
281 menu_status_line(buf, buflen, menu, optional ? ifstr : elstr);
286 void menu_status_line(char* buf, ssize_t len, MUTTMENU* menu, const char* p)
288 m_strformat(buf, len, COLS - SW, p, status_format_str, menu, 0);