NeoMutt  2018-07-16 +952-a2da0a
Teaching an old dog new tricks
DOXYGEN
status.c File Reference

GUI display a user-configurable status line. More...

#include "config.h"
#include <stdio.h>
#include "mutt/mutt.h"
#include "context.h"
#include "format_flags.h"
#include "globals.h"
#include "mailbox.h"
#include "menu.h"
#include "mutt_window.h"
#include "muttlib.h"
#include "mx.h"
#include "options.h"
#include "protos.h"
#include "sort.h"
+ Include dependency graph for status.c:

Go to the source code of this file.

Functions

static char * get_sort_str (char *buf, size_t buflen, int method)
 Get the sort method as a string. More...
 
static const char * status_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, enum FormatFlag flags)
 Create the status bar string - Implements format_t. More...
 
void menu_status_line (char *buf, size_t buflen, struct Menu *menu, const char *p)
 Create the status line. More...
 

Variables

struct MbTableStatusChars
 Config: Indicator characters for the status bar. More...
 

Detailed Description

GUI display a user-configurable status line.

Authors
  • Michael R. Elkins

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file status.c.

Function Documentation

static char* get_sort_str ( char *  buf,
size_t  buflen,
int  method 
)
static

Get the sort method as a string.

Parameters
bufBuffer for the sort string
buflenLength of the bufer
methodSort method, e.g. SORT_DATE
Return values
ptrBuffer pointer

Definition at line 54 of file status.c.

