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.
15 #include "mutt_menu.h"
16 #include "mutt_curses.h"
30 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
32 static char *get_sort_str (char *buf, size_t buflen, int method)
34 snprintf (buf, buflen, "%s%s%s",
35 (method & SORT_REVERSE) ? "reverse-" : "",
36 (method & SORT_LAST) ? "last-" : "",
37 mutt_getnamebyvalue (method & SORT_MASK, SortMethods));
41 /* %b = number of incoming folders with unread messages [option]
42 * %B = short mailbox path
43 * %d = number of deleted messages [option]
44 * %f = full mailbox path
45 * %F = number of flagged messages [option]
47 * %l = length of mailbox (in bytes) [option]
48 * %m = total number of messages [option]
49 * %M = number of messages shown (virutal message count when limiting) [option]
50 * %n = number of new messages [option]
51 * %p = number of postponed messages [option]
52 * %P = percent of way through index
53 * %r = readonly/wontwrite/changed flag
54 * %s = current sorting method ($sort)
55 * %S = current aux sorting method ($sort_aux)
56 * %t = # of tagged messages [option]
57 * %v = Mutt-ng version
58 * %V = currently active limit pattern [option] */
59 static const char *status_format_str (char *buf, size_t buflen, char op,
60 const char *src, const char *prefix,
62 const char *elsestring,
63 unsigned long data, format_flag flags)
65 char fmt[SHORT_STRING], tmp[SHORT_STRING], *cp, *p;
66 int count, optional = (flags & M_FORMAT_OPTIONAL);
67 MUTTMENU *menu = (MUTTMENU *) data;
73 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
74 snprintf (buf, buflen, fmt, buffy_check (0));
76 else if (!buffy_check (0))
81 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
83 if (Context && Context->compressinfo && Context->realpath) {
84 if ((p = strrchr (Context->realpath, '/')))
85 strfcpy (tmp, p + 1, sizeof (tmp));
87 strfcpy (tmp, Context->realpath, sizeof (tmp));
91 if (Context && Context->path) {
92 if ((p = strrchr (Context->path, '/')))
93 strfcpy (tmp, p + 1, sizeof (tmp));
95 strfcpy (tmp, Context->path, sizeof (tmp));
98 strfcpy (tmp, _("no mailbox"), sizeof (tmp));
99 snprintf (buf, buflen, fmt, tmp);
104 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
105 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
107 else if (!Context || !Context->deleted)
112 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
113 snprintf (buf, buflen, fmt, NONULL (Hostname));
117 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
118 #ifdef USE_COMPRESSED
119 if (Context && Context->compressinfo && Context->realpath) {
120 strfcpy (tmp, Context->realpath, sizeof (tmp));
121 mutt_pretty_mailbox (tmp);
125 if (Context && Context->path) {
126 strfcpy (tmp, Context->path, sizeof (tmp));
127 mutt_pretty_mailbox (tmp);
130 strfcpy (tmp, _("(no mailbox)"), sizeof (tmp));
131 snprintf (buf, buflen, fmt, tmp);
136 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
137 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
139 else if (!Context || !Context->flagged)
145 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
146 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
147 snprintf (buf, buflen, fmt, tmp);
149 else if (!Context || !Context->size)
155 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
156 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize : 0);
157 snprintf (buf, buflen, fmt, tmp);
159 else if (!Context || !Context->pattern)
165 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
166 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
168 else if (!Context || !Context->msgcount)
174 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
175 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
177 else if (!Context || !Context->pattern)
183 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
184 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
186 else if (!Context || Context->new <= 0)
192 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
193 snprintf (buf, buflen, fmt,
194 Context ? Context->unread - Context->new : 0);
196 else if (!Context || !(Context->unread - Context->new))
201 count = mutt_num_postponed (0);
203 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
204 snprintf (buf, buflen, fmt, count);
211 if (menu->top + menu->pagelen >= menu->max)
212 cp = menu->top ? "end" : "all";
214 count = (100 * (menu->top + menu->pagelen)) / menu->max;
215 snprintf (tmp, sizeof (tmp), "%d%%", count);
218 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
219 snprintf (buf, buflen, fmt, cp);
227 i = option (OPTATTACHMSG) ? 3 : ((Context->readonly ||
228 Context->dontwrite) ? 2 : (Context->
232 /* deleted doesn't necessarily mean changed in IMAP */
246 else if (i >= str_len (StChars))
256 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
257 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), Sort));
261 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
262 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), SortAux));
267 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
268 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
270 else if (!Context || !Context->tagged)
276 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
277 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
279 else if (!Context || !Context->unread)
284 strncpy (buf, mutt_make_version (0), buflen);
289 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
290 snprintf (buf, buflen, fmt,
291 (Context && Context->pattern) ? Context->pattern : "");
293 else if (!Context || !Context->pattern)
302 snprintf (buf, buflen, "%%%s%c", prefix, op);
307 menu_status_line (buf, buflen, menu, ifstring);
308 else if (flags & M_FORMAT_OPTIONAL)
309 menu_status_line (buf, buflen, menu, elsestring);
314 void menu_status_line (char* buf, size_t len, MUTTMENU* menu, const char* p) {
316 * if we have enough space for buffer, format lines to $COLS-$SidebarWidth
317 * only to not wrap past end of screen
319 int width = COLS - SW;
320 mutt_FormatString (buf, (width >= len ? len : (width + 1)),
321 p, status_format_str,
322 (unsigned long) menu, 0);