2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 #include "mutt_menu.h"
25 #include "mutt_curses.h"
34 static char *get_sort_str (char *buf, size_t buflen, int method)
36 snprintf (buf, buflen, "%s%s%s",
37 (method & SORT_REVERSE) ? "reverse-" : "",
38 (method & SORT_LAST) ? "last-" : "",
39 mutt_getnamebyvalue (method & SORT_MASK, SortMethods));
43 /* %b = number of incoming folders with unread messages [option]
44 * %B = short mailbox path
45 * %d = number of deleted messages [option]
46 * %f = full mailbox path
47 * %F = number of flagged messages [option]
49 * %l = length of mailbox (in bytes) [option]
50 * %m = total number of messages [option]
51 * %M = number of messages shown (virutal message count when limiting) [option]
52 * %n = number of new messages [option]
53 * %p = number of postponed messages [option]
54 * %P = percent of way through index
55 * %r = readonly/wontwrite/changed flag
56 * %s = current sorting method ($sort)
57 * %S = current aux sorting method ($sort_aux)
58 * %t = # of tagged messages [option]
59 * %v = Mutt-ng version
60 * %V = currently active limit pattern [option] */
62 status_format_str (char *buf, size_t buflen, char op, const char *src,
63 const char *prefix, const char *ifstring,
64 const char *elsestring,
65 unsigned long data, format_flag flags)
67 char fmt[SHORT_STRING], tmp[SHORT_STRING], *cp, *p;
68 int count, optional = (flags & M_FORMAT_OPTIONAL);
69 MUTTMENU *menu = (MUTTMENU *) data;
77 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
78 snprintf (buf, buflen, fmt, mutt_buffy_check (0));
80 else if (!mutt_buffy_check (0))
85 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
87 if (Context && Context->compressinfo && Context->realpath)
89 if ((p = strrchr (Context->realpath, '/')))
90 strfcpy (tmp, p + 1, sizeof (tmp));
92 strfcpy (tmp, Context->realpath, sizeof (tmp));
96 if (Context && Context->path)
98 if ((p = strrchr (Context->path, '/')))
99 strfcpy (tmp, p + 1, sizeof (tmp));
101 strfcpy (tmp, Context->path, sizeof (tmp));
104 strfcpy (tmp, _("no mailbox"), sizeof (tmp));
105 snprintf (buf, buflen, fmt, tmp);
111 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
112 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
114 else if (!Context || !Context->deleted)
119 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
120 snprintf (buf, buflen, fmt, NONULL(Hostname));
124 snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
125 #ifdef USE_COMPRESSED
126 if (Context && Context->compressinfo && Context->realpath)
128 strfcpy (tmp, Context->realpath, sizeof (tmp));
129 mutt_pretty_mailbox (tmp);
133 if (Context && Context->path)
135 strfcpy (tmp, Context->path, sizeof (tmp));
136 mutt_pretty_mailbox (tmp);
139 strfcpy (tmp, _("(no mailbox)"), sizeof (tmp));
140 snprintf (buf, buflen, fmt, tmp);
146 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
147 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
149 else if (!Context || !Context->flagged)
156 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
157 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
158 snprintf (buf, buflen, fmt, tmp);
160 else if (!Context || !Context->size)
167 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
168 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize: 0);
169 snprintf (buf, buflen, fmt, tmp);
171 else if (!Context || !Context->pattern)
178 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
179 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
181 else if (!Context || !Context->msgcount)
188 snprintf (fmt, sizeof(fmt), "%%%sd", prefix);
189 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
191 else if (!Context || !Context->pattern)
198 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
199 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
201 else if (!Context || !Context->new)
208 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
209 snprintf (buf, buflen, fmt, Context ? Context->unread - Context->new : 0);
211 else if (!Context || !(Context->unread - Context->new))
216 count = mutt_num_postponed (0);
219 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
220 snprintf (buf, buflen, fmt, count);
227 if (menu->top + menu->pagelen >= menu->max)
228 cp = menu->top ? "end" : "all";
231 count = (100 * (menu->top + menu->pagelen)) / menu->max;
232 snprintf (tmp, sizeof (tmp), "%d%%", count);
235 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
236 snprintf (buf, buflen, fmt, cp);
245 i = option(OPTATTACHMSG) ? 3 : ((Context->readonly ||
246 Context->dontwrite) ? 2 : (Context->changed || (
248 /* deleted doesn't necessarily mean changed in IMAP */
249 Context->magic != M_IMAP &&
251 Context->deleted)) ? 1 : 0);
256 else if (i >= mutt_strlen(StChars))
266 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
267 snprintf (buf, buflen, fmt,
268 get_sort_str (tmp, sizeof (tmp), Sort));
272 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
273 snprintf (buf, buflen, fmt,
274 get_sort_str (tmp, sizeof (tmp), SortAux));
280 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
281 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
283 else if (!Context || !Context->tagged)
290 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
291 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
293 else if (!Context || !Context->unread)
298 snprintf (fmt, sizeof (fmt), "Mutt-ng %%s");
299 snprintf (buf, buflen, fmt, MUTT_VERSION);
305 snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
306 snprintf (buf, buflen, fmt, (Context && Context->pattern) ? Context->pattern : "");
308 else if (!Context || !Context->pattern)
317 snprintf (buf, buflen, "%%%s%c", prefix, op);
322 menu_status_line (buf, buflen, menu, ifstring);
323 else if (flags & M_FORMAT_OPTIONAL)
324 menu_status_line (buf, buflen, menu, elsestring);
329 void menu_status_line (char *buf, size_t buflen, MUTTMENU *menu, const char *p)
331 mutt_FormatString (buf, buflen, p, status_format_str, (unsigned long) menu, 0);