55 {
56  snprintf(buf, buflen, "%s%s%s", (method & SORT_REVERSE) ? "reverse-" : "",
57  (method & SORT_LAST) ? "last-" : "",
59  return buf;
60 }
#define SORT_LAST
Sort thread by last-X, e.g.
Definition: sort.h:79
const char * mutt_map_get_name(int val, const struct Mapping *map)
Lookup a string for a constant.
Definition: mapping.c:42
const struct Mapping SortMethods[]
Sort methods for &#39;$sort&#39; for the index.
Definition: sort.c:100
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort.h:78
#define SORT_MASK
Mask for the sort id.
Definition: sort.h:77

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static const char* status_format_str ( char *  buf,
size_t  buflen,
size_t  col,
int  cols,
char  op,
const char *  src,
const char *  prec,
const char *  if_str,
const char *  else_str,
unsigned long  data,
enum FormatFlag  flags 
)
static

Create the status bar string - Implements format_t.

Expando Description
%b Number of incoming folders with unread messages
%d Number of deleted messages
%D Description of the mailbox
%f Full mailbox path
%F Number of flagged messages
%h Hostname
%l Length of mailbox (in bytes)
%L Size (in bytes) of the messages shown
%M Number of messages shown (virtual message count when limiting)
%m Total number of messages
%n Number of new messages
%o Number of old unread messages
%p Number of postponed messages
%P Percent of way through index
%R Number of read messages
%r Readonly/wontwrite/changed flag
%S Current aux sorting method ($sort_aux)
%s Current sorting method ($sort)
%t # of tagged messages
%u Number of unread messages
%V Currently active limit pattern
%v NeoMutt version

Definition at line 90 of file status.c.

94 {
95  char fmt[SHORT_STRING], tmp[SHORT_STRING], *cp = NULL;
96  int count, optional = (flags & MUTT_FORMAT_OPTIONAL);
97  struct Menu *menu = (struct Menu *) data;
98 
99  *buf = 0;
100  switch (op)
101  {
102  case 'b':
103  if (!optional)
104  {
105  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
106  snprintf(buf, buflen, fmt, mutt_mailbox_check(0));
107  }
108  else if (mutt_mailbox_check(0) == 0)
109  optional = 0;
110  break;
111 
112  case 'd':
113  if (!optional)
114  {
115  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
116  snprintf(buf, buflen, fmt, Context ? Context->mailbox->msg_deleted : 0);
117  }
118  else if (!Context || !Context->mailbox->msg_deleted)
119  optional = 0;
120  break;
121 
122  case 'D':
123  {
124  struct Mailbox *mbox = Context ? Context->mailbox : NULL;
125  // If there's a description, use it. Otherwise, fall-through
126  if (mbox && mbox->desc)
127  {
128  mutt_str_strfcpy(tmp, mbox->desc, sizeof(tmp));
129  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
130  snprintf(buf, buflen, fmt, tmp);
131  break;
132  }
133  }
134  /* fallthrough */
135  case 'f':
136  {
137  struct Mailbox *m = Context ? Context->mailbox : NULL;
138 
139 #ifdef USE_COMPRESSED
140  if (m && m->compress_info && (m->realpath[0] != '\0'))
141  {
142  mutt_str_strfcpy(tmp, m->realpath, sizeof(tmp));
143  mutt_pretty_mailbox(tmp, sizeof(tmp));
144  }
145  else
146 #endif
147  if (m && (m->magic == MUTT_NOTMUCH) && m->desc)
148  {
149  mutt_str_strfcpy(tmp, m->desc, sizeof(tmp));
150  }
151  else if (m && (m->path[0] != '\0'))
152  {
153  mutt_str_strfcpy(tmp, m->path, sizeof(tmp));
154  mutt_pretty_mailbox(tmp, sizeof(tmp));
155  }
156  else
157  mutt_str_strfcpy(tmp, _("(no mailbox)"), sizeof(tmp));
158 
159  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
160  snprintf(buf, buflen, fmt, tmp);
161  break;
162  }
163  case 'F':
164  if (!optional)
165  {
166  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
167  snprintf(buf, buflen, fmt, Context ? Context->mailbox->msg_flagged : 0);
168  }
169  else if (!Context || !Context->mailbox->msg_flagged)
170  optional = 0;
171  break;
172 
173  case 'h':
174  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
175  snprintf(buf, buflen, fmt, NONULL(ShortHostname));
176  break;
177 
178  case 'l':
179  if (!optional)
180  {
181  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
182  mutt_str_pretty_size(tmp, sizeof(tmp), Context ? Context->mailbox->size : 0);
183  snprintf(buf, buflen, fmt, tmp);
184  }
185  else if (!Context || !Context->mailbox->size)
186  optional = 0;
187  break;
188 
189  case 'L':
190  if (!optional)
191  {
192  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
193  mutt_str_pretty_size(tmp, sizeof(tmp), Context ? Context->vsize : 0);
194  snprintf(buf, buflen, fmt, tmp);
195  }
196  else if (!Context || !Context->pattern)
197  optional = 0;
198  break;
199 
200  case 'm':
201  if (!optional)
202  {
203  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
204  snprintf(buf, buflen, fmt, Context ? Context->mailbox->msg_count : 0);
205  }
206  else if (!Context || !Context->mailbox->msg_count)
207  optional = 0;
208  break;
209 
210  case 'M':
211  if (!optional)
212  {
213  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
214  snprintf(buf, buflen, fmt, Context ? Context->mailbox->vcount : 0);
215  }
216  else if (!Context || !Context->pattern)
217  optional = 0;
218  break;
219 
220  case 'n':
221  if (!optional)
222  {
223  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
224  snprintf(buf, buflen, fmt, Context ? Context->mailbox->msg_new : 0);
225  }
226  else if (!Context || !Context->mailbox->msg_new)
227  optional = 0;
228  break;
229 
230  case 'o':
231  if (!optional)
232  {
233  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
234  snprintf(buf, buflen, fmt,
236  }
237  else if (!Context || !(Context->mailbox->msg_unread - Context->mailbox->msg_new))
238  optional = 0;
239  break;
240 
241  case 'p':
242  count = mutt_num_postponed(Context ? Context->mailbox : NULL, false);
243  if (!optional)
244  {
245  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
246  snprintf(buf, buflen, fmt, count);
247  }
248  else if (!count)
249  optional = 0;
250  break;
251 
252  case 'P':
253  if (!menu)
254  break;
255  if (menu->top + menu->pagelen >= menu->max)
256  {
257  cp = menu->top ?
258  /* L10N: Status bar message: the end of the list emails is visible in the index */
259  _("end") :
260  /* L10N: Status bar message: all the emails are visible in the index */
261  _("all");
262  }
263  else
264  {
265  count = (100 * (menu->top + menu->pagelen)) / menu->max;
266  snprintf(tmp, sizeof(tmp), "%d%%", count);
267  cp = tmp;
268  }
269  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
270  snprintf(buf, buflen, fmt, cp);
271  break;
272 
273  case 'r':
274  {
275  size_t i = 0;
276 
277  if (Context)
278  {
279  i = OptAttachMsg ?
280  3 :
282  2 :
283  (Context->mailbox->changed ||
284  /* deleted doesn't necessarily mean changed in IMAP */
286  1 :
287  0);
288  }
289 
290  if (!StatusChars || !StatusChars->len)
291  buf[0] = 0;
292  else if (i >= StatusChars->len)
293  snprintf(buf, buflen, "%s", StatusChars->chars[0]);
294  else
295  snprintf(buf, buflen, "%s", StatusChars->chars[i]);
296  break;
297  }
298 
299  case 'R':
300  {
301  int read = Context ? Context->mailbox->msg_count - Context->mailbox->msg_unread : 0;
302 
303  if (!optional)
304  {
305  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
306  snprintf(buf, buflen, fmt, read);
307  }
308  else if (!read)
309  optional = 0;
310  break;
311  }
312 
313  case 's':
314  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
315  snprintf(buf, buflen, fmt, get_sort_str(tmp, sizeof(tmp), Sort));
316  break;
317 
318  case 'S':
319  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
320  snprintf(buf, buflen, fmt, get_sort_str(tmp, sizeof(tmp), SortAux));
321  break;
322 
323  case 't':
324  if (!optional)
325  {
326  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
327  snprintf(buf, buflen, fmt, Context ? Context->mailbox->msg_tagged : 0);
328  }
329  else if (!Context || !Context->mailbox || !Context->mailbox->msg_tagged)
330  optional = 0;
331  break;
332 
333  case 'u':
334  if (!optional)
335  {
336  snprintf(fmt, sizeof(fmt), "%%%sd", prec);
337  snprintf(buf, buflen, fmt, Context ? Context->mailbox->msg_unread : 0);
338  }
339  else if (!Context || !Context->mailbox->msg_unread)
340  optional = 0;
341  break;
342 
343  case 'v':
344  snprintf(buf, buflen, "%s", mutt_make_version());
345  break;
346 
347  case 'V':
348  if (!optional)
349  {
350  snprintf(fmt, sizeof(fmt), "%%%ss", prec);
351  snprintf(buf, buflen, fmt, (Context && Context->pattern) ? Context->pattern : "");
352  }
353  else if (!Context || !Context->pattern)
354  optional = 0;
355  break;
356 
357  case 0:
358  *buf = 0;
359  return src;
360 
361  default:
362  snprintf(buf, buflen, "%%%s%c", prec, op);
363  break;
364  }
365 
366  if (optional)
367  {
368  mutt_expando_format(buf, buflen, col, cols, if_str, status_format_str,
369  (unsigned long) menu, 0);
370  }
371  else if (flags & MUTT_FORMAT_OPTIONAL)
372  {
373  mutt_expando_format(buf, buflen, col, cols, else_str, status_format_str,
374  (unsigned long) menu, 0);
375  }
376 
377  return src;
378 }
The "current" mailbox.
Definition: context.h:36
&#39;Notmuch&#39; (virtual) Mailbox type
Definition: magic.h:43
#define NONULL(x)
Definition: string2.h:39
int msg_count
total number of messages
Definition: mailbox.h:86
#define SHORT_STRING
Definition: string2.h:34
off_t size
Definition: mailbox.h:82
char ** chars
The array of multibyte character strings.
Definition: mbtable.h:39
GUI selectable list of items.
Definition: menu.h:56
int msg_deleted
number of deleted messages
Definition: mailbox.h:90
int msg_unread
number of unread messages
Definition: mailbox.h:87
void mutt_pretty_mailbox(char *s, size_t buflen)
Shorten a mailbox path using &#39;~&#39; or &#39;=&#39;.
Definition: muttlib.c:606
int msg_flagged
number of flagged messages
Definition: mailbox.h:88
char * desc
Definition: mailbox.h:81
#define _(a)
Definition: message.h:28
&#39;IMAP&#39; Mailbox type
Definition: magic.h:42
int menu
menu definition for keymap entries.
Definition: menu.h:64
int mutt_mailbox_check(int force)
Check all AllMailboxes for new mail.
Definition: mailbox.c:538
int vcount
the number of virtual messages
Definition: mailbox.h:96
static char * get_sort_str(char *buf, size_t buflen, int method)
Get the sort method as a string.
Definition: status.c:54
struct Mailbox * mailbox
Definition: context.h:50
enum MailboxType magic
mailbox type
Definition: mailbox.h:99
bool readonly
don&#39;t allow changes to the mailbox
Definition: mailbox.h:113
allow optional field processing
Definition: format_flags.h:36
static const char * status_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, enum FormatFlag flags)
Create the status bar string - Implements format_t.
Definition: status.c:90
int flags
e.g.
Definition: mailbox.h:128
off_t vsize
Definition: context.h:38
WHERE bool OptAttachMsg
(pseudo) used by attach-message
Definition: options.h:31
A mailbox.
Definition: mailbox.h:76
int top
entry that is the top of the current page
Definition: menu.h:84
bool dontwrite
don&#39;t write the mailbox on close
Definition: mailbox.h:109
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:742
int msg_tagged
how many messages are tagged?
Definition: mailbox.h:91
int pagelen
number of entries per screen
Definition: menu.h:66
unsigned char flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:37
int max
the number of entries in the menu
Definition: menu.h:62
char path[PATH_MAX]
Definition: mailbox.h:78
int mutt_num_postponed(struct Mailbox *m, bool force)
Return the number of postponed messages.
Definition: postpone.c:86
WHERE short Sort
Config: Sort method for the index.
Definition: sort.h:58
int msg_new
number of new messages
Definition: mailbox.h:89
void * compress_info
compressed mbox module private data
Definition: mailbox.h:118
WHERE char * ShortHostname
Short version of the hostname.
Definition: globals.h:48
void * data
extra data for the current menu
Definition: menu.h:60
bool changed
mailbox has been modified
Definition: mailbox.h:108
char realpath[PATH_MAX]
used for duplicate detection, context comparison, and the sidebar
Definition: mailbox.h:79
void mutt_str_pretty_size(char *buf, size_t buflen, size_t num)
Display an abbreviated size, like 3.4K.
Definition: string.c:1015
WHERE short SortAux
Config: Secondary sort method for the index.
Definition: sort.h:59
char * pattern
limit pattern string
Definition: context.h:39
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, enum FormatFlag flags)
Expand expandos (x) in a string.
Definition: muttlib.c:816
struct MbTable * StatusChars
Config: Indicator characters for the status bar.
Definition: status.c:45
int len
Number of characters.
Definition: mbtable.h:38
const char * mutt_make_version(void)
Generate the NeoMutt version string.
Definition: muttlib.c:1492

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void menu_status_line ( char *  buf,
size_t  buflen,
struct Menu menu,
const char *  p 
)

Create the status line.

Parameters
[out]bufBuffer in which to save string
[in]buflenBuffer length
[in]menuCurrent menu
[in]pFormat string

Definition at line 387 of file status.c.

388 {
389  mutt_expando_format(buf, buflen, 0,
390  menu ? menu->statuswin->cols : MuttStatusWindow->cols, p,
391  status_format_str, (unsigned long) menu, 0);
392 }
struct MuttWindow * MuttStatusWindow
Status Window.
Definition: mutt_window.c:40
static const char * status_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, enum FormatFlag flags)
Create the status bar string - Implements format_t.
Definition: status.c:90
struct MuttWindow * statuswin
Definition: menu.h:70
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, enum FormatFlag flags)
Expand expandos (x) in a string.
Definition: muttlib.c:816

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

struct MbTable* StatusChars

Config: Indicator characters for the status bar.

Definition at line 45 of file status.c.