NeoMutt  2021-02-05
Teaching an old dog new tricks
DOXYGEN
menu.c File Reference

GUI present the user with a selectable list. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "pattern/lib.h"
#include "commands.h"
#include "context.h"
#include "keymap.h"
#include "mutt_globals.h"
#include "mutt_logging.h"
#include "mutt_mailbox.h"
#include "mutt_menu.h"
#include "mutt_thread.h"
#include "muttlib.h"
#include "opcodes.h"
#include "options.h"
#include "protos.h"
+ Include dependency graph for menu.c:

Go to the source code of this file.

Macros

#define DIRECTION   ((neg * 2) + 1)
 
#define MUTT_SEARCH_UP   1
 
#define MUTT_SEARCH_DOWN   2
 

Functions

 ARRAY_HEAD (struct Menu *)
 
static void print_enriched_string (int index, int attr, unsigned char *s, bool do_color)
 Display a string with embedded colours and graphics. More...
 
static void make_entry (char *buf, size_t buflen, struct Menu *menu, int i)
 Create string to display in a Menu (the index) More...
 
static void menu_pad_string (struct Menu *menu, char *buf, size_t buflen)
 Pad a string with spaces for display in the Menu. More...
 
void menu_redraw_full (struct Menu *menu)
 Force the redraw of the Menu. More...
 
void menu_redraw_status (struct Menu *menu)
 Force the redraw of the status bar. More...
 
void menu_redraw_index (struct Menu *menu)
 Force the redraw of the index. More...
 
void menu_redraw_motion (struct Menu *menu)
 Force the redraw of the list part of the menu. More...
 
void menu_redraw_current (struct Menu *menu)
 Redraw the current menu. More...
 
static void menu_redraw_prompt (struct Menu *menu)
 Force the redraw of the message window. More...
 
void menu_check_recenter (struct Menu *menu)
 Recentre the menu on screen. More...
 
static void menu_jump (struct Menu *menu)
 Jump to another item in the menu. More...
 
void menu_next_line (struct Menu *menu)
 Move the view down one line, keeping the selection the same. More...
 
void menu_prev_line (struct Menu *menu)
 Move the view up one line, keeping the selection the same. More...
 
static void menu_length_jump (struct Menu *menu, int jumplen)
 Calculate the destination of a jump. More...
 
void menu_next_page (struct Menu *menu)
 Move the focus to the next page in the menu. More...
 
void menu_prev_page (struct Menu *menu)
 Move the focus to the previous page in the menu. More...
 
void menu_half_down (struct Menu *menu)
 Move the focus down half a page in the menu. More...
 
void menu_half_up (struct Menu *menu)
 Move the focus up half a page in the menu. More...
 
void menu_top_page (struct Menu *menu)
 Move the focus to the top of the page. More...
 
void menu_bottom_page (struct Menu *menu)
 Move the focus to the bottom of the page. More...
 
void menu_middle_page (struct Menu *menu)
 Move the focus to the centre of the page. More...
 
void menu_first_entry (struct Menu *menu)
 Move the focus to the first entry in the menu. More...
 
void menu_last_entry (struct Menu *menu)
 Move the focus to the last entry in the menu. More...
 
void menu_current_top (struct Menu *menu)
 Move the current selection to the top of the window. More...
 
void menu_current_middle (struct Menu *menu)
 Move the current selection to the centre of the window. More...
 
void menu_current_bottom (struct Menu *menu)
 Move the current selection to the bottom of the window. More...
 
static void menu_next_entry (struct Menu *menu)
 Move the focus to the next item in the menu. More...
 
static void menu_prev_entry (struct Menu *menu)
 Move the focus to the previous item in the menu. More...
 
static int default_color (int line)
 Get the default colour for a line of the menu - Implements Menu::color() More...
 
static int generic_search (struct Menu *menu, regex_t *rx, int line)
 Search a menu for a item matching a regex - Implements Menu::search() More...
 
void mutt_menu_init (void)
 Initialise all the Menus. More...
 
struct Menumutt_menu_new (enum MenuType type)
 Create a new Menu. More...
 
void mutt_menu_free (struct Menu **ptr)
 Destroy a menu. More...
 
void mutt_menu_add_dialog_row (struct Menu *menu, const char *row)
 Add a row to a Menu. More...
 
static struct Menuget_current_menu (void)
 Get the current Menu. More...
 
void mutt_menu_push_current (struct Menu *menu)
 Add a new Menu to the stack. More...
 
void mutt_menu_pop_current (struct Menu *menu)
 Remove a Menu from the stack. More...
 
void mutt_menu_set_current_redraw (MuttRedrawFlags redraw)
 Set redraw flags on the current menu. More...
 
void mutt_menu_set_current_redraw_full (void)
 Flag the current menu to be fully redrawn. More...
 
void mutt_menu_set_redraw (enum MenuType menu, MuttRedrawFlags redraw)
 Set redraw flags on a menu. More...
 
void mutt_menu_set_redraw_full (enum MenuType menu)
 Flag a menu to be fully redrawn. More...
 
void mutt_menu_current_redraw (void)
 Redraw the current menu. More...
 
static int search (struct Menu *menu, int op)
 Search a menu. More...
 
static int menu_dialog_translate_op (int i)
 Convert menubar movement to scrolling. More...
 
static int menu_dialog_dokey (struct Menu *menu, int *ip)
 Check if there are any menu key events to process. More...
 
int menu_redraw (struct Menu *menu)
 Redraw the parts of the screen that have been flagged to be redrawn. More...
 
int mutt_menu_loop (struct Menu *menu)
 Menu event loop. More...
 
int mutt_menu_color_observer (struct NotifyCallback *nc)
 Listen for colour changes affecting the menu - Implements observer_t. More...
 
int mutt_menu_config_observer (struct NotifyCallback *nc)
 Listen for config changes affecting the menu - Implements observer_t. More...
 

Variables

short C_MenuContext
 Config: Number of lines of overlap when changing pages in the index. More...
 
bool C_MenuMoveOff
 Config: Allow the last menu item to move off the bottom of the screen. More...
 
bool C_MenuScroll
 Config: Scroll the menu/index by one line, rather than a page. More...
 
char * SearchBuffers [MENU_MAX]
 

Detailed Description

GUI present the user with a selectable list.

Authors
  • Michael R. Elkins
  • R Primus

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 menu.c.

Macro Definition Documentation

◆ DIRECTION

#define DIRECTION   ((neg * 2) + 1)

◆ MUTT_SEARCH_UP

#define MUTT_SEARCH_UP   1

◆ MUTT_SEARCH_DOWN

#define MUTT_SEARCH_DOWN   2

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( struct Menu )

Definition at line 63 of file menu.c.

80 {
81  struct ColorLineList *color = NULL;
82  struct ColorLine *np = NULL;
84  int type = *s;
85 
86  switch (type)
87  {
89  color = &Colors->index_author_list;
90  break;
92  color = &Colors->index_flags_list;
93  break;
95  color = &Colors->index_subject_list;
96  break;
97  case MT_COLOR_INDEX_TAG:
98  STAILQ_FOREACH(np, &Colors->index_tag_list, entries)
99  {
100  if (mutt_strn_equal((const char *) (s + 1), np->pattern, strlen(np->pattern)))
101  return np->pair;
102  const char *transform = mutt_hash_find(TagTransforms, np->pattern);
103  if (transform && mutt_strn_equal((const char *) (s + 1), transform, strlen(transform)))
104  {
105  return np->pair;
106  }
107  }
108  return 0;
109  default:
110  return Colors->defs[type];
111  }
112 
113  STAILQ_FOREACH(np, color, entries)
114  {
117  return np->pair;
118  }
119 
120  return 0;
121 }
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:354
struct ColorLineList index_tag_list
List of colours applied to tags in the index.
Definition: color.h:140
The "current" mailbox.
Definition: context.h:38
The envelope/body of an email.
Definition: email.h:37
struct Email * mutt_get_virt_email(struct Mailbox *m, int vnum)
Get a virtual Email.
Definition: context.c:396
int * defs
Array of all fixed colours, see enum ColorId.
Definition: color.h:131
struct PatternList * color_pattern
Compiled pattern to speed up index color calculation.
Definition: color.h:40
struct ColorLineList index_flags_list
List of colours applied to the flags in the index.
Definition: color.h:137
char * pattern
Pattern to match.
Definition: color.h:39
int pair
Colour pair index.
Definition: color.h:43
struct ColorLineList index_subject_list
List of colours applied to the subject in the index.
Definition: color.h:139
Index: author field (takes a pattern)
Definition: color.h:101
struct Mailbox * mailbox
Definition: context.h:50
Index: tag field (g, takes a pattern)
Definition: color.h:104
#define SLIST_FIRST(head)
Definition: queue.h:228
struct ColorLineList index_author_list
List of colours applied to the author in the index.
Definition: color.h:136
struct HashTable * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:38
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
Definition: color.h:129
bool mutt_strn_equal(const char *a, const char *b, size_t l)
Check for equality of two strings (to a maximum), safely.
Definition: string.c:593
int mutt_pattern_exec(struct Pattern *pat, PatternExecFlags flags, struct Mailbox *m, struct Email *e, struct PatternCache *cache)
Match a pattern against an email header.
Definition: exec.c:738
Index: subject field (takes a pattern)
Definition: color.h:103
int index
The absolute (unsorted) message number.
Definition: email.h:86
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition: lib.h:98
Index: flags field (takes a pattern)
Definition: color.h:102
A regular expression and a color to highlight a line.
Definition: color.h:35
+ Here is the call graph for this function:

◆ print_enriched_string()

static void print_enriched_string ( int  index,
int  attr,
unsigned char *  s,
bool  do_color 
)
static

