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] */
61 static const char *status_format_str (char *buf, size_t buflen, char op,
62 const char *src, const char *prefix,
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;
75 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
76 snprintf (buf, buflen, fmt, mutt_buffy_check (0));
78 else if (!mutt_buffy_check (0))
83 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
85 if (Context && Context->compressinfo && Context->realpath) {
86 if ((p = strrchr (Context->realpath, '/')))
87 strfcpy (tmp, p + 1, sizeof (tmp));
89 strfcpy (tmp, Context->realpath, sizeof (tmp));
93 if (Context && Context->path) {
94 if ((p = strrchr (Context->path, '/')))
95 strfcpy (tmp, p + 1, sizeof (tmp));
97 strfcpy (tmp, Context->path, sizeof (tmp));
100 strfcpy (tmp, _("no mailbox"), sizeof (tmp));
101 snprintf (buf, buflen, fmt, tmp);
106 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
107 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
109 else if (!Context || !Context->deleted)
114 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
115 snprintf (buf, buflen, fmt, NONULL (Hostname));
119 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
120 #ifdef USE_COMPRESSED
121 if (Context && Context->compressinfo && Context->realpath) {
122 strfcpy (tmp, Context->realpath, sizeof (tmp));
123 mutt_pretty_mailbox (tmp);
127 if (Context && Context->path) {
128 strfcpy (tmp, Context->path, sizeof (tmp));
129 mutt_pretty_mailbox (tmp);
132 strfcpy (tmp, _("(no mailbox)"), sizeof (tmp));
133 snprintf (buf, buflen, fmt, tmp);
138 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
139 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
141 else if (!Context || !Context->flagged)
147 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
148 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
149 snprintf (buf, buflen, fmt, tmp);
151 else if (!Context || !Context->size)
157 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
158 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize : 0);
159 snprintf (buf, buflen, fmt, tmp);
161 else if (!Context || !Context->pattern)
167 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
168 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
170 else if (!Context || !Context->msgcount)
176 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
177 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
179 else if (!Context || !Context->pattern)
185 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
186 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
188 else if (!Context || Context->new <= 0)
194 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
195 snprintf (buf, buflen, fmt,
196 Context ? Context->unread - Context->new : 0);
198 else if (!Context || !(Context->unread - Context->new))
203 count = mutt_num_postponed (0);
205 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
206 snprintf (buf, buflen, fmt, count);
213 if (menu->top + menu->pagelen >= menu->max)
214 cp = menu->top ? "end" : "all";
216 count = (100 * (menu->top + menu->pagelen)) / menu->max;
217 snprintf (tmp, sizeof (tmp), "%d%%", count);
220 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
221 snprintf (buf, buflen, fmt, cp);
229 i = option (OPTATTACHMSG) ? 3 : ((Context->readonly ||
230 Context->dontwrite) ? 2 : (Context->
234 /* deleted doesn't necessarily mean changed in IMAP */
248 else if (i >= mutt_strlen (StChars))
258 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
259 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), Sort));
263 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
264 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), SortAux));
269 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
270 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
272 else if (!Context || !Context->tagged)
278 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
279 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
281 else if (!Context || !Context->unread)
286 snprintf (fmt, sizeof (fmt), "Mutt-ng %%s");
287 snprintf (buf, buflen, fmt, MUTT_VERSION);
292 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
293 snprintf (buf, buflen, fmt,
294 (Context && Context->pattern) ? Context->pattern : "");
296 else if (!Context || !Context->pattern)
305 snprintf (buf, buflen, "%%%s%c", prefix, op);
310 menu_status_line (buf, buflen, menu, ifstring);
311 else if (flags & M_FORMAT_OPTIONAL)
312 menu_status_line (buf, buflen, menu, elsestring);
317 void menu_status_line (char *buf, size_t buflen, MUTTMENU * menu,
320 mutt_FormatString (buf, buflen, p, status_format_str, (unsigned long) menu,