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-ui/lib-ui.h>
12 #include <lib-ui/menu.h>
13 #include <lib-mx/mx.h>
19 static char *get_sort_str (char *buf, ssize_t buflen, int method)
21 snprintf (buf, buflen, "%s%s%s",
22 (method & SORT_REVERSE) ? "reverse-" : "",
23 (method & SORT_LAST) ? "last-" : "",
24 mutt_getnamebyvalue (method & SORT_MASK, SortMethods));
28 /* %b = number of incoming folders with unread messages [option]
29 * %B = short mailbox path
30 * %d = number of deleted messages [option]
31 * %f = full mailbox path
32 * %F = number of flagged messages [option]
34 * %l = length of mailbox (in bytes) [option]
35 * %m = total number of messages [option]
36 * %M = number of messages shown (virutal message count when limiting) [option]
37 * %n = number of new messages [option]
38 * %p = number of postponed messages [option]
39 * %P = percent of way through index
40 * %r = readonly/wontwrite/changed flag
41 * %s = current sorting method ($sort)
42 * %S = current aux sorting method ($sort_aux)
43 * %t = # of tagged messages [option]
44 * %v = Madmutt version
45 * %V = currently active limit pattern [option] */
47 status_format_str(char *buf, ssize_t buflen, char op, const char *src,
48 const char *prefix, const char *ifstr, const char *elstr,
49 anytype data, format_flag flags)
51 char fmt[STRING], tmp[STRING];
53 int count, optional = (flags & M_FORMAT_OPTIONAL);
54 MUTTMENU *menu = data.ptr;
60 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
61 snprintf (buf, buflen, fmt, buffy_check (0));
63 else if (!buffy_check (0))
68 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
69 if (Context && Context->cinfo && Context->realpath) {
70 if ((p = strrchr (Context->realpath, '/')))
71 m_strcpy(tmp, sizeof(tmp), p + 1);
73 m_strcpy(tmp, sizeof(tmp), Context->realpath);
76 if (Context && Context->path) {
77 if ((p = strrchr (Context->path, '/')))
78 m_strcpy(tmp, sizeof(tmp), p + 1);
80 m_strcpy(tmp, sizeof(tmp), Context->path);
83 m_strcpy(tmp, sizeof(tmp), _("no mailbox"));
84 snprintf (buf, buflen, fmt, tmp);
89 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
90 snprintf (buf, buflen, fmt, Context ? Context->deleted : 0);
92 else if (!Context || !Context->deleted)
97 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
98 snprintf (buf, buflen, fmt, NONULL (mod_core.shorthost));
102 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
103 if (Context && Context->cinfo && Context->realpath) {
104 m_strcpy(tmp, sizeof(tmp), Context->realpath);
105 mutt_pretty_mailbox (tmp);
107 if (Context && Context->path) {
108 m_strcpy(tmp, sizeof(tmp), Context->path);
109 mutt_pretty_mailbox (tmp);
111 m_strcpy(tmp, sizeof(tmp), _("(no mailbox)"));
113 snprintf (buf, buflen, fmt, tmp);
118 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
119 snprintf (buf, buflen, fmt, Context ? Context->flagged : 0);
121 else if (!Context || !Context->flagged)
127 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
128 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->size : 0);
129 snprintf (buf, buflen, fmt, tmp);
131 else if (!Context || !Context->size)
137 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
138 mutt_pretty_size (tmp, sizeof (tmp), Context ? Context->vsize : 0);
139 snprintf (buf, buflen, fmt, tmp);
141 else if (!Context || !Context->pattern)
147 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
148 snprintf (buf, buflen, fmt, Context ? Context->msgcount : 0);
150 else if (!Context || !Context->msgcount)
156 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
157 snprintf (buf, buflen, fmt, Context ? Context->vcount : 0);
159 else if (!Context || !Context->pattern)
165 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
166 snprintf (buf, buflen, fmt, Context ? Context->new : 0);
168 else if (!Context || Context->new <= 0)
174 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
175 snprintf (buf, buflen, fmt,
176 Context ? Context->unread - Context->new : 0);
178 else if (!Context || !(Context->unread - Context->new))
183 count = mutt_num_postponed (0);
185 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
186 snprintf (buf, buflen, fmt, count);
193 if (menu->top + menu->pagelen >= menu->max)
194 cp = menu->top ? "end" : "all";
196 count = (100 * (menu->top + menu->pagelen)) / menu->max;
197 snprintf (tmp, sizeof (tmp), "%d%%", count);
200 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
201 snprintf (buf, buflen, fmt, cp);
209 /* XXX: deleted doesn't necessarily mean changed in IMAP */
210 i = option (OPTATTACHMSG) ? 3
211 : ((Context->readonly || Context->dontwrite) ? 2
212 : (Context->changed || (Context-> magic != M_IMAP && Context->
218 else if (i >= m_strlen(StChars))
228 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
229 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), Sort));
233 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
234 snprintf (buf, buflen, fmt, get_sort_str (tmp, sizeof (tmp), SortAux));
239 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
240 snprintf (buf, buflen, fmt, Context ? Context->tagged : 0);
242 else if (!Context || !Context->tagged)
248 snprintf (fmt, sizeof (fmt), "%%%sd", prefix);
249 snprintf (buf, buflen, fmt, Context ? Context->unread : 0);
251 else if (!Context || !Context->unread)
256 m_strcpy(buf, buflen, madmutt_version);
261 snprintf (fmt, sizeof (fmt), "%%%ss", prefix);
262 snprintf (buf, buflen, fmt,
263 (Context && Context->pattern) ? Context->pattern : "");
265 else if (!Context || !Context->pattern)
278 if (flags & M_FORMAT_OPTIONAL)
279 menu_status_line(buf, buflen, menu, optional ? ifstr : elstr);
284 void menu_status_line(char* buf, ssize_t len, MUTTMENU* menu, const char* p)
286 m_strformat(buf, len, getmaxx(main_w), p, status_format_str, menu, 0);