Display a string with embedded colours and graphics.

Parameters
indexIndex number
attrDefault colour for the line
sString of embedded colour codes
do_colorIf true, apply colour

Definition at line 130 of file menu.c.

131 {
132  wchar_t wc;
133  size_t k;
134  size_t n = mutt_str_len((char *) s);
135  mbstate_t mbstate;
136 
137  memset(&mbstate, 0, sizeof(mbstate));
138  while (*s)
139  {
140  if (*s < MUTT_TREE_MAX)
141  {
142  if (do_color)
143 #if defined(HAVE_COLOR) && defined(HAVE_USE_DEFAULT_COLORS)
144  /* Combining tree fg color and another bg color requires having
145  * use_default_colors, because the other bg color may be undefined. */
147 #else
149 #endif
150 
151  while (*s && (*s < MUTT_TREE_MAX))
152  {
153  switch (*s)
154  {
155  case MUTT_TREE_LLCORNER:
156  if (C_AsciiChars)
157  mutt_window_addch('`');
158 #ifdef WACS_LLCORNER
159  else
160  add_wch(WACS_LLCORNER);
161 #else
162  else if (CharsetIsUtf8)
163  mutt_window_addstr("\342\224\224"); /* WACS_LLCORNER */
164  else
165  mutt_window_addch(ACS_LLCORNER);
166 #endif
167  break;
168  case MUTT_TREE_ULCORNER:
169  if (C_AsciiChars)
170  mutt_window_addch(',');
171 #ifdef WACS_ULCORNER
172  else
173  add_wch(WACS_ULCORNER);
174 #else
175  else if (CharsetIsUtf8)
176  mutt_window_addstr("\342\224\214"); /* WACS_ULCORNER */
177  else
178  mutt_window_addch(ACS_ULCORNER);
179 #endif
180  break;
181  case MUTT_TREE_LTEE:
182  if (C_AsciiChars)
183  mutt_window_addch('|');
184 #ifdef WACS_LTEE
185  else
186  add_wch(WACS_LTEE);
187 #else
188  else if (CharsetIsUtf8)
189  mutt_window_addstr("\342\224\234"); /* WACS_LTEE */
190  else
191  mutt_window_addch(ACS_LTEE);
192 #endif
193  break;
194  case MUTT_TREE_HLINE:
195  if (C_AsciiChars)
196  mutt_window_addch('-');
197 #ifdef WACS_HLINE
198  else
199  add_wch(WACS_HLINE);
200 #else
201  else if (CharsetIsUtf8)
202  mutt_window_addstr("\342\224\200"); /* WACS_HLINE */
203  else
204  mutt_window_addch(ACS_HLINE);
205 #endif
206  break;
207  case MUTT_TREE_VLINE:
208  if (C_AsciiChars)
209  mutt_window_addch('|');
210 #ifdef WACS_VLINE
211  else
212  add_wch(WACS_VLINE);
213 #else
214  else if (CharsetIsUtf8)
215  mutt_window_addstr("\342\224\202"); /* WACS_VLINE */
216  else
217  mutt_window_addch(ACS_VLINE);
218 #endif
219  break;
220  case MUTT_TREE_TTEE:
221  if (C_AsciiChars)
222  mutt_window_addch('-');
223 #ifdef WACS_TTEE
224  else
225  add_wch(WACS_TTEE);
226 #else
227  else if (CharsetIsUtf8)
228  mutt_window_addstr("\342\224\254"); /* WACS_TTEE */
229  else
230  mutt_window_addch(ACS_TTEE);
231 #endif
232  break;
233  case MUTT_TREE_BTEE:
234  if (C_AsciiChars)
235  mutt_window_addch('-');
236 #ifdef WACS_BTEE
237  else
238  add_wch(WACS_BTEE);
239 #else
240  else if (CharsetIsUtf8)
241  mutt_window_addstr("\342\224\264"); /* WACS_BTEE */
242  else
243  mutt_window_addch(ACS_BTEE);
244 #endif
245  break;
246  case MUTT_TREE_SPACE:
247  mutt_window_addch(' ');
248  break;
249  case MUTT_TREE_RARROW:
250  mutt_window_addch('>');
251  break;
252  case MUTT_TREE_STAR:
253  mutt_window_addch('*'); /* fake thread indicator */
254  break;
255  case MUTT_TREE_HIDDEN:
256  mutt_window_addch('&');
257  break;
258  case MUTT_TREE_EQUALS:
259  mutt_window_addch('=');
260  break;
261  case MUTT_TREE_MISSING:
262  mutt_window_addch('?');
263  break;
264  }
265  s++;
266  n--;
267  }
268  if (do_color)
269  mutt_curses_set_attr(attr);
270  }
271  else if (*s == MUTT_SPECIAL_INDEX)
272  {
273  s++;
274  if (do_color)
275  {
276  if (*s == MT_COLOR_INDEX)
277  {
278  attrset(attr);
279  }
280  else
281  {
282  if (get_color(index, s) == 0)
283  {
284  attron(attr);
285  }
286  else
287  {
288  attron(get_color(index, s));
289  }
290  }
291  }
292  s++;
293  n -= 2;
294  }
295  else if ((k = mbrtowc(&wc, (char *) s, n, &mbstate)) > 0)
296  {
297  mutt_window_addnstr((char *) s, k);
298  s += k;
299  n -= k;
300  }
301  else
302  break;
303  }
304 }
Star character (for threads)
Definition: mutt_thread.h:63
Ampersand character (for threads)
Definition: mutt_thread.h:64
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:57
int * defs
Array of all fixed colours, see enum ColorId.
Definition: color.h:131
Lower left corner.
Definition: mutt_thread.h:56
int mutt_window_addnstr(const char *str, int num)
Write a partial string to a Window.
Definition: mutt_window.c:504
Top T-piece.
Definition: mutt_thread.h:66
Index: tree-drawing characters.
Definition: color.h:96
Vertical line.
Definition: mutt_thread.h:60
Right arrow.
Definition: mutt_thread.h:62
Bottom T-piece.
Definition: mutt_thread.h:67
Left T-piece.
Definition: mutt_thread.h:58
Upper left corner.
Definition: mutt_thread.h:57
Definition: color.h:129
bool CharsetIsUtf8
Is the user&#39;s current character set utf-8?
Definition: charset.c:63
WHERE bool C_AsciiChars
Config: Use plain ASCII characters, when drawing email threads.
Definition: mutt_globals.h:133
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
int mutt_window_addch(int ch)
Write one character to a Window.
Definition: mutt_window.c:492
Horizontal line.
Definition: mutt_thread.h:59
int index
The absolute (unsorted) message number.
Definition: email.h:86
Colour indicator.
Definition: mutt_thread.h:71
int mutt_window_addstr(const char *str)
Write a string to a Window.
Definition: mutt_window.c:522
int mutt_color_combine(struct Colors *c, uint32_t fg_attr, uint32_t bg_attr)
Combine two colours.
Definition: color.c:577
Index: default colour (takes a pattern)
Definition: color.h:100
Blank space.
Definition: mutt_thread.h:61
void mutt_curses_set_attr(int attr)
Set the attributes for text.
Definition: mutt_curses.c:40
Question mark.
Definition: mutt_thread.h:68
Equals (for threads)
Definition: mutt_thread.h:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ make_entry()

static void make_entry ( char *  buf,
size_t  buflen,
struct Menu menu,
int  i 
)
static

Create string to display in a Menu (the index)

Parameters
bufBuffer for the result
buflenLength of the buffer
menuCurrent Menu
iSelected item

Definition at line 313 of file menu.c.

