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 * %d = number of deleted messages [option]
45 * %f = full mailbox path
46 * %F = number of flagged messages [option]
48 * %l = length of mailbox (in bytes) [option]
49 * %m = total number of messages [option]
50 * %M = number of messages shown (virutal message count when limiting) [option]
51 * %n = number of new messages [option]
52 * %p = number of postponed messages [option]
53 * %P = percent of way through index
54 * %r = readonly/wontwrite/changed flag
55 * %s = current sorting method ($sort)
56 * %S = current aux sorting method ($sort_aux)
57 * %t = # of tagged messages [option]
59 * %V = currently active limit pattern [option] */
61 status_format_str (char *buf, size_t buflen, char op, const char *src,
62 const char *prefix, const char *ifstring,
63 const char *elsestring,
64 unsigned long data, format_flag flags)
66 char fmt[SHORT_STRING], tmp[SHORT_STRING], *cp;
67 int count, optional = (flags & M_FORMAT_OPTIONAL);
68 MUTTMENU *menu = (MUTTMENU *) data;
76 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
77 snprintf (buf, buflen, fmt, mutt_buffy_check (0));
79 else if (!mutt_buffy_check (0))
86 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
87 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
89 else if (!Context || !Context->deleted)
94 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
95 snprintf (buf, buflen, fmt, NONULL(Hostname));
99 snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
100 #ifdef USE_COMPRESSED
101 if (Context && Context->compressinfo && Context->realpath)
103 strfcpy (tmp, Context->realpath, sizeof (tmp));
104 mutt_pretty_mailbox (tmp);
108 if (Context && Context->path)
110 strfcpy (tmp, Context->path, sizeof (tmp));
111 mutt_pretty_mailbox (tmp);
114 strfcpy (tmp, _("(no mailbox)"), sizeof (tmp));
115 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)
131 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
132 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
133 snprintf (buf, buflen, fmt, tmp);
135 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)
153 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
154 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
156 else if (!Context || !Context->msgcount)
163 snprintf (fmt, sizeof(fmt), "%%%sd", prefix);
164 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
166 else if (!Context || !Context->pattern)
173 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
174 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
176 else if (!Context || !Context->new)
183 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
184 snprintf (buf, buflen, fmt, Context ? Context->unread - Context->new : 0);
186 else if (!Context || !(Context->unread - Context->new))
191 count = mutt_num_postponed (0);
194 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
195 snprintf (buf, buflen, fmt, count);
202 if (menu->top + menu->pagelen >= menu->max)
203 cp = menu->top ? "end" : "all";
206 count = (100 * (menu->top + menu->pagelen)) / menu->max;
207 snprintf (tmp, sizeof (tmp), "%d%%", count);
210 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
211 snprintf (buf, buflen, fmt, cp);
220 i = option(OPTATTACHMSG) ? 3 : ((Context->readonly ||
221 Context->dontwrite) ? 2 : (Context->changed || (
223 /* deleted doesn't necessarily mean changed in IMAP */
224 Context->magic != M_IMAP &&
226 Context->deleted)) ? 1 : 0);
231 else if (i >= mutt_strlen(StChars))
241 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
242 snprintf (buf, buflen, fmt,
243 get_sort_str (tmp, sizeof (tmp), Sort));
247 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
248 snprintf (buf, buflen, fmt,
249 get_sort_str (tmp, sizeof (tmp), SortAux));
255 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
256 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
258 else if (!Context || !Context->tagged)
265 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
266 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
268 else if (!Context || !Context->unread)
273 snprintf (fmt, sizeof (fmt), "Mutt %%s");
274 snprintf (buf, buflen, fmt, MUTT_VERSION);
280 snprintf (fmt, sizeof(fmt), "%%%ss", prefix);
281 snprintf (buf, buflen, fmt, (Context && Context->pattern) ? Context->pattern : "");
283 else if (!Context || !Context->pattern)
292 snprintf (buf, buflen, "%%%s%c", prefix, op);
297 menu_status_line (buf, buflen, menu, ifstring);
298 else if (flags & M_FORMAT_OPTIONAL)
299 menu_status_line (buf, buflen, menu, elsestring);
304 void menu_status_line (char *buf, size_t buflen, MUTTMENU *menu, const char *p)
306 mutt_FormatString (buf, buflen, p, status_format_str, (unsigned long) menu, 0);