NeoMutt  2019-12-07-60-g0cfa53
Teaching an old dog new tricks
DOXYGEN
status.c File Reference

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

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include "mutt/mutt.h"
#include "config/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "status.h"
#include "context.h"
#include "format_flags.h"
#include "globals.h"
#include "mutt_mailbox.h"
#include "mutt_menu.h"
#include "muttlib.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, enum SortType 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, MuttFormatFlags 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 MbTableC_StatusChars
 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

◆ get_sort_str()

static char* get_sort_str ( char *  buf,
size_t  buflen,
enum SortType  method 
)
static

Get the sort method as a string.

Parameters
bufBuffer for the sort string
buflenLength of the buffer
methodSort method, see SortType
Return values
ptrBuffer pointer

Definition at line 57 of file status.c.

58 {
59  snprintf(buf, buflen, "%s%s%s", (method & SORT_REVERSE) ? "reverse-" : "",
60  (method & SORT_LAST) ? "last-" : "",
62  return buf;
63 }
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:97
#define SORT_REVERSE
Reverse the order of the sort.
Definition: sort2.h:86
#define SORT_LAST
Sort thread by last-X, e.g. received date.
Definition: sort2.h:87
#define SORT_MASK
Mask for the sort id.
Definition: sort2.h:85
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ status_format_str()

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,
MuttFormatFlags  flags 
)
static

Create the status bar string - Implements format_t.

Expando Description
%b Number of incoming folders with unread messages
%D Description of the mailbox
%d Number of deleted messages
%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 (or limited)
%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 93 of file status.c.

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

◆ menu_status_line()

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 409 of file status.c.

410 {
411  mutt_expando_format(buf, buflen, 0, menu ? menu->win_ibar->state.cols : buflen, p,
412  status_format_str, (unsigned long) menu, MUTT_FORMAT_NO_FLAGS);
413 }
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:877
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, MuttFormatFlags flags)
Create the status bar string - Implements format_t.
Definition: status.c:93
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
struct MuttWindow * win_ibar
Definition: mutt_menu.h:96
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:56
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ C_StatusChars

struct MbTable* C_StatusChars

Config: Indicator characters for the status bar.

Definition at line 48 of file status.c.