314 {
315  if (!ARRAY_EMPTY(&menu->dialog))
316  {
317  mutt_str_copy(buf, NONULL(*ARRAY_GET(&menu->dialog, i)), buflen);
318  menu->current = -1; /* hide menubar */
319  }
320  else
321  menu->make_entry(buf, buflen, menu, i);
322 }
#define NONULL(x)
Definition: string2.h:37
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
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:716
int current
Current entry.
Definition: mutt_menu.h:56
void(* make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: mutt_menu.h:88
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_pad_string()

static void menu_pad_string ( struct Menu menu,
char *  buf,
size_t  buflen 
)
static

Pad a string with spaces for display in the Menu.

Parameters
menuCurrent Menu
bufBuffer containing the string
buflenLength of the buffer
Note
The string is padded in-place.

Definition at line 332 of file menu.c.

333 {
334  char *scratch = mutt_str_dup(buf);
335  int shift = C_ArrowCursor ? mutt_strwidth(C_ArrowString) + 1 : 0;
336  int cols = menu->win_index->state.cols - shift;
337 
338  mutt_simple_format(buf, buflen, cols, cols, JUSTIFY_LEFT, ' ', scratch,
339  mutt_str_len(scratch), true);
340  buf[buflen - 1] = '\0';
341  FREE(&scratch);
342 }
Left justify the text.
Definition: curs_lib.h:47
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
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:120
int mutt_strwidth(const char *s)
Measure a string&#39;s width in screen cells.
Definition: curs_lib.c:1359
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: mutt_globals.h:131
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:631
#define FREE(x)
Definition: memory.h:40
struct MuttWindow * win_index
Definition: mutt_menu.h:63
WHERE char * C_ArrowString
Config: Use an custom string for arrow_cursor.
Definition: mutt_globals.h:132
void mutt_simple_format(char *buf, size_t buflen, int min_width, int max_width, enum FormatJustify justify, char pad_char, const char *s, size_t n, bool arboreal)
Format a string, like snprintf()
Definition: curs_lib.c:1093
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_full()

void menu_redraw_full ( struct Menu menu)

Force the redraw of the Menu.

Parameters
menuCurrent Menu

Definition at line 348 of file menu.c.

349 {
352 
353  window_redraw(RootWindow, true);
354  menu->pagelen = menu->win_index->state.rows;
355 
356  mutt_show_error();
357 
359 }
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:57
void mutt_window_clear(struct MuttWindow *win)
Clear a Window.
Definition: mutt_window.c:806
Plain text.
Definition: color.h:77
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:44
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:45
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:58
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:40
void window_redraw(struct MuttWindow *win, bool force)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:747
void mutt_show_error(void)
Show the user an error message.
Definition: curs_lib.c:557
struct MuttWindow * win_index
Definition: mutt_menu.h:63
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_status()

void menu_redraw_status ( struct Menu menu)

Force the redraw of the status bar.

Parameters
menuCurrent Menu

Definition at line 365 of file menu.c.

366 {
367  char buf[256];
368 
369  snprintf(buf, sizeof(buf), "-- NeoMutt: %s", menu->title);
371  mutt_window_move(menu->win_ibar, 0, 0);
372  mutt_paddstr(menu->win_ibar->state.cols, buf);
374  menu->redraw &= ~REDRAW_STATUS;
375 }
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:57
void mutt_paddstr(int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:1266
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:382
struct MuttWindow * win_ibar
Definition: mutt_menu.h:64
const char * title
Title of this menu.
Definition: mutt_menu.h:54
Plain text.
Definition: color.h:77
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:120
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:44
Status bar (takes a pattern)
Definition: color.h:94
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_index()

void menu_redraw_index ( struct Menu menu)

Force the redraw of the index.

Parameters
menuCurrent Menu

Definition at line 381 of file menu.c.

382 {
383  char buf[1024];
384  bool do_color;
385  int attr;
386 
387  for (int i = menu->top; i < (menu->top + menu->pagelen); i++)
388  {
389  if (i < menu->max)
390  {
391  attr = menu->color(i);
392 
393  make_entry(buf, sizeof(buf), menu, i);
394  menu_pad_string(menu, buf, sizeof(buf));
395 
396  mutt_curses_set_attr(attr);
397  mutt_window_move(menu->win_index, 0, i - menu->top);
398  do_color = true;
399 
400  if (i == menu->current)
401  {
403  if (C_ArrowCursor)
404  {
406  mutt_curses_set_attr(attr);
407  mutt_window_addch(' ');
408  }
409  else
410  do_color = false;
411  }
412  else if (C_ArrowCursor)
413  {
414  /* Print space chars to match the screen width of `$arrow_string` */
416  }
417 
418  print_enriched_string(i, attr, (unsigned char *) buf, do_color);
419  }
420  else
421  {
423  mutt_window_clearline(menu->win_index, i - menu->top);
424  }
425  }
427  menu->redraw = 0;
428 }
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:57
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:382
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:232
Plain text.
Definition: color.h:77
int(* color)(int line)
Calculate the colour for a line of the menu.
Definition: mutt_menu.h:115
int mutt_strwidth(const char *s)
Measure a string&#39;s width in screen cells.
Definition: curs_lib.c:1359
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
Selected item in list.
Definition: color.h:73
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: mutt_globals.h:131
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
int mutt_window_printf(const char *fmt,...)
Write a formatted string to a Window.
Definition: mutt_window.c:550
int mutt_window_addch(int ch)
Write one character to a Window.
Definition: mutt_window.c:492
int mutt_window_addstr(const char *str)
Write a string to a Window.
Definition: mutt_window.c:522
int current
Current entry.
Definition: mutt_menu.h:56
struct MuttWindow * win_index
Definition: mutt_menu.h:63
void mutt_curses_set_attr(int attr)
Set the attributes for text.
Definition: mutt_curses.c:40
WHERE char * C_ArrowString
Config: Use an custom string for arrow_cursor.
Definition: mutt_globals.h:132
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_motion()

void menu_redraw_motion ( struct Menu menu)

Force the redraw of the list part of the menu.

Parameters
menuCurrent Menu

Definition at line 434 of file menu.c.

435 {
436  char buf[1024];
437 
438  if (!ARRAY_EMPTY(&menu->dialog))
439  {
440  menu->redraw &= ~REDRAW_MOTION;
441  return;
442  }
443 
444  /* Note: menu->color() for the index can end up retrieving a message
445  * over imap (if matching against ~h for instance). This can
446  * generate status messages. So we want to call it *before* we
447  * position the cursor for drawing. */
448  const int old_color = menu->color(menu->oldcurrent);
449  mutt_window_move(menu->win_index, 0, menu->oldcurrent - menu->top);
450  mutt_curses_set_attr(old_color);
451 
452  if (C_ArrowCursor)
453  {
454  /* clear the arrow */
455  /* Print space chars to match the screen width of `$arrow_string` */
457 
458  if (menu->redraw & REDRAW_MOTION_RESYNC)
459  {
460  make_entry(buf, sizeof(buf), menu, menu->oldcurrent);
461  menu_pad_string(menu, buf, sizeof(buf));
463  menu->oldcurrent - menu->top);
464  print_enriched_string(menu->oldcurrent, old_color, (unsigned char *) buf, true);
465  }
466 
467  /* now draw it in the new location */
469  mutt_window_mvaddstr(menu->win_index, 0, menu->current - menu->top, C_ArrowString);
470  }
471  else
472  {
473  /* erase the current indicator */
474  make_entry(buf, sizeof(buf), menu, menu->oldcurrent);
475  menu_pad_string(menu, buf, sizeof(buf));
476  print_enriched_string(menu->oldcurrent, old_color, (unsigned char *) buf, true);
477 
478  /* now draw the new one to reflect the change */
479  const int cur_color = menu->color(menu->current);
480  make_entry(buf, sizeof(buf), menu, menu->current);
481  menu_pad_string(menu, buf, sizeof(buf));
483  mutt_window_move(menu->win_index, 0, menu->current - menu->top);
484  print_enriched_string(menu->current, cur_color, (unsigned char *) buf, false);
485  }
486  menu->redraw &= REDRAW_STATUS;
488 }
int oldcurrent
For driver use only.
Definition: mutt_menu.h:76
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:57
int mutt_window_mvaddstr(struct MuttWindow *win, int col, int row, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:396
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:382
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:41
Plain text.
Definition: color.h:77
#define REDRAW_MOTION_RESYNC
Redraw any changing the menu selection.
Definition: mutt_menu.h:42
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:44
int(* color)(int line)
Calculate the colour for a line of the menu.
Definition: mutt_menu.h:115
int mutt_strwidth(const char *s)
Measure a string&#39;s width in screen cells.
Definition: curs_lib.c:1359
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
Selected item in list.
Definition: color.h:73
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: mutt_globals.h:131
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
int mutt_window_printf(const char *fmt,...)
Write a formatted string to a Window.
Definition: mutt_window.c:550
int current
Current entry.
Definition: mutt_menu.h:56
struct MuttWindow * win_index
Definition: mutt_menu.h:63
void mutt_curses_set_attr(int attr)
Set the attributes for text.
Definition: mutt_curses.c:40
WHERE char * C_ArrowString
Config: Use an custom string for arrow_cursor.
Definition: mutt_globals.h:132
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_current()

void menu_redraw_current ( struct Menu menu)

Redraw the current menu.

Parameters
menuCurrent Menu

Definition at line 494 of file menu.c.

495 {
496  char buf[1024];
497  int attr = menu->color(menu->current);
498 
499  mutt_window_move(menu->win_index, 0, menu->current - menu->top);
500  make_entry(buf, sizeof(buf), menu, menu->current);
501  menu_pad_string(menu, buf, sizeof(buf));
502 
504  if (C_ArrowCursor)
505  {
507  mutt_curses_set_attr(attr);
508  mutt_window_addch(' ');
509  menu_pad_string(menu, buf, sizeof(buf));
510  print_enriched_string(menu->current, attr, (unsigned char *) buf, true);
511  }
512  else
513  print_enriched_string(menu->current, attr, (unsigned char *) buf, false);
514  menu->redraw &= REDRAW_STATUS;
516 }
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:57
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:382
Plain text.
Definition: color.h:77
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:44
int(* color)(int line)
Calculate the colour for a line of the menu.
Definition: mutt_menu.h:115
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
Selected item in list.
Definition: color.h:73
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: mutt_globals.h:131
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
int mutt_window_addch(int ch)
Write one character to a Window.
Definition: mutt_window.c:492
int mutt_window_addstr(const char *str)
Write a string to a Window.
Definition: mutt_window.c:522
int current
Current entry.
Definition: mutt_menu.h:56
struct MuttWindow * win_index
Definition: mutt_menu.h:63
void mutt_curses_set_attr(int attr)
Set the attributes for text.
Definition: mutt_curses.c:40
WHERE char * C_ArrowString
Config: Use an custom string for arrow_cursor.
Definition: mutt_globals.h:132
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_prompt()

static void menu_redraw_prompt ( struct Menu menu)
static

Force the redraw of the message window.

Parameters
menuCurrent Menu

Definition at line 522 of file menu.c.

523 {
524  if (!menu || ARRAY_EMPTY(&menu->dialog))
525  return;
526 
527  if (OptMsgErr)
528  {
529  mutt_sleep(1);
530  OptMsgErr = false;
531  }
532 
533  if (ErrorBufMessage)
535 
538 }
char * prompt
Prompt for user, similar to mutt_multi_choice.
Definition: mutt_menu.h:71
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:244
int mutt_window_mvaddstr(struct MuttWindow *win, int col, int row, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:396
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1447
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
struct MuttWindow * MessageWindow
Message Window, ":set", etc.
Definition: mutt_window.c:47
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
WHERE bool OptMsgErr
(pseudo) used by mutt_error/mutt_message
Definition: options.h:41
WHERE bool ErrorBufMessage
true if the last message was an error
Definition: mutt_globals.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_check_recenter()

void menu_check_recenter ( struct Menu menu)

Recentre the menu on screen.

Parameters
menuCurrent Menu

Definition at line 544 of file menu.c.

545 {
546  int c = MIN(C_MenuContext, (menu->pagelen / 2));
547  int old_top = menu->top;
548 
549  if (!C_MenuMoveOff && (menu->max <= menu->pagelen)) /* less entries than lines */
550  {
551  if (menu->top != 0)
552  {
553  menu->top = 0;
554  menu->redraw |= REDRAW_INDEX;
555  }
556  }
557  else
558  {
559  if (C_MenuScroll || (menu->pagelen <= 0) || (c < C_MenuContext))
560  {
561  if (menu->current < (menu->top + c))
562  menu->top = menu->current - c;
563  else if (menu->current >= (menu->top + menu->pagelen - c))
564  menu->top = menu->current - menu->pagelen + c + 1;
565  }
566  else
567  {
568  if (menu->current < menu->top + c)
569  {
570  menu->top -= (menu->pagelen - c) * ((menu->top + menu->pagelen - 1 - menu->current) /
571  (menu->pagelen - c)) -
572  c;
573  }
574  else if ((menu->current >= (menu->top + menu->pagelen - c)))
575  {
576  menu->top +=
577  (menu->pagelen - c) * ((menu->current - menu->top) / (menu->pagelen - c)) - c;
578  }
579  }
580  }
581 
582  if (!C_MenuMoveOff) /* make entries stick to bottom */
583  menu->top = MIN(menu->top, menu->max - menu->pagelen);
584  menu->top = MAX(menu->top, 0);
585 
586  if (menu->top != old_top)
587  menu->redraw |= REDRAW_INDEX;
588 }
#define MIN(a, b)
Definition: memory.h:31
#define MAX(a, b)
Definition: memory.h:30
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:40
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_jump()

static void menu_jump ( struct Menu menu)
static

Jump to another item in the menu.

Parameters
menuCurrent Menu

Ask the user for a message number to jump to.

Definition at line 596 of file menu.c.

597 {
598  if (menu->max == 0)
599  {
600  mutt_error(_("No entries"));
601  return;
602  }
603 
605  char buf[128] = { 0 };
606  if ((mutt_get_field(_("Jump to: "), buf, sizeof(buf), MUTT_COMP_NO_FLAGS) == 0) &&
607  (buf[0] != '\0'))
608  {
609  int n = 0;
610  if ((mutt_str_atoi(buf, &n) == 0) && (n > 0) && (n < (menu->max + 1)))
611  {
612  menu->current = n - 1; // msg numbers are 0-based
613  menu->redraw = REDRAW_MOTION;
614  }
615  else
616  mutt_error(_("Invalid index number"));
617  }
618 }
int mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition: string.c:252
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:834
#define _(a)
Definition: message.h:28
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:91
#define MUTT_COMP_NO_FLAGS
No flags are set.
Definition: mutt.h:56
int LastKey
contains the last key the user pressed
Definition: keymap.c:146
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:41
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_next_line()

void menu_next_line ( struct Menu menu)

Move the view down one line, keeping the selection the same.

Parameters
menuCurrent Menu

Definition at line 624 of file menu.c.

625 {
626  if (menu->max == 0)
627  {
628  mutt_error(_("No entries"));
629  return;
630  }
631 
632  int c = MIN(C_MenuContext, (menu->pagelen / 2));
633 
634  if (((menu->top + 1) < (menu->max - c)) &&
635  (C_MenuMoveOff ||
636  ((menu->max > menu->pagelen) && (menu->top < (menu->max - menu->pagelen)))))
637  {
638  menu->top++;
639  if ((menu->current < (menu->top + c)) && (menu->current < (menu->max - 1)))
640  menu->current++;
641  menu->redraw = REDRAW_INDEX;
642  }
643  else
644  mutt_message(_("You can't scroll down farther"));
645 }
#define MIN(a, b)
Definition: memory.h:31
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:40
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_prev_line()

void menu_prev_line ( struct Menu menu)

Move the view up one line, keeping the selection the same.

Parameters
menuCurrent Menu

Definition at line 651 of file menu.c.

652 {
653  if (menu->top < 1)
654  {
655  mutt_message(_("You can't scroll up farther"));
656  return;
657  }
658 
659  int c = MIN(C_MenuContext, (menu->pagelen / 2));
660 
661  menu->top--;
662  if ((menu->current >= (menu->top + menu->pagelen - c)) && (menu->current > 1))
663  menu->current--;
664  menu->redraw = REDRAW_INDEX;
665 }
#define MIN(a, b)
Definition: memory.h:31
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:40
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_length_jump()

static void menu_length_jump ( struct Menu menu,
int  jumplen 
)
static

Calculate the destination of a jump.

Parameters
menuCurrent Menu
jumplenNumber of lines to jump
  • pageup: jumplen == -pagelen
  • pagedown: jumplen == pagelen
  • halfup: jumplen == -pagelen/2
  • halfdown: jumplen == pagelen/2

Definition at line 677 of file menu.c.

678 {
679  if (menu->max == 0)
680  {
681  mutt_error(_("No entries"));
682  return;
683  }
684 
685  const int neg = (jumplen >= 0) ? 0 : -1;
686  const int c = MIN(C_MenuContext, (menu->pagelen / 2));
687 
688  /* possible to scroll? */
689  int tmp;
690  if ((DIRECTION * menu->top) <
691  (tmp = (neg ? 0 : (menu->max /* -1 */) - (menu->pagelen /* -1 */))))
692  {
693  menu->top += jumplen;
694 
695  /* jumped too long? */
696  if ((neg || !C_MenuMoveOff) && ((DIRECTION * menu->top) > tmp))
697  menu->top = tmp;
698 
699  /* need to move the cursor? */
700  if ((DIRECTION *
701  (tmp = (menu->current - (menu->top + (neg ? (menu->pagelen - 1) - c : c))))) < 0)
702  {
703  menu->current -= tmp;
704  }
705 
706  menu->redraw = REDRAW_INDEX;
707  }
708  else if ((menu->current != (neg ? 0 : menu->max - 1)) && ARRAY_EMPTY(&menu->dialog))
709  {
710  menu->current += jumplen;
711  menu->redraw = REDRAW_MOTION;
712  }
713  else
714  {
715  mutt_message(neg ? _("You are on the first page") : _("You are on the last page"));
716  }
717 
718  menu->current = MIN(menu->current, menu->max - 1);
719  menu->current = MAX(menu->current, 0);
720 }
#define MIN(a, b)
Definition: memory.h:31
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
#define MAX(a, b)
Definition: memory.h:30
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:41
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:40
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_next_page()

void menu_next_page ( struct Menu menu)

Move the focus to the next page in the menu.

Parameters
menuCurrent Menu

Definition at line 726 of file menu.c.

727 {
728  menu_length_jump(menu, MAX(menu->pagelen /* - MenuOverlap */, 0));
729 }
#define MAX(a, b)
Definition: memory.h:30
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_prev_page()

void menu_prev_page ( struct Menu menu)

Move the focus to the previous page in the menu.

Parameters
menuCurrent Menu

Definition at line 735 of file menu.c.

736 {
737  menu_length_jump(menu, 0 - MAX(menu->pagelen /* - MenuOverlap */, 0));
738 }
#define MAX(a, b)
Definition: memory.h:30
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_half_down()

void menu_half_down ( struct Menu menu)

Move the focus down half a page in the menu.

Parameters
menuCurrent Menu

Definition at line 744 of file menu.c.

745 {
746  menu_length_jump(menu, (menu->pagelen / 2));
747 }
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_half_up()

void menu_half_up ( struct Menu menu)

Move the focus up half a page in the menu.

Parameters
menuCurrent Menu

Definition at line 753 of file menu.c.

754 {
755  menu_length_jump(menu, 0 - (menu->pagelen / 2));
756 }
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_top_page()

void menu_top_page ( struct Menu menu)

Move the focus to the top of the page.

Parameters
menuCurrent Menu

Definition at line 762 of file menu.c.

763 {
764  if (menu->current == menu->top)
765  return;
766 
767  menu->current = menu->top;
768  menu->redraw = REDRAW_MOTION;
769 }
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:41
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_bottom_page()

void menu_bottom_page ( struct Menu menu)

Move the focus to the bottom of the page.

Parameters
menuCurrent Menu

Definition at line 775 of file menu.c.

776 {
777  if (menu->max == 0)
778  {
779  mutt_error(_("No entries"));
780  return;
781  }
782 
783  menu->current = menu->top + menu->pagelen - 1;
784  if (menu->current > (menu->max - 1))
785  menu->current = menu->max - 1;
786  menu->redraw = REDRAW_MOTION;
787 }
#define _(a)
Definition: message.h:28
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:41
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_middle_page()

void menu_middle_page ( struct Menu menu)

Move the focus to the centre of the page.

Parameters
menuCurrent Menu

Definition at line 793 of file menu.c.

794 {
795  if (menu->max == 0)
796  {
797  mutt_error(_("No entries"));
798  return;
799  }
800 
801  int i = menu->top + menu->pagelen;
802  if (i > (menu->max - 1))
803  i = menu->max - 1;
804  menu->current = menu->top + (i - menu->top) / 2;
805  menu->redraw = REDRAW_MOTION;
806 }
#define _(a)
Definition: message.h:28
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:41
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_first_entry()

void menu_first_entry ( struct Menu menu)

Move the focus to the first entry in the menu.

Parameters
menuCurrent Menu

Definition at line 812 of file menu.c.

813 {
814  if (menu->max == 0)
815  {
816  mutt_error(_("No entries"));
817  return;
818  }
819 
820  menu->current = 0;
821  menu->redraw = REDRAW_MOTION;
822 }
#define _(a)
Definition: message.h:28
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:41
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_last_entry()

void menu_last_entry ( struct Menu menu)

Move the focus to the last entry in the menu.

Parameters
menuCurrent Menu

Definition at line 828 of file menu.c.

829 {
830  if (menu->max == 0)
831  {
832  mutt_error(_("No entries"));
833  return;
834  }
835 
836  menu->current = menu->max - 1;
837  menu->redraw = REDRAW_MOTION;
838 }
#define _(a)
Definition: message.h:28
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:41
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_current_top()

void menu_current_top ( struct Menu menu)

Move the current selection to the top of the window.

Parameters
menuCurrent Menu

Definition at line 844 of file menu.c.

845 {
846  if (menu->max == 0)
847  {
848  mutt_error(_("No entries"));
849  return;
850  }
851 
852  menu->top = menu->current;
853  menu->redraw = REDRAW_INDEX;
854 }
#define _(a)
Definition: message.h:28
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:40
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_current_middle()

void menu_current_middle ( struct Menu menu)

Move the current selection to the centre of the window.

Parameters
menuCurrent Menu

Definition at line 860 of file menu.c.

861 {
862  if (menu->max == 0)
863  {
864  mutt_error(_("No entries"));
865  return;
866  }
867 
868  menu->top = menu->current - (menu->pagelen / 2);
869  if (menu->top < 0)
870  menu->top = 0;
871  menu->redraw = REDRAW_INDEX;
872 }
#define _(a)
Definition: message.h:28
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:40
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_current_bottom()

void menu_current_bottom ( struct Menu menu)

Move the current selection to the bottom of the window.

Parameters
menuCurrent Menu

Definition at line 878 of file menu.c.

879 {
880  if (menu->max == 0)
881  {
882  mutt_error(_("No entries"));
883  return;
884  }
885 
886  menu->top = menu->current - menu->pagelen + 1;
887  if (menu->top < 0)
888  menu->top = 0;
889  menu->redraw = REDRAW_INDEX;
890 }
#define _(a)
Definition: message.h:28
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:60
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:40
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_next_entry()

static void menu_next_entry ( struct Menu menu)
static

Move the focus to the next item in the menu.

Parameters
menuCurrent Menu

Definition at line 896 of file menu.c.

897 {
898  if (menu->current < (menu->max - 1))
899  {
900  menu->current++;
901  menu->redraw = REDRAW_MOTION;
902  }
903  else
904  mutt_message(_("You are on the last entry"));
905 }
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:41
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ menu_prev_entry()

static void menu_prev_entry ( struct Menu menu)
static

Move the focus to the previous item in the menu.

Parameters
menuCurrent Menu

Definition at line 911 of file menu.c.

912 {
913  if (menu->current)
914  {
915  menu->current--;
916  menu->redraw = REDRAW_MOTION;
917  }
918  else
919  mutt_message(_("You are on the first entry"));
920 }
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:41
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
int current
Current entry.
Definition: mutt_menu.h:56
+ Here is the caller graph for this function:

◆ default_color()

static int default_color ( int  line)
static

Get the default colour for a line of the menu - Implements Menu::color()

Definition at line 925 of file menu.c.

926 {
927  return Colors->defs[MT_COLOR_NORMAL];
928 }
int * defs
Array of all fixed colours, see enum ColorId.
Definition: color.h:131
Plain text.
Definition: color.h:77
Definition: color.h:129
+ Here is the caller graph for this function:

◆ generic_search()

static int generic_search ( struct Menu menu,
regex_t *  rx,
int  line 
)
static

Search a menu for a item matching a regex - Implements Menu::search()

Definition at line 933 of file menu.c.

934 {
935  char buf[1024];
936 
937  make_entry(buf, sizeof(buf), menu, line);
938  return regexec(rx, buf, 0, NULL, 0);
939 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_menu_init()

void mutt_menu_init ( void  )

Initialise all the Menus.

Definition at line 944 of file menu.c.

945 {
946  for (int i = 0; i < MENU_MAX; i++)
947  SearchBuffers[i] = NULL;
948 }
+ Here is the caller graph for this function:

◆ mutt_menu_new()

struct Menu* mutt_menu_new ( enum MenuType  type)

Create a new Menu.

Parameters
typeMenu type, e.g. MENU_PAGER
Return values
ptrNew Menu

Definition at line 955 of file menu.c.

956 {
957  struct Menu *menu = mutt_mem_calloc(1, sizeof(struct Menu));
958 
959  menu->type = type;
960  menu->redraw = REDRAW_FULL;
961  menu->color = default_color;
962  menu->search = generic_search;
963 
964  return menu;
965 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
GUI selectable list of items.
Definition: mutt_menu.h:52
enum MenuType type
Menu definition for keymap entries.
Definition: mutt_menu.h:59
int(* color)(int line)
Calculate the colour for a line of the menu.
Definition: mutt_menu.h:115
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
int(* search)(struct Menu *menu, regex_t *rx, int line)
Search a menu for a item matching a regex.
Definition: mutt_menu.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_menu_free()

void mutt_menu_free ( struct Menu **  ptr)

Destroy a menu.

Parameters
[out]ptrMenu to destroy

Definition at line 971 of file menu.c.

972 {
973  if (!ptr || !*ptr)
974  return;
975 
976  struct Menu *menu = *ptr;
977  char **line = NULL;
978  ARRAY_FOREACH(line, &menu->dialog)
979  {
980  FREE(line);
981  }
982  ARRAY_FREE(&menu->dialog);
983 
984  FREE(ptr);
985 }
GUI selectable list of items.
Definition: mutt_menu.h:52
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:198
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:206
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ mutt_menu_add_dialog_row()

void mutt_menu_add_dialog_row ( struct Menu menu,
const char *  row 
)

Add a row to a Menu.

Parameters
menuMenu to add to
rowRow of text to add

Definition at line 992 of file menu.c.

993 {
994  ARRAY_SET(&menu->dialog, menu->max, mutt_str_dup(row));
995  menu->max++;
996 }
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
#define ARRAY_SET(head, idx, elem)
Set an element in the array.
Definition: array.h:119
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_current_menu()

static struct Menu* get_current_menu ( void  )
static

Get the current Menu.

Return values
ptrCurrent Menu

Definition at line 1002 of file menu.c.

1003 {
1004  struct Menu **mp = ARRAY_LAST(&MenuStack);
1005  return mp ? *mp : NULL;
1006 }
GUI selectable list of items.
Definition: mutt_menu.h:52
#define ARRAY_LAST(head)
Convenience method to get the last element.
Definition: array.h:140
+ Here is the caller graph for this function:

◆ mutt_menu_push_current()

void mutt_menu_push_current ( struct Menu menu)

Add a new Menu to the stack.

Parameters
menuMenu to add

The menus are stored in a LIFO. The top-most is shown to the user.

Definition at line 1014 of file menu.c.

1015 {
1016  ARRAY_ADD(&MenuStack, menu);
1017  CurrentMenu = menu->type;
1018 }
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: mutt_globals.h:77
enum MenuType type
Menu definition for keymap entries.
Definition: mutt_menu.h:59
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:152
+ Here is the caller graph for this function:

◆ mutt_menu_pop_current()

void mutt_menu_pop_current ( struct Menu menu)

Remove a Menu from the stack.

Parameters
menuCurrent Menu

The menus are stored in a LIFO. The top-most is shown to the user.

Definition at line 1026 of file menu.c.

1027 {
1028  struct Menu *prev_menu = NULL;
1029 
1030  if (ARRAY_EMPTY(&MenuStack) || (*ARRAY_LAST(&MenuStack) != menu))
1031  {
1032  mutt_debug(LL_DEBUG1, "called with inactive menu\n");
1033  return;
1034  }
1035  ARRAY_SHRINK(&MenuStack, 1);
1036 
1037  prev_menu = get_current_menu();
1038  if (prev_menu)
1039  {
1040  CurrentMenu = prev_menu->type;
1041  prev_menu->redraw = REDRAW_FULL;
1042  }
1043  else
1044  {
1046  /* Clearing when NeoMutt exits would be an annoying change in behavior for
1047  * those who have disabled alternative screens. The option is currently
1048  * set by autocrypt initialization which mixes menus and prompts outside of
1049  * the normal menu system state. */
1051  {
1053  }
1054  }
1055 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
GUI selectable list of items.
Definition: mutt_menu.h:52
Index panel (list of emails)
Definition: keymap.h:80
#define ARRAY_SHRINK(head, num)
Mark a number of slots at the end of the array as unused.
Definition: array.h:168
void mutt_window_clear(struct MuttWindow *win)
Clear a Window.
Definition: mutt_window.c:806
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: mutt_globals.h:77
enum MenuType type
Menu definition for keymap entries.
Definition: mutt_menu.h:59
#define ARRAY_LAST(head)
Convenience method to get the last element.
Definition: array.h:140
WHERE bool OptMenuPopClearScreen
(pseudo) clear the screen when popping the last menu
Definition: options.h:40
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:45
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
Log at debug level 1.
Definition: logging.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_menu_set_current_redraw()

void mutt_menu_set_current_redraw ( MuttRedrawFlags  redraw)

Set redraw flags on the current menu.

Parameters
redrawFlags to set, see MuttRedrawFlags

Definition at line 1061 of file menu.c.

1062 {
1063  struct Menu *current_menu = get_current_menu();
1064  if (current_menu)
1065  current_menu->redraw |= redraw;
1066 }
GUI selectable list of items.
Definition: mutt_menu.h:52
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_menu_set_current_redraw_full()

void mutt_menu_set_current_redraw_full ( void  )

Flag the current menu to be fully redrawn.

Definition at line 1071 of file menu.c.

1072 {
1073  struct Menu *current_menu = get_current_menu();
1074  if (current_menu)
1075  current_menu->redraw = REDRAW_FULL;
1076 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
GUI selectable list of items.
Definition: mutt_menu.h:52
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_menu_set_redraw()

void mutt_menu_set_redraw ( enum MenuType  menu,
MuttRedrawFlags  redraw 
)

Set redraw flags on a menu.

Parameters
menuMenu type, e.g. MENU_ALIAS
redrawFlags, e.g. REDRAW_INDEX

This is ignored if it's not the current menu.

Definition at line 1085 of file menu.c.

1086 {
1087  if (CurrentMenu == menu)
1089 }
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: mutt_globals.h:77
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_menu_set_redraw_full()

void mutt_menu_set_redraw_full ( enum MenuType  menu)

Flag a menu to be fully redrawn.

Parameters
menuMenu type, e.g. MENU_ALIAS

This is ignored if it's not the current menu.

Definition at line 1097 of file menu.c.

1098 {
1099  if (CurrentMenu == menu)
1101 }
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: mutt_globals.h:77
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_menu_current_redraw()

void mutt_menu_current_redraw ( void  )

Redraw the current menu.

Definition at line 1106 of file menu.c.

1107 {
1108  struct Menu *current_menu = get_current_menu();
1109  if (current_menu)
1110  {
1111  if (menu_redraw(current_menu) == OP_REDRAW)
1112  {
1113  /* On a REDRAW_FULL with a non-customized redraw, menu_redraw()
1114  * will return OP_REDRAW to give the calling menu-loop a chance to
1115  * customize output. */
1116  menu_redraw(current_menu);
1117  }
1118  }
1119 }
GUI selectable list of items.
Definition: mutt_menu.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ search()

static int search ( struct Menu menu,
int  op 
)
static

Search a menu.

Parameters
menuMenu to search
opSearch operation, e.g. OP_SEARCH_NEXT
Return values
>=0Index of matching item
-1Search failed, or was cancelled

Definition at line 1128 of file menu.c.

1129 {
1130  int rc = 0, wrap = 0;
1131  int search_dir;
1132  regex_t re;
1133  char buf[128];
1134  char *search_buf = ((menu->type < MENU_MAX)) ? SearchBuffers[menu->type] : NULL;
1135 
1136  if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
1137  {
1138  mutt_str_copy(buf, search_buf && (search_buf[0] != '\0') ? search_buf : "",
1139  sizeof(buf));
1140  if ((mutt_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
1141  _("Search for: ") :
1142  _("Reverse search for: "),
1143  buf, sizeof(buf), MUTT_CLEAR) != 0) ||
1144  (buf[0] == '\0'))
1145  {
1146  return -1;
1147  }
1148  if (menu->type < MENU_MAX)
1149  {
1150  mutt_str_replace(&SearchBuffers[menu->type], buf);
1151  search_buf = SearchBuffers[menu->type];
1152  }
1153  menu->search_dir =
1154  ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ? MUTT_SEARCH_DOWN : MUTT_SEARCH_UP;
1155  }
1156 
1157  search_dir = (menu->search_dir == MUTT_SEARCH_UP) ? -1 : 1;
1158  if (op == OP_SEARCH_OPPOSITE)
1159  search_dir = -search_dir;
1160 
1161  if (search_buf)
1162  {
1163  uint16_t flags = mutt_mb_is_lower(search_buf) ? REG_ICASE : 0;
1164  rc = REG_COMP(&re, search_buf, REG_NOSUB | flags);
1165  }
1166 
1167  if (rc != 0)
1168  {
1169  regerror(rc, &re, buf, sizeof(buf));
1170  mutt_error("%s", buf);
1171  return -1;
1172  }
1173 
1174  rc = menu->current + search_dir;
1175 search_next:
1176  if (wrap)
1177  mutt_message(_("Search wrapped to top"));
1178  while ((rc >= 0) && (rc < menu->max))
1179  {
1180  if (menu->search(menu, &re, rc) == 0)
1181  {
1182  regfree(&re);
1183  return rc;
1184  }
1185 
1186  rc += search_dir;
1187  }
1188 
1189  if (C_WrapSearch && (wrap++ == 0))
1190  {
1191  rc = (search_dir == 1) ? 0 : menu->max - 1;
1192  goto search_next;
1193  }
1194  regfree(&re);
1195  mutt_error(_("Not found"));
1196  return -1;
1197 }
#define MUTT_CLEAR
Clear input if printable character is pressed.
Definition: mutt.h:62
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition: regex3.h:54
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:91
enum MenuType type
Menu definition for keymap entries.
Definition: mutt_menu.h:59
int search_dir
Direction of search.
Definition: mutt_menu.h:77
WHERE bool C_WrapSearch
Config: Wrap around when the search hits the end.
Definition: mutt_globals.h:170
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
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:716
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:56
bool mutt_mb_is_lower(const char *s)
Does a multi-byte string contain only lowercase characters?
Definition: mbyte.c:358
int(* search)(struct Menu *menu, regex_t *rx, int line)
Search a menu for a item matching a regex.
Definition: mutt_menu.h:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_dialog_translate_op()

static int menu_dialog_translate_op ( int  i)
static

Convert menubar movement to scrolling.

Parameters
iAction requested, e.g. OP_NEXT_ENTRY
Return values
numAction to perform, e.g. OP_NEXT_LINE

Definition at line 1204 of file menu.c.

1205 {
1206  switch (i)
1207  {
1208  case OP_NEXT_ENTRY:
1209  return OP_NEXT_LINE;
1210  case OP_PREV_ENTRY:
1211  return OP_PREV_LINE;
1212  case OP_CURRENT_TOP:
1213  case OP_FIRST_ENTRY:
1214  return OP_TOP_PAGE;
1215  case OP_CURRENT_BOTTOM:
1216  case OP_LAST_ENTRY:
1217  return OP_BOTTOM_PAGE;
1218  case OP_CURRENT_MIDDLE:
1219  return OP_MIDDLE_PAGE;
1220  }
1221 
1222  return i;
1223 }
+ Here is the caller graph for this function:

◆ menu_dialog_dokey()

static int menu_dialog_dokey ( struct Menu menu,
int *  ip 
)
static

Check if there are any menu key events to process.

Parameters
menuCurrent Menu
ipKeyEvent ID
Return values
0An event occurred for the menu, or a timeout
-1There was an event, but not for menu

Definition at line 1232 of file menu.c.

1233 {
1234  struct KeyEvent ch;
1235  char *p = NULL;
1236 
1237  do
1238  {
1239  ch = mutt_getch();
1240  } while (ch.ch == -2);
1241 
1242  if (ch.ch < 0)
1243  {
1244  *ip = -1;
1245  return 0;
1246  }
1247 
1248  if (ch.ch && (p = strchr(menu->keys, ch.ch)))
1249  {
1250  *ip = OP_MAX + (p - menu->keys + 1);
1251  return 0;
1252  }
1253  else
1254  {
1255  if (ch.op == OP_NULL)
1256  mutt_unget_event(ch.ch, 0);
1257  else
1258  mutt_unget_event(0, ch.op);
1259  return -1;
1260  }
1261 }
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:834
int ch
raw key pressed
Definition: keymap.h:65
An event such as a keypress.
Definition: keymap.h:63
struct KeyEvent mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:189
char * keys
Keys used in the prompt.
Definition: mutt_menu.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw()

int menu_redraw ( struct Menu menu)

Redraw the parts of the screen that have been flagged to be redrawn.

Parameters
menuMenu to redraw
Return values
OP_NULLMenu was redrawn
OP_REDRAWFull redraw required

Definition at line 1269 of file menu.c.

1270 {
1271  if (menu->custom_redraw)
1272  {
1273  menu->custom_redraw(menu);
1274  return OP_NULL;
1275  }
1276 
1277  /* See if all or part of the screen needs to be updated. */
1278  if (menu->redraw & REDRAW_FULL)
1279  {
1280  menu_redraw_full(menu);
1281  /* allow the caller to do any local configuration */
1282  return OP_REDRAW;
1283  }
1284 
1285  if (ARRAY_EMPTY(&menu->dialog))
1286  menu_check_recenter(menu);
1287 
1288  if (menu->redraw & REDRAW_STATUS)
1289  menu_redraw_status(menu);
1290  if (menu->redraw & REDRAW_INDEX)
1291  menu_redraw_index(menu);
1292  else if (menu->redraw & (REDRAW_MOTION | REDRAW_MOTION_RESYNC))
1293  menu_redraw_motion(menu);
1294  else if (menu->redraw == REDRAW_CURRENT)
1295  menu_redraw_current(menu);
1296 
1297  if (!ARRAY_EMPTY(&menu->dialog))
1298  menu_redraw_prompt(menu);
1299 
1300  return OP_NULL;
1301 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:41
#define REDRAW_MOTION_RESYNC
Redraw any changing the menu selection.
Definition: mutt_menu.h:42
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:44
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
void(* custom_redraw)(struct Menu *menu)
Redraw the menu.
Definition: mutt_menu.h:121
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:40
#define REDRAW_CURRENT
Redraw the current line of the menu.
Definition: mutt_menu.h:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_menu_loop()

int mutt_menu_loop ( struct Menu menu)

Menu event loop.

Parameters
menuCurrent Menu
Return values
numAn event id that the menu can't process

Definition at line 1308 of file menu.c.

1309 {
1310  static int last_position = -1;
1311  int op = OP_NULL;
1312 
1313  if (menu->max && menu->is_mailbox_list)
1314  {
1315  if (last_position > (menu->max - 1))
1316  last_position = -1;
1317  else if (last_position >= 0)
1318  menu->current = last_position;
1319  }
1320 
1321  while (true)
1322  {
1323  /* Clear the tag prefix unless we just started it. Don't clear
1324  * the prefix on a timeout (op==-2), but do clear on an abort (op==-1) */
1325  if (menu->tagprefix && (op != OP_TAG_PREFIX) &&
1326  (op != OP_TAG_PREFIX_COND) && (op != -2))
1327  {
1328  menu->tagprefix = false;
1329  }
1330 
1332 
1333  if (menu_redraw(menu) == OP_REDRAW)
1334  return OP_REDRAW;
1335 
1336  /* give visual indication that the next command is a tag- command */
1337  if (menu->tagprefix)
1338  {
1339  mutt_window_mvaddstr(MessageWindow, 0, 0, "tag-");
1341  }
1342 
1343  menu->oldcurrent = menu->current;
1344 
1345  /* move the cursor out of the way */
1346  if (C_ArrowCursor)
1347  mutt_window_move(menu->win_index, 2, menu->current - menu->top);
1348  else if (C_BrailleFriendly)
1349  mutt_window_move(menu->win_index, 0, menu->current - menu->top);
1350  else
1351  {
1352  mutt_window_move(menu->win_index, menu->win_index->state.cols - 1,
1353  menu->current - menu->top);
1354  }
1355 
1356  mutt_refresh();
1357 
1358  /* try to catch dialog keys before ops */
1359  if (!ARRAY_EMPTY(&menu->dialog) && (menu_dialog_dokey(menu, &op) == 0))
1360  return op;
1361 
1362  op = km_dokey(menu->type);
1363  if ((op == OP_TAG_PREFIX) || (op == OP_TAG_PREFIX_COND))
1364  {
1365  if (menu->tagprefix)
1366  {
1367  menu->tagprefix = false;
1369  continue;
1370  }
1371 
1372  if (menu->tagged)
1373  {
1374  menu->tagprefix = true;
1375  continue;
1376  }
1377  else if (op == OP_TAG_PREFIX)
1378  {
1379  mutt_error(_("No tagged entries"));
1380  op = -1;
1381  }
1382  else /* None tagged, OP_TAG_PREFIX_COND */
1383  {
1385  mutt_message(_("Nothing to do"));
1386  op = -1;
1387  }
1388  }
1389  else if (menu->tagged && C_AutoTag)
1390  menu->tagprefix = true;
1391 
1393 
1394  if (SigWinch)
1395  {
1396  SigWinch = 0;
1398  clearok(stdscr, true); /* force complete redraw */
1399  }
1400 
1401  if (op < 0)
1402  {
1403  if (menu->tagprefix)
1405  continue;
1406  }
1407 
1408  if (ARRAY_EMPTY(&menu->dialog))
1409  mutt_clear_error();
1410 
1411  /* Convert menubar movement to scrolling */
1412  if (!ARRAY_EMPTY(&menu->dialog))
1413  op = menu_dialog_translate_op(op);
1414 
1415  switch (op)
1416  {
1417  case OP_NEXT_ENTRY:
1418  menu_next_entry(menu);
1419  break;
1420  case OP_PREV_ENTRY:
1421  menu_prev_entry(menu);
1422  break;
1423  case OP_HALF_DOWN:
1424  menu_half_down(menu);
1425  break;
1426  case OP_HALF_UP:
1427  menu_half_up(menu);
1428  break;
1429  case OP_NEXT_PAGE:
1430  menu_next_page(menu);
1431  break;
1432  case OP_PREV_PAGE:
1433  menu_prev_page(menu);
1434  break;
1435  case OP_NEXT_LINE:
1436  menu_next_line(menu);
1437  break;
1438  case OP_PREV_LINE:
1439  menu_prev_line(menu);
1440  break;
1441  case OP_FIRST_ENTRY:
1442  menu_first_entry(menu);
1443  break;
1444  case OP_LAST_ENTRY:
1445  menu_last_entry(menu);
1446  break;
1447  case OP_TOP_PAGE:
1448  menu_top_page(menu);
1449  break;
1450  case OP_MIDDLE_PAGE:
1451  menu_middle_page(menu);
1452  break;
1453  case OP_BOTTOM_PAGE:
1454  menu_bottom_page(menu);
1455  break;
1456  case OP_CURRENT_TOP:
1457  menu_current_top(menu);
1458  break;
1459  case OP_CURRENT_MIDDLE:
1460  menu_current_middle(menu);
1461  break;
1462  case OP_CURRENT_BOTTOM:
1463  menu_current_bottom(menu);
1464  break;
1465  case OP_SEARCH:
1466  case OP_SEARCH_REVERSE:
1467  case OP_SEARCH_NEXT:
1468  case OP_SEARCH_OPPOSITE:
1469  if (menu->custom_search)
1470  return op;
1471  else if (menu->search && ARRAY_EMPTY(&menu->dialog)) /* Searching dialogs won't work */
1472  {
1473  menu->oldcurrent = menu->current;
1474  menu->current = search(menu, op);
1475  if (menu->current != -1)
1476  menu->redraw = REDRAW_MOTION;
1477  else
1478  menu->current = menu->oldcurrent;
1479  }
1480  else
1481  mutt_error(_("Search is not implemented for this menu"));
1482  break;
1483 
1484  case OP_JUMP:
1485  if (!ARRAY_EMPTY(&menu->dialog))
1486  mutt_error(_("Jumping is not implemented for dialogs"));
1487  else
1488  menu_jump(menu);
1489  break;
1490 
1491  case OP_ENTER_COMMAND:
1493  window_set_focus(menu->win_index);
1494  window_redraw(RootWindow, false);
1495  break;
1496 
1497  case OP_TAG:
1498  if (menu->tag && ARRAY_EMPTY(&menu->dialog))
1499  {
1500  if (menu->tagprefix && !C_AutoTag)
1501  {
1502  for (int i = 0; i < menu->max; i++)
1503  menu->tagged += menu->tag(menu, i, 0);
1504  menu->redraw |= REDRAW_INDEX;
1505  }
1506  else if (menu->max != 0)
1507  {
1508  int j = menu->tag(menu, menu->current, -1);
1509  menu->tagged += j;
1510  if (j && C_Resolve && (menu->current < (menu->max - 1)))
1511  {
1512  menu->current++;
1513  menu->redraw |= REDRAW_MOTION_RESYNC;
1514  }
1515  else
1516  menu->redraw |= REDRAW_CURRENT;
1517  }
1518  else
1519  mutt_error(_("No entries"));
1520  }
1521  else
1522  mutt_error(_("Tagging is not supported"));
1523  break;
1524 
1525  case OP_SHELL_ESCAPE:
1526  if (mutt_shell_escape())
1527  {
1529  }
1530  break;
1531 
1532  case OP_WHAT_KEY:
1533  mutt_what_key();
1534  break;
1535 
1536  case OP_CHECK_STATS:
1537  mutt_check_stats();
1538  break;
1539 
1540  case OP_REDRAW:
1541  clearok(stdscr, true);
1542  menu->redraw = REDRAW_FULL;
1543  break;
1544 
1545  case OP_HELP:
1546  mutt_help(menu->type, menu->win_index->state.cols);
1547  menu->redraw = REDRAW_FULL;
1548  break;
1549 
1550  case OP_NULL:
1551  km_error_key(menu->type);
1552  break;
1553 
1554  case OP_END_COND:
1555  break;
1556 
1557  default:
1558  if (menu->is_mailbox_list)
1559  last_position = menu->current;
1560  return op;
1561  }
1562  }
1563  /* not reached */
1564 }
int km_dokey(enum MenuType menu)
Determine what a keypress should do.
Definition: keymap.c:658
The "current" mailbox.
Definition: context.h:38
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
struct Mailbox * ctx_mailbox(struct Context *ctx)
wrapper to get the mailbox in a Context, or NULL
Definition: context.c:428
void window_set_focus(struct MuttWindow *win)
Set the Window focus.
Definition: mutt_window.c:763
#define mutt_message(...)
Definition: logging.h:83
int oldcurrent
For driver use only.
Definition: mutt_menu.h:76
bool mutt_shell_escape(void)
invoke a command in a subshell
Definition: commands.c:846
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:244
void mutt_resize_screen(void)
Update NeoMutt&#39;s opinion about the window size (CURSES)
Definition: resize.c:101
void mutt_check_stats(void)
Forcibly update mailbox stats.
Definition: commands.c:1435
void mutt_enter_command(void)
enter a neomutt command
Definition: commands.c:879
#define _(a)
Definition: message.h:28
int op
function op
Definition: keymap.h:66
WHERE bool C_BrailleFriendly
Config: Move the cursor to the beginning of the line.
Definition: mutt_globals.h:140
int mutt_window_mvaddstr(struct MuttWindow *win, int col, int row, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:396
WHERE bool C_AutoTag
Config: Automatically apply actions to all tagged messages.
Definition: mutt_globals.h:137
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:382
void mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:78
enum MenuType type
Menu definition for keymap entries.
Definition: mutt_menu.h:59
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition: curs_lib.c:890
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:232
void mutt_what_key(void)
Ask the user to press a key.
Definition: keymap.c:1676
Display a normal cursor.
Definition: mutt_curses.h:81
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:41
#define REDRAW_MOTION_RESYNC
Redraw any changing the menu selection.
Definition: mutt_menu.h:42
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:57
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:108
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:120
struct MuttWindow * MessageWindow
Message Window, ":set", etc.
Definition: mutt_window.c:47
struct MuttWindow * RootWindow
Parent of all Windows.
Definition: mutt_window.c:45
void km_error_key(enum MenuType menu)
Handle an unbound key sequence.
Definition: keymap.c:1137
int mutt_mailbox_check(struct Mailbox *m_cur, int force)
Check all all Mailboxes for new mail.
Definition: mutt_mailbox.c:138
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
bool tagprefix
Definition: mutt_menu.h:61
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
bool is_mailbox_list
Definition: mutt_menu.h:62
int(* tag)(struct Menu *menu, int sel, int act)
Tag some menu items.
Definition: mutt_menu.h:107
bool custom_search
The menu implements its own non-Menusearch()-compatible search, trickle OP_SEARCH*.
Definition: mutt_menu.h:79
int tagged
Number of tagged entries.
Definition: mutt_menu.h:78
#define MUTT_MAILBOX_CHECK_FORCE
Definition: mutt_mailbox.h:16
int max
Number of entries in the menu.
Definition: mutt_menu.h:57
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: mutt_globals.h:131
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:40
void mutt_help(enum MenuType menu, int wraplen)
Display the help menu.
Definition: help.c:386
#define mutt_error(...)
Definition: logging.h:84
Hide the cursor.
Definition: mutt_curses.h:80
void window_redraw(struct MuttWindow *win, bool force)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:747
int current
Current entry.
Definition: mutt_menu.h:56
struct MuttWindow * win_index
Definition: mutt_menu.h:63
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: mutt_globals.h:75
int(* search)(struct Menu *menu, regex_t *rx, int line)
Search a menu for a item matching a regex.
Definition: mutt_menu.h:98
#define REDRAW_CURRENT
Redraw the current line of the menu.
Definition: mutt_menu.h:43
WHERE bool C_Resolve
Config: Move to the next email whenever a command modifies an email.
Definition: mutt_globals.h:155
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_menu_color_observer()

int mutt_menu_color_observer ( struct NotifyCallback nc)

Listen for colour changes affecting the menu - Implements observer_t.

Definition at line 1569 of file menu.c.

1570 {
1571  if (!nc->event_data)
1572  return -1;
1573  if (nc->event_type != NT_CONFIG)
1574  return 0;
1575 
1576  struct EventColor *ev_c = nc->event_data;
1577 
1578  int c = ev_c->color;
1579 
1580  bool simple = (c == MT_COLOR_INDEX_COLLAPSED) || (c == MT_COLOR_INDEX_DATE) ||
1581  (c == MT_COLOR_INDEX_LABEL) || (c == MT_COLOR_INDEX_NUMBER) ||
1582  (c == MT_COLOR_INDEX_SIZE) || (c == MT_COLOR_INDEX_TAGS);
1583  bool lists = (c == MT_COLOR_ATTACH_HEADERS) || (c == MT_COLOR_BODY) ||
1584  (c == MT_COLOR_HEADER) || (c == MT_COLOR_INDEX) ||
1585  (c == MT_COLOR_INDEX_AUTHOR) || (c == MT_COLOR_INDEX_FLAGS) ||
1586  (c == MT_COLOR_INDEX_SUBJECT) || (c == MT_COLOR_INDEX_TAG);
1587 
1588  // The changes aren't relevant to the index menu
1589  if (!simple && !lists)
1590  return 0;
1591 
1592  // Colour deleted from a list
1593  struct Mailbox *m = ctx_mailbox(Context);
1594  if ((nc->event_subtype == NT_COLOR_RESET) && lists && m)
1595  {
1596  // Force re-caching of index colors
1597  for (int i = 0; i < m->msg_count; i++)
1598  {
1599  struct Email *e = m->emails[i];
1600  if (!e)
1601  break;
1602  e->pair = 0;
1603  }
1604  }
1605 
1607  return 0;
1608 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
MIME attachment test (takes a pattern)
Definition: color.h:62
The "current" mailbox.
Definition: context.h:38
Index: index number.
Definition: color.h:109
int msg_count
Total number of messages.
Definition: mailbox.h:91
The envelope/body of an email.
Definition: email.h:37
Index: tags field (g, J)
Definition: color.h:111
struct Mailbox * ctx_mailbox(struct Context *ctx)
wrapper to get the mailbox in a Context, or NULL
Definition: context.c:428
An Event that happened to a Colour.
Definition: color.h:159
Pager: highlight body of message (takes a pattern)
Definition: color.h:63
Index panel (list of emails)
Definition: keymap.h:80
Index: number of messages in collapsed thread.
Definition: color.h:106
int event_subtype
Send: Event subtype, e.g. NT_ACCOUNT_ADD.
Definition: observer.h:43
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
Index: author field (takes a pattern)
Definition: color.h:101
Message headers (takes a pattern)
Definition: color.h:72
Index: tag field (g, takes a pattern)
Definition: color.h:104
Index: date field.
Definition: color.h:107
Index: size field.
Definition: color.h:110
A mailbox.
Definition: mailbox.h:81
Color has been reset/removed.
Definition: color.h:172
enum ColorId color
Definition: color.h:161
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:37
Index: label field.
Definition: color.h:108
Index: subject field (takes a pattern)
Definition: color.h:103
Index: default colour (takes a pattern)
Definition: color.h:100
int pair
Color-pair to use when displaying in the index.
Definition: email.h:80
Index: flags field (takes a pattern)
Definition: color.h:102
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_menu_config_observer()

int mutt_menu_config_observer ( struct NotifyCallback nc)

Listen for config changes affecting the menu - Implements observer_t.

Definition at line 1613 of file menu.c.

1614 {
1615  if (!nc->event_data)
1616  return -1;
1617  if (nc->event_type != NT_CONFIG)
1618  return 0;
1619 
1620  struct EventConfig *ec = nc->event_data;
1621 
1622  const struct ConfigDef *cdef = ec->he->data;
1623  ConfigRedrawFlags flags = cdef->type & R_REDRAW_MASK;
1624 
1625  if (flags == R_REDRAW_NO_FLAGS)
1626  return 0;
1627 
1628  if (flags & R_INDEX)
1630  if (flags & R_PAGER)
1632  if (flags & R_PAGER_FLOW)
1633  {
1636  }
1637 
1638  if (flags & R_RESORT_SUB)
1639  OptSortSubthreads = true;
1640  if (flags & R_RESORT)
1641  OptNeedResort = true;
1642  if (flags & R_RESORT_INIT)
1643  OptResortInit = true;
1644  if (flags & R_TREE)
1645  OptRedrawTree = true;
1646 
1647  if (flags & R_REFLOW)
1648  mutt_window_reflow(NULL);
1649  if (flags & R_MENU)
1651 
1652  return 0;
1653 }
#define R_PAGER
Redraw the pager menu.
Definition: types.h:66
#define R_PAGER_FLOW
Reflow line_info and redraw the pager menu.
Definition: types.h:67
#define REDRAW_FLOW
Used by pager to reflow text.
Definition: mutt_menu.h:47
WHERE bool OptNeedResort
(pseudo) used to force a re-sort
Definition: options.h:43
A config-change event.
Definition: subset.h:70
Index panel (list of emails)
Definition: keymap.h:80
Config item definition.
Definition: set.h:61
#define R_RESORT
Resort the mailbox.
Definition: types.h:68
#define R_TREE
Redraw the thread tree.
Definition: types.h:71
enum NotifyType event_type
Send: Event type, e.g. NT_ACCOUNT.
Definition: observer.h:42
Pager pager (email viewer)
Definition: keymap.h:81
#define R_REDRAW_NO_FLAGS
No refresh/resort flags.
Definition: types.h:64
struct HashElem * he
Config item that changed.
Definition: subset.h:74
#define R_MENU
Redraw all menus.
Definition: types.h:74
#define R_RESORT_SUB
Resort subthreads.
Definition: types.h:69
#define R_REFLOW
Reflow window layout and full redraw.
Definition: types.h:72
uint32_t ConfigRedrawFlags
Flags for redraw/resort, e.g. R_INDEX.
Definition: types.h:63
uint32_t type
Variable type, e.g. DT_STRING.
Definition: set.h:64
WHERE bool OptRedrawTree
(pseudo) redraw the thread tree
Definition: options.h:50
WHERE bool OptResortInit
(pseudo) used to force the next resort to be from scratch
Definition: options.h:51
void * event_data
Data from notify_send()
Definition: observer.h:44
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:37
void * data
User-supplied data.
Definition: hash.h:47
void mutt_window_reflow(struct MuttWindow *win)
Resize a Window and its children.
Definition: mutt_window.c:433
#define R_RESORT_INIT
Resort from scratch.
Definition: types.h:70
WHERE bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition: options.h:54
#define R_REDRAW_MASK
Mask for the Redraw Flags.
Definition: types.h:76
#define R_INDEX
Redraw the index menu (MENU_MAIN)
Definition: types.h:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ C_MenuContext

short C_MenuContext

Config: Number of lines of overlap when changing pages in the index.

Definition at line 56 of file menu.c.

◆ C_MenuMoveOff

bool C_MenuMoveOff

Config: Allow the last menu item to move off the bottom of the screen.

Definition at line 57 of file menu.c.

◆ C_MenuScroll

bool C_MenuScroll

Config: Scroll the menu/index by one line, rather than a page.

Definition at line 58 of file menu.c.

◆ SearchBuffers

char* SearchBuffers[MENU_MAX]

Definition at line 60 of file menu.c.