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>
14 #include <lib-mx/mx.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] */
50 status_format_str(char *buf, ssize_t buflen, char op, const char *src,
51 const char *prefix, const char *ifstr, const char *elstr,
52 anytype data, format_flag flags)
54 char fmt[STRING], tmp[STRING];
56 int count, optional = (flags & M_FORMAT_OPTIONAL);
57 MUTTMENU *menu = data.ptr;
63 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
64 snprintf (buf, buflen, fmt, buffy_check (0));
66 else if (!buffy_check (0))
71 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
72 if (Context && Context->cinfo && Context->realpath) {
73 if ((p = strrchr (Context->realpath, '/')))
74 m_strcpy(tmp, sizeof(tmp), p + 1);
76 m_strcpy(tmp, sizeof(tmp), Context->realpath);
79 if (Context && Context->path) {
80 if ((p = strrchr (Context->path, '/')))
81 m_strcpy(tmp, sizeof(tmp), p + 1);
83 m_strcpy(tmp, sizeof(tmp), Context->path);
86 m_strcpy(tmp, sizeof(tmp), _("no mailbox"));
87 snprintf (buf, buflen, fmt, tmp);
92 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
93 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
95 else if (!Context || !Context->deleted)
100 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
101 snprintf (buf, buflen, fmt, NONULL (mod_core.shorthost));
105 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
106 if (Context && Context->cinfo && Context->realpath) {
107 m_strcpy(tmp, sizeof(tmp), Context->realpath);
108 mutt_pretty_mailbox (tmp);
110 if (Context && Context->path) {
111 m_strcpy(tmp, sizeof(tmp), Context->path);
112 mutt_pretty_mailbox (tmp);
114 m_strcpy(tmp, sizeof(tmp), _("(no mailbox)"));
116 snprintf (buf, buflen, fmt, tmp);
121 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
122 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
124 else if (!Context || !Context->flagged)
130 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
131 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
132 snprintf (buf, buflen, fmt, tmp);
134 else if (!Context || !Context->size)
140 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
141 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize : 0);
142 snprintf (buf, buflen, fmt, tmp);
144 else if (!Context || !Context->pattern)
150 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
151 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
153 else if (!Context || !Context->msgcount)
159 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
160 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
162 else if (!Context || !Context->pattern)
168 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
169 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
171 else if (!Context || Context->new <= 0)
177 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
178 snprintf (buf, buflen, fmt,
179 Context ? Context->unread - Context->new : 0);
181 else if (!Context || !(Context->unread - Context->new))
186 count = mutt_num_postponed (0);
188 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
189 snprintf (buf, buflen, fmt, count);
196 if (menu->top + menu->pagelen >= menu->max)
197 cp = menu->top ? "end" : "all";
199 count = (100 * (menu->top + menu->pagelen)) / menu->max;
200 snprintf (tmp, sizeof (tmp), "%d%%", count);
203 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
204 snprintf (buf, buflen, fmt, cp);
212 /* XXX: deleted doesn't necessarily mean changed in IMAP */
213 i = option (OPTATTACHMSG) ? 3
214 : ((Context->readonly || Context->dontwrite) ? 2
215 : (Context->changed || (Context-> magic != M_IMAP && Context->
221 else if (i >= m_strlen(StChars))
231 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
232 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), Sort));
236 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
237 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), SortAux));
242 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
243 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
245 else if (!Context || !Context->tagged)
251 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
252 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
254 else if (!Context || !Context->unread)
259 m_strcpy(buf, buflen, mutt_make_version());
264 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
265 snprintf (buf, buflen, fmt,
266 (Context && Context->pattern) ? Context->pattern : "");
268 else if (!Context || !Context->pattern)
281 if (flags & M_FORMAT_OPTIONAL)
282 menu_status_line(buf, buflen, menu, optional ? ifstr : elstr);
287 void menu_status_line(char* buf, ssize_t len, MUTTMENU* menu, const char* p)
289 m_strformat(buf, len, COLS - SW, p, status_format_str, menu, 0);