NeoMutt  2020-06-26-30-g76c339
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 <stdint.h>
#include <stdio.h>
#include "mutt/lib.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, intptr_t 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 58 of file status.c.

59 {
60  snprintf(buf, buflen, "%s%s%s", (method & SORT_REVERSE) ? "reverse-" : "",
61  (method & SORT_LAST) ? "last-" : "",
63  return buf;
64 }
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:107
#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,
intptr_t  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 Number of tagged messages
%u Number of unread messages
%V Currently active limit pattern
%v NeoMutt version

Definition at line 94 of file status.c.

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

411 {
412  mutt_expando_format(buf, buflen, 0, menu ? menu->win_ibar->state.cols : buflen,
413  p, status_format_str, (intptr_t) menu, MUTT_FORMAT_NO_FLAGS);
414 }
#define MUTT_FORMAT_NO_FLAGS
No flags are set.
Definition: format_flags.h:30
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string.
Definition: muttlib.c:862
struct MuttWindow * win_ibar
Definition: mutt_menu.h:93
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:57
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:113
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, intptr_t data, MuttFormatFlags flags)
Create the status bar string - Implements format_t.
Definition: status.c:94
+ 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 49 of file status.c.