NeoMutt  2020-11-20
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_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

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 61 of file menu.c.

78 {
79  struct ColorLineList *color = NULL;
80  struct ColorLine *np = NULL;
82  int type = *s;
83 
84  switch (type)
85  {
87  color = &Colors->index_author_list;
88  break;
90  color = &Colors->index_flags_list;
91  break;
93  color = &Colors->index_subject_list;
94  break;
95  case MT_COLOR_INDEX_TAG:
96  STAILQ_FOREACH(np, &Colors->index_tag_list, entries)
97  {
98  if (mutt_strn_equal((const char *) (s + 1), np->pattern, strlen(np->pattern)))
99  return np->pair;
100  const char *transform = mutt_hash_find(TagTransforms, np->pattern);
101  if (transform && mutt_strn_equal((const char *) (s + 1), transform, strlen(transform)))
102  {
103  return np->pair;
104  }
105  }
106  return 0;
107  default:
108  return Colors->defs[type];
109  }
110 
111  STAILQ_FOREACH(np, color, entries)
112  {
115  return np->pair;
116  }
117 
118  return 0;
119 }
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 128 of file menu.c.

129 {
130  wchar_t wc;
131  size_t k;
132  size_t n = mutt_str_len((char *) s);
133  mbstate_t mbstate;
134 
135  memset(&mbstate, 0, sizeof(mbstate));
136  while (*s)
137  {
138  if (*s < MUTT_TREE_MAX)
139  {
140  if (do_color)
141 #if defined(HAVE_COLOR) && defined(HAVE_USE_DEFAULT_COLORS)
142  /* Combining tree fg color and another bg color requires
143  * having use_default_colors, because the other bg color
144  * may be undefined. */
146 #else
148 #endif
149 
150  while (*s && (*s < MUTT_TREE_MAX))
151  {
152  switch (*s)
153  {
154  case MUTT_TREE_LLCORNER:
155  if (C_AsciiChars)
156  mutt_window_addch('`');
157 #ifdef WACS_LLCORNER
158  else
159  add_wch(WACS_LLCORNER);
160 #else
161  else if (CharsetIsUtf8)
162  mutt_window_addstr("\342\224\224"); /* WACS_LLCORNER */
163  else
164  mutt_window_addch(ACS_LLCORNER);
165 #endif
166  break;
167  case MUTT_TREE_ULCORNER:
168  if (C_AsciiChars)
169  mutt_window_addch(',');
170 #ifdef WACS_ULCORNER
171  else
172  add_wch(WACS_ULCORNER);
173 #else
174  else if (CharsetIsUtf8)
175  mutt_window_addstr("\342\224\214"); /* WACS_ULCORNER */
176  else
177  mutt_window_addch(ACS_ULCORNER);
178 #endif
179  break;
180  case MUTT_TREE_LTEE:
181  if (C_AsciiChars)
182  mutt_window_addch('|');
183 #ifdef WACS_LTEE
184  else
185  add_wch(WACS_LTEE);
186 #else
187  else if (CharsetIsUtf8)
188  mutt_window_addstr("\342\224\234"); /* WACS_LTEE */
189  else
190  mutt_window_addch(ACS_LTEE);
191 #endif
192  break;
193  case MUTT_TREE_HLINE:
194  if (C_AsciiChars)
195  mutt_window_addch('-');
196 #ifdef WACS_HLINE
197  else
198  add_wch(WACS_HLINE);
199 #else
200  else if (CharsetIsUtf8)
201  mutt_window_addstr("\342\224\200"); /* WACS_HLINE */
202  else
203  mutt_window_addch(ACS_HLINE);
204 #endif
205  break;
206  case MUTT_TREE_VLINE:
207  if (C_AsciiChars)
208  mutt_window_addch('|');
209 #ifdef WACS_VLINE
210  else
211  add_wch(WACS_VLINE);
212 #else
213  else if (CharsetIsUtf8)
214  mutt_window_addstr("\342\224\202"); /* WACS_VLINE */
215  else
216  mutt_window_addch(ACS_VLINE);
217 #endif
218  break;
219  case MUTT_TREE_TTEE:
220  if (C_AsciiChars)
221  mutt_window_addch('-');
222 #ifdef WACS_TTEE
223  else
224  add_wch(WACS_TTEE);
225 #else
226  else if (CharsetIsUtf8)
227  mutt_window_addstr("\342\224\254"); /* WACS_TTEE */
228  else
229  mutt_window_addch(ACS_TTEE);
230 #endif
231  break;
232  case MUTT_TREE_BTEE:
233  if (C_AsciiChars)
234  mutt_window_addch('-');
235 #ifdef WACS_BTEE
236  else
237  add_wch(WACS_BTEE);
238 #else
239  else if (CharsetIsUtf8)
240  mutt_window_addstr("\342\224\264"); /* WACS_BTEE */
241  else
242  mutt_window_addch(ACS_BTEE);
243 #endif
244  break;
245  case MUTT_TREE_SPACE:
246  mutt_window_addch(' ');
247  break;
248  case MUTT_TREE_RARROW:
249  mutt_window_addch('>');
250  break;
251  case MUTT_TREE_STAR:
252  mutt_window_addch('*'); /* fake thread indicator */
253  break;
254  case MUTT_TREE_HIDDEN:
255  mutt_window_addch('&');
256  break;
257  case MUTT_TREE_EQUALS:
258  mutt_window_addch('=');
259  break;
260  case MUTT_TREE_MISSING:
261  mutt_window_addch('?');
262  break;
263  }
264  s++;
265  n--;
266  }
267  if (do_color)
268  mutt_curses_set_attr(attr);
269  }
270  else if (*s == MUTT_SPECIAL_INDEX)
271  {
272  s++;
273  if (do_color)
274  {
275  if (*s == MT_COLOR_INDEX)
276  {
277  attrset(attr);
278  }
279  else
280  {
281  if (get_color(index, s) == 0)
282  {
283  attron(attr);
284  }
285  else
286  {
287  attron(get_color(index, s));
288  }
289  }
290  }
291  s++;
292  n -= 2;
293  }
294  else if ((k = mbrtowc(&wc, (char *) s, n, &mbstate)) > 0)
295  {
296  mutt_window_addnstr((char *) s, k);
297  s += k;
298  n -= k;
299  }
300  else
301  break;
302  }
303 }
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:576
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 312 of file menu.c.

313 {
314  if (!ARRAY_EMPTY(&menu->dialog))
315  {
316  mutt_str_copy(buf, NONULL(*ARRAY_GET(&menu->dialog, i)), buflen);
317  menu->current = -1; /* hide menubar */
318  }
319  else
320  menu->make_entry(buf, buflen, menu, i);
321 }
#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 331 of file menu.c.

332 {
333  char *scratch = mutt_str_dup(buf);
334  int shift = C_ArrowCursor ? mutt_strwidth(C_ArrowString) + 1 : 0;
335  int cols = menu->win_index->state.cols - shift;
336 
337  mutt_simple_format(buf, buflen, cols, cols, JUSTIFY_LEFT, ' ', scratch,
338  mutt_str_len(scratch), true);
339  buf[buflen - 1] = '\0';
340  FREE(&scratch);
341 }
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 347 of file menu.c.

348 {
351 
352  window_redraw(RootWindow, true);
353  menu->pagelen = menu->win_index->state.rows;
354 
355  mutt_show_error();
356 
358 }
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 364 of file menu.c.

365 {
366  char buf[256];
367 
368  snprintf(buf, sizeof(buf), "-- NeoMutt: %s", menu->title);
370  mutt_window_move(menu->win_ibar, 0, 0);
371  mutt_paddstr(menu->win_ibar->state.cols, buf);
373  menu->redraw &= ~REDRAW_STATUS;
374 }
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 380 of file menu.c.

381 {
382  char buf[1024];
383  bool do_color;
384  int attr;
385 
386  for (int i = menu->top; i < menu->top + menu->pagelen; i++)
387  {
388  if (i < menu->max)
389  {
390  attr = menu->color(i);
391 
392  make_entry(buf, sizeof(buf), menu, i);
393  menu_pad_string(menu, buf, sizeof(buf));
394 
395  mutt_curses_set_attr(attr);
396  mutt_window_move(menu->win_index, 0, i - menu->top);
397  do_color = true;
398 
399  if (i == menu->current)
400  {
402  if (C_ArrowCursor)
403  {
405  mutt_curses_set_attr(attr);
406  mutt_window_addch(' ');
407  }
408  else
409  do_color = false;
410  }
411  else if (C_ArrowCursor)
412  /* Print space chars to match the screen width of `$arrow_string` */
414 
415  print_enriched_string(i, attr, (unsigned char *) buf, do_color);
416  }
417  else
418  {
420  mutt_window_clearline(menu->win_index, i - menu->top);
421  }
422  }
424  menu->redraw = 0;
425 }
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 431 of file menu.c.

432 {
433  char buf[1024];
434 
435  if (!ARRAY_EMPTY(&menu->dialog))
436  {
437  menu->redraw &= ~REDRAW_MOTION;
438  return;
439  }
440 
441  /* Note: menu->color() for the index can end up retrieving a message
442  * over imap (if matching against ~h for instance). This can
443  * generate status messages. So we want to call it *before* we
444  * position the cursor for drawing. */
445  const int old_color = menu->color(menu->oldcurrent);
446  mutt_window_move(menu->win_index, 0, menu->oldcurrent - menu->top);
447  mutt_curses_set_attr(old_color);
448 
449  if (C_ArrowCursor)
450  {
451  /* clear the arrow */
452  /* Print space chars to match the screen width of `$arrow_string` */
454 
455  if (menu->redraw & REDRAW_MOTION_RESYNC)
456  {
457  make_entry(buf, sizeof(buf), menu, menu->oldcurrent);
458  menu_pad_string(menu, buf, sizeof(buf));
460  menu->oldcurrent - menu->top);
461  print_enriched_string(menu->oldcurrent, old_color, (unsigned char *) buf, true);
462  }
463 
464  /* now draw it in the new location */
466  mutt_window_mvaddstr(menu->win_index, 0, menu->current - menu->top, C_ArrowString);
467  }
468  else
469  {
470  /* erase the current indicator */
471  make_entry(buf, sizeof(buf), menu, menu->oldcurrent);
472  menu_pad_string(menu, buf, sizeof(buf));
473  print_enriched_string(menu->oldcurrent, old_color, (unsigned char *) buf, true);
474 
475  /* now draw the new one to reflect the change */
476  const int cur_color = menu->color(menu->current);
477  make_entry(buf, sizeof(buf), menu, menu->current);
478  menu_pad_string(menu, buf, sizeof(buf));
480  mutt_window_move(menu->win_index, 0, menu->current - menu->top);
481  print_enriched_string(menu->current, cur_color, (unsigned char *) buf, false);
482  }
483  menu->redraw &= REDRAW_STATUS;
485 }
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 491 of file menu.c.

492 {
493  char buf[1024];
494  int attr = menu->color(menu->current);
495 
496  mutt_window_move(menu->win_index, 0, menu->current - menu->top);
497  make_entry(buf, sizeof(buf), menu, menu->current);
498  menu_pad_string(menu, buf, sizeof(buf));
499 
501  if (C_ArrowCursor)
502  {
504  mutt_curses_set_attr(attr);
505  mutt_window_addch(' ');
506  menu_pad_string(menu, buf, sizeof(buf));
507  print_enriched_string(menu->current, attr, (unsigned char *) buf, true);
508  }
509  else
510  print_enriched_string(menu->current, attr, (unsigned char *) buf, false);
511  menu->redraw &= REDRAW_STATUS;
513 }
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 519 of file menu.c.

520 {
521  if (!menu || ARRAY_EMPTY(&menu->dialog))
522  return;
523 
524  if (OptMsgErr)
525  {
526  mutt_sleep(1);
527  OptMsgErr = false;
528  }
529 
530  if (ErrorBufMessage)
532 
535 }
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:1446
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 541 of file menu.c.

542 {
543  int c = MIN(C_MenuContext, menu->pagelen / 2);
544  int old_top = menu->top;
545 
546  if (!C_MenuMoveOff && (menu->max <= menu->pagelen)) /* less entries than lines */
547  {
548  if (menu->top != 0)
549  {
550  menu->top = 0;
551  menu->redraw |= REDRAW_INDEX;
552  }
553  }
554  else
555  {
556  if (C_MenuScroll || (menu->pagelen <= 0) || (c < C_MenuContext))
557  {
558  if (menu->current < menu->top + c)
559  menu->top = menu->current - c;
560  else if (menu->current >= menu->top + menu->pagelen - c)
561  menu->top = menu->current - menu->pagelen + c + 1;
562  }
563  else
564  {
565  if (menu->current < menu->top + c)
566  {
567  menu->top -= (menu->pagelen - c) * ((menu->top + menu->pagelen - 1 - menu->current) /
568  (menu->pagelen - c)) -
569  c;
570  }
571  else if ((menu->current >= menu->top + menu->pagelen - c))
572  {
573  menu->top +=
574  (menu->pagelen - c) * ((menu->current - menu->top) / (menu->pagelen - c)) - c;
575  }
576  }
577  }
578 
579  if (!C_MenuMoveOff) /* make entries stick to bottom */
580  menu->top = MIN(menu->top, menu->max - menu->pagelen);
581  menu->top = MAX(menu->top, 0);
582 
583  if (menu->top != old_top)
584  menu->redraw |= REDRAW_INDEX;
585 }
#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 593 of file menu.c.

594 {
595  int n;
596 
597  if (menu->max)
598  {
600  char buf[128];
601  buf[0] = '\0';
602  if ((mutt_get_field(_("Jump to: "), buf, sizeof(buf), MUTT_COMP_NO_FLAGS) == 0) && buf[0])
603  {
604  if ((mutt_str_atoi(buf, &n) == 0) && (n > 0) && (n < menu->max + 1))
605  {
606  n--; /* msg numbers are 0-based */
607  menu->current = n;
608  menu->redraw = REDRAW_MOTION;
609  }
610  else
611  mutt_error(_("Invalid index number"));
612  }
613  }
614  else
615  mutt_error(_("No entries"));
616 }
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 622 of file menu.c.

623 {
624  if (menu->max)
625  {
626  int c = MIN(C_MenuContext, menu->pagelen / 2);
627 
628  if ((menu->top + 1 < menu->max - c) &&
629  (C_MenuMoveOff ||
630  ((menu->max > menu->pagelen) && (menu->top < menu->max - menu->pagelen))))
631  {
632  menu->top++;
633  if ((menu->current < menu->top + c) && (menu->current < menu->max - 1))
634  menu->current++;
635  menu->redraw = REDRAW_INDEX;
636  }
637  else
638  mutt_message(_("You can't scroll down farther"));
639  }
640  else
641  mutt_error(_("No entries"));
642 }
#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 648 of file menu.c.

649 {
650  if (menu->top > 0)
651  {
652  int c = MIN(C_MenuContext, menu->pagelen / 2);
653 
654  menu->top--;
655  if ((menu->current >= menu->top + menu->pagelen - c) && (menu->current > 1))
656  menu->current--;
657  menu->redraw = REDRAW_INDEX;
658  }
659  else
660  mutt_message(_("You can't scroll up farther"));
661 }
#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 673 of file menu.c.

674 {
675  const int neg = (jumplen >= 0) ? 0 : -1;
676  const int c = MIN(C_MenuContext, menu->pagelen / 2);
677 
678  if (menu->max)
679  {
680  /* possible to scroll? */
681  int tmp;
682  if (DIRECTION * menu->top <
683  (tmp = (neg ? 0 : (menu->max /* -1 */) - (menu->pagelen /* -1 */))))
684  {
685  menu->top += jumplen;
686 
687  /* jumped too long? */
688  if ((neg || !C_MenuMoveOff) && (DIRECTION * menu->top > tmp))
689  menu->top = tmp;
690 
691  /* need to move the cursor? */
692  if ((DIRECTION *
693  (tmp = (menu->current - (menu->top + (neg ? (menu->pagelen - 1) - c : c))))) < 0)
694  {
695  menu->current -= tmp;
696  }
697 
698  menu->redraw = REDRAW_INDEX;
699  }
700  else if ((menu->current != (neg ? 0 : menu->max - 1)) && ARRAY_EMPTY(&menu->dialog))
701  {
702  menu->current += jumplen;
703  menu->redraw = REDRAW_MOTION;
704  }
705  else
706  {
707  mutt_message(neg ? _("You are on the first page") : _("You are on the last page"));
708  }
709 
710  menu->current = MIN(menu->current, menu->max - 1);
711  menu->current = MAX(menu->current, 0);
712  }
713  else
714  mutt_error(_("No entries"));
715 }
#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 721 of file menu.c.

722 {
723  menu_length_jump(menu, MAX(menu->pagelen /* - MenuOverlap */, 0));
724 }
#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 730 of file menu.c.

731 {
732  menu_length_jump(menu, 0 - MAX(menu->pagelen /* - MenuOverlap */, 0));
733 }
#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 739 of file menu.c.

740 {
741  menu_length_jump(menu, menu->pagelen / 2);
742 }
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 748 of file menu.c.

749 {
750  menu_length_jump(menu, 0 - menu->pagelen / 2);
751 }
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 757 of file menu.c.

758 {
759  if (menu->current == menu->top)
760  return;
761 
762  menu->current = menu->top;
763  menu->redraw = REDRAW_MOTION;
764 }
#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 770 of file menu.c.

771 {
772  if (menu->max)
773  {
774  menu->current = menu->top + menu->pagelen - 1;
775  if (menu->current > menu->max - 1)
776  menu->current = menu->max - 1;
777  menu->redraw = REDRAW_MOTION;
778  }
779  else
780  mutt_error(_("No entries"));
781 }
#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 787 of file menu.c.

788 {
789  if (menu->max)
790  {
791  int i = menu->top + menu->pagelen;
792  if (i > menu->max - 1)
793  i = menu->max - 1;
794  menu->current = menu->top + (i - menu->top) / 2;
795  menu->redraw = REDRAW_MOTION;
796  }
797  else
798  mutt_error(_("No entries"));
799 }
#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 805 of file menu.c.

806 {
807  if (menu->max)
808  {
809  menu->current = 0;
810  menu->redraw = REDRAW_MOTION;
811  }
812  else
813  mutt_error(_("No entries"));
814 }
#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 820 of file menu.c.

821 {
822  if (menu->max)
823  {
824  menu->current = menu->max - 1;
825  menu->redraw = REDRAW_MOTION;
826  }
827  else
828  mutt_error(_("No entries"));
829 }
#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 835 of file menu.c.

836 {
837  if (menu->max)
838  {
839  menu->top = menu->current;
840  menu->redraw = REDRAW_INDEX;
841  }
842  else
843  mutt_error(_("No entries"));
844 }
#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 850 of file menu.c.

851 {
852  if (menu->max)
853  {
854  menu->top = menu->current - menu->pagelen / 2;
855  if (menu->top < 0)
856  menu->top = 0;
857  menu->redraw = REDRAW_INDEX;
858  }
859  else
860  mutt_error(_("No entries"));
861 }
#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 867 of file menu.c.

868 {
869  if (menu->max)
870  {
871  menu->top = menu->current - menu->pagelen + 1;
872  if (menu->top < 0)
873  menu->top = 0;
874  menu->redraw = REDRAW_INDEX;
875  }
876  else
877  mutt_error(_("No entries"));
878 }
#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 884 of file menu.c.

885 {
886  if (menu->current < menu->max - 1)
887  {
888  menu->current++;
889  menu->redraw = REDRAW_MOTION;
890  }
891  else
892  mutt_message(_("You are on the last entry"));
893 }
#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 899 of file menu.c.

900 {
901  if (menu->current)
902  {
903  menu->current--;
904  menu->redraw = REDRAW_MOTION;
905  }
906  else
907  mutt_message(_("You are on the first entry"));
908 }
#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 913 of file menu.c.

914 {
915  return Colors->defs[MT_COLOR_NORMAL];
916 }
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 921 of file menu.c.

922 {
923  char buf[1024];
924 
925  make_entry(buf, sizeof(buf), menu, line);
926  return regexec(rx, buf, 0, NULL, 0);
927 }
+ 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 932 of file menu.c.

933 {
934  for (int i = 0; i < MENU_MAX; i++)
935  SearchBuffers[i] = NULL;
936 }
+ 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 943 of file menu.c.

944 {
945  struct Menu *menu = mutt_mem_calloc(1, sizeof(struct Menu));
946 
947  menu->type = type;
948  menu->current = 0;
949  menu->top = 0;
950  menu->redraw = REDRAW_FULL;
951  menu->color = default_color;
952  menu->search = generic_search;
953  menu->custom_search = false;
954 
955  return menu;
956 }
#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
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:75
bool custom_search
The menu implements its own non-Menusearch()-compatible search, trickle OP_SEARCH*.
Definition: mutt_menu.h:79
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:58
int current
Current entry.
Definition: mutt_menu.h:56
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 962 of file menu.c.

963 {
964  if (!ptr || !*ptr)
965  return;
966 
967  struct Menu *m = *ptr;
968  char **line = NULL;
969  ARRAY_FOREACH(line, &m->dialog)
970  {
971  FREE(line);
972  }
973  ARRAY_FREE(&m->dialog);
974 
975  FREE(ptr);
976 }
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 983 of file menu.c.

984 {
985  ARRAY_SET(&menu->dialog, menu->max, mutt_str_dup(row));
986  menu->max++;
987 }
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 993 of file menu.c.

994 {
995  struct Menu **mp = ARRAY_LAST(&MenuStack);
996  return mp ? *mp : NULL;
997 }
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 1005 of file menu.c.

1006 {
1007  ARRAY_ADD(&MenuStack, menu);
1008  CurrentMenu = menu->type;
1009 }
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 1017 of file menu.c.

1018 {
1019  struct Menu *prev_menu = NULL;
1020 
1021  if (ARRAY_EMPTY(&MenuStack) || (*ARRAY_LAST(&MenuStack) != menu))
1022  {
1023  mutt_debug(LL_DEBUG1, "called with inactive menu\n");
1024  return;
1025  }
1026  ARRAY_SHRINK(&MenuStack, 1);
1027 
1028  prev_menu = get_current_menu();
1029  if (prev_menu)
1030  {
1031  CurrentMenu = prev_menu->type;
1032  prev_menu->redraw = REDRAW_FULL;
1033  }
1034  else
1035  {
1037  /* Clearing when NeoMutt exits would be an annoying change in behavior for
1038  * those who have disabled alternative screens. The option is currently
1039  * set by autocrypt initialization which mixes menus and prompts outside of
1040  * the normal menu system state. */
1042  {
1044  }
1045  }
1046 }
#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 1052 of file menu.c.

1053 {
1054  struct Menu *current_menu = get_current_menu();
1055  if (current_menu)
1056  current_menu->redraw |= redraw;
1057 }
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 1062 of file menu.c.

1063 {
1064  struct Menu *current_menu = get_current_menu();
1065  if (current_menu)
1066  current_menu->redraw = REDRAW_FULL;
1067 }
#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 1076 of file menu.c.

1077 {
1078  if (CurrentMenu == menu)
1080 }
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 1088 of file menu.c.

1089 {
1090  if (CurrentMenu == menu)
1092 }
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 1097 of file menu.c.

1098 {
1099  struct Menu *current_menu = get_current_menu();
1100  if (current_menu)
1101  {
1102  if (menu_redraw(current_menu) == OP_REDRAW)
1103  {
1104  /* On a REDRAW_FULL with a non-customized redraw, menu_redraw()
1105  * will return OP_REDRAW to give the calling menu-loop a chance to
1106  * customize output. */
1107  menu_redraw(current_menu);
1108  }
1109  }
1110 }
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 1119 of file menu.c.

1120 {
1121  int rc = 0, wrap = 0;
1122  int search_dir;
1123  regex_t re;
1124  char buf[128];
1125  char *search_buf = ((menu->type < MENU_MAX)) ? SearchBuffers[menu->type] : NULL;
1126 
1127  if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
1128  {
1129  mutt_str_copy(buf, search_buf && (search_buf[0] != '\0') ? search_buf : "",
1130  sizeof(buf));
1131  if ((mutt_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
1132  _("Search for: ") :
1133  _("Reverse search for: "),
1134  buf, sizeof(buf), MUTT_CLEAR) != 0) ||
1135  (buf[0] == '\0'))
1136  {
1137  return -1;
1138  }
1139  if (menu->type < MENU_MAX)
1140  {
1141  mutt_str_replace(&SearchBuffers[menu->type], buf);
1142  search_buf = SearchBuffers[menu->type];
1143  }
1144  menu->search_dir =
1145  ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ? MUTT_SEARCH_DOWN : MUTT_SEARCH_UP;
1146  }
1147 
1148  search_dir = (menu->search_dir == MUTT_SEARCH_UP) ? -1 : 1;
1149  if (op == OP_SEARCH_OPPOSITE)
1150  search_dir = -search_dir;
1151 
1152  if (search_buf)
1153  {
1154  int flags = mutt_mb_is_lower(search_buf) ? REG_ICASE : 0;
1155  rc = REG_COMP(&re, search_buf, REG_NOSUB | flags);
1156  }
1157 
1158  if (rc != 0)
1159  {
1160  regerror(rc, &re, buf, sizeof(buf));
1161  mutt_error("%s", buf);
1162  return -1;
1163  }
1164 
1165  rc = menu->current + search_dir;
1166 search_next:
1167  if (wrap)
1168  mutt_message(_("Search wrapped to top"));
1169  while ((rc >= 0) && (rc < menu->max))
1170  {
1171  if (menu->search(menu, &re, rc) == 0)
1172  {
1173  regfree(&re);
1174  return rc;
1175  }
1176 
1177  rc += search_dir;
1178  }
1179 
1180  if (C_WrapSearch && (wrap++ == 0))
1181  {
1182  rc = (search_dir == 1) ? 0 : menu->max - 1;
1183  goto search_next;
1184  }
1185  regfree(&re);
1186  mutt_error(_("Not found"));
1187  return -1;
1188 }
#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:53
#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 1195 of file menu.c.

1196 {
1197  switch (i)
1198  {
1199  case OP_NEXT_ENTRY:
1200  return OP_NEXT_LINE;
1201  case OP_PREV_ENTRY:
1202  return OP_PREV_LINE;
1203  case OP_CURRENT_TOP:
1204  case OP_FIRST_ENTRY:
1205  return OP_TOP_PAGE;
1206  case OP_CURRENT_BOTTOM:
1207  case OP_LAST_ENTRY:
1208  return OP_BOTTOM_PAGE;
1209  case OP_CURRENT_MIDDLE:
1210  return OP_MIDDLE_PAGE;
1211  }
1212 
1213  return i;
1214 }
+ 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 1223 of file menu.c.

1224 {
1225  struct KeyEvent ch;
1226  char *p = NULL;
1227 
1228  do
1229  {
1230  ch = mutt_getch();
1231  } while (ch.ch == -2);
1232 
1233  if (ch.ch < 0)
1234  {
1235  *ip = -1;
1236  return 0;
1237  }
1238 
1239  if (ch.ch && (p = strchr(menu->keys, ch.ch)))
1240  {
1241  *ip = OP_MAX + (p - menu->keys + 1);
1242  return 0;
1243  }
1244  else
1245  {
1246  if (ch.op == OP_NULL)
1247  mutt_unget_event(ch.ch, 0);
1248  else
1249  mutt_unget_event(0, ch.op);
1250  return -1;
1251  }
1252 }
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 1260 of file menu.c.

1261 {
1262  if (menu->custom_redraw)
1263  {
1264  menu->custom_redraw(menu);
1265  return OP_NULL;
1266  }
1267 
1268  /* See if all or part of the screen needs to be updated. */
1269  if (menu->redraw & REDRAW_FULL)
1270  {
1271  menu_redraw_full(menu);
1272  /* allow the caller to do any local configuration */
1273  return OP_REDRAW;
1274  }
1275 
1276  if (ARRAY_EMPTY(&menu->dialog))
1277  menu_check_recenter(menu);
1278 
1279  if (menu->redraw & REDRAW_STATUS)
1280  menu_redraw_status(menu);
1281  if (menu->redraw & REDRAW_INDEX)
1282  menu_redraw_index(menu);
1283  else if (menu->redraw & (REDRAW_MOTION | REDRAW_MOTION_RESYNC))
1284  menu_redraw_motion(menu);
1285  else if (menu->redraw == REDRAW_CURRENT)
1286  menu_redraw_current(menu);
1287 
1288  if (!ARRAY_EMPTY(&menu->dialog))
1289  menu_redraw_prompt(menu);
1290 
1291  return OP_NULL;
1292 }
#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 1299 of file menu.c.

1300 {
1301  static int last_position = -1;
1302  int op = OP_NULL;
1303 
1304  if (menu->max && menu->is_mailbox_list)
1305  {
1306  if (last_position > (menu->max - 1))
1307  last_position = -1;
1308  else if (last_position >= 0)
1309  menu->current = last_position;
1310  }
1311 
1312  while (true)
1313  {
1314  /* Clear the tag prefix unless we just started it. Don't clear
1315  * the prefix on a timeout (op==-2), but do clear on an abort (op==-1) */
1316  if (menu->tagprefix && (op != OP_TAG_PREFIX) &&
1317  (op != OP_TAG_PREFIX_COND) && (op != -2))
1318  {
1319  menu->tagprefix = false;
1320  }
1321 
1323 
1324  if (menu_redraw(menu) == OP_REDRAW)
1325  return OP_REDRAW;
1326 
1327  /* give visual indication that the next command is a tag- command */
1328  if (menu->tagprefix)
1329  {
1330  mutt_window_mvaddstr(MessageWindow, 0, 0, "tag-");
1332  }
1333 
1334  menu->oldcurrent = menu->current;
1335 
1336  /* move the cursor out of the way */
1337  if (C_ArrowCursor)
1338  mutt_window_move(menu->win_index, 2, menu->current - menu->top);
1339  else if (C_BrailleFriendly)
1340  mutt_window_move(menu->win_index, 0, menu->current - menu->top);
1341  else
1342  {
1343  mutt_window_move(menu->win_index, menu->win_index->state.cols - 1,
1344  menu->current - menu->top);
1345  }
1346 
1347  mutt_refresh();
1348 
1349  /* try to catch dialog keys before ops */
1350  if (!ARRAY_EMPTY(&menu->dialog) && (menu_dialog_dokey(menu, &op) == 0))
1351  return op;
1352 
1353  op = km_dokey(menu->type);
1354  if ((op == OP_TAG_PREFIX) || (op == OP_TAG_PREFIX_COND))
1355  {
1356  if (menu->tagprefix)
1357  {
1358  menu->tagprefix = false;
1360  continue;
1361  }
1362 
1363  if (menu->tagged)
1364  {
1365  menu->tagprefix = true;
1366  continue;
1367  }
1368  else if (op == OP_TAG_PREFIX)
1369  {
1370  mutt_error(_("No tagged entries"));
1371  op = -1;
1372  }
1373  else /* None tagged, OP_TAG_PREFIX_COND */
1374  {
1376  mutt_message(_("Nothing to do"));
1377  op = -1;
1378  }
1379  }
1380  else if (menu->tagged && C_AutoTag)
1381  menu->tagprefix = true;
1382 
1384 
1385  if (SigWinch)
1386  {
1387  SigWinch = 0;
1389  clearok(stdscr, true); /* force complete redraw */
1390  }
1391 
1392  if (op < 0)
1393  {
1394  if (menu->tagprefix)
1396  continue;
1397  }
1398 
1399  if (ARRAY_EMPTY(&menu->dialog))
1400  mutt_clear_error();
1401 
1402  /* Convert menubar movement to scrolling */
1403  if (!ARRAY_EMPTY(&menu->dialog))
1404  op = menu_dialog_translate_op(op);
1405 
1406  switch (op)
1407  {
1408  case OP_NEXT_ENTRY:
1409  menu_next_entry(menu);
1410  break;
1411  case OP_PREV_ENTRY:
1412  menu_prev_entry(menu);
1413  break;
1414  case OP_HALF_DOWN:
1415  menu_half_down(menu);
1416  break;
1417  case OP_HALF_UP:
1418  menu_half_up(menu);
1419  break;
1420  case OP_NEXT_PAGE:
1421  menu_next_page(menu);
1422  break;
1423  case OP_PREV_PAGE:
1424  menu_prev_page(menu);
1425  break;
1426  case OP_NEXT_LINE:
1427  menu_next_line(menu);
1428  break;
1429  case OP_PREV_LINE:
1430  menu_prev_line(menu);
1431  break;
1432  case OP_FIRST_ENTRY:
1433  menu_first_entry(menu);
1434  break;
1435  case OP_LAST_ENTRY:
1436  menu_last_entry(menu);
1437  break;
1438  case OP_TOP_PAGE:
1439  menu_top_page(menu);
1440  break;
1441  case OP_MIDDLE_PAGE:
1442  menu_middle_page(menu);
1443  break;
1444  case OP_BOTTOM_PAGE:
1445  menu_bottom_page(menu);
1446  break;
1447  case OP_CURRENT_TOP:
1448  menu_current_top(menu);
1449  break;
1450  case OP_CURRENT_MIDDLE:
1451  menu_current_middle(menu);
1452  break;
1453  case OP_CURRENT_BOTTOM:
1454  menu_current_bottom(menu);
1455  break;
1456  case OP_SEARCH:
1457  case OP_SEARCH_REVERSE:
1458  case OP_SEARCH_NEXT:
1459  case OP_SEARCH_OPPOSITE:
1460  if (menu->custom_search)
1461  return op;
1462  else if (menu->search && ARRAY_EMPTY(&menu->dialog)) /* Searching dialogs won't work */
1463  {
1464  menu->oldcurrent = menu->current;
1465  menu->current = search(menu, op);
1466  if (menu->current != -1)
1467  menu->redraw = REDRAW_MOTION;
1468  else
1469  menu->current = menu->oldcurrent;
1470  }
1471  else
1472  mutt_error(_("Search is not implemented for this menu"));
1473  break;
1474 
1475  case OP_JUMP:
1476  if (!ARRAY_EMPTY(&menu->dialog))
1477  mutt_error(_("Jumping is not implemented for dialogs"));
1478  else
1479  menu_jump(menu);
1480  break;
1481 
1482  case OP_ENTER_COMMAND:
1484  window_set_focus(menu->win_index);
1485  window_redraw(RootWindow, false);
1486  break;
1487 
1488  case OP_TAG:
1489  if (menu->tag && ARRAY_EMPTY(&menu->dialog))
1490  {
1491  if (menu->tagprefix && !C_AutoTag)
1492  {
1493  for (int i = 0; i < menu->max; i++)
1494  menu->tagged += menu->tag(menu, i, 0);
1495  menu->redraw |= REDRAW_INDEX;
1496  }
1497  else if (menu->max)
1498  {
1499  int j = menu->tag(menu, menu->current, -1);
1500  menu->tagged += j;
1501  if (j && C_Resolve && (menu->current < menu->max - 1))
1502  {
1503  menu->current++;
1504  menu->redraw |= REDRAW_MOTION_RESYNC;
1505  }
1506  else
1507  menu->redraw |= REDRAW_CURRENT;
1508  }
1509  else
1510  mutt_error(_("No entries"));
1511  }
1512  else
1513  mutt_error(_("Tagging is not supported"));
1514  break;
1515 
1516  case OP_SHELL_ESCAPE:
1518  break;
1519 
1520  case OP_WHAT_KEY:
1521  mutt_what_key();
1522  break;
1523 
1524  case OP_CHECK_STATS:
1525  mutt_check_stats();
1526  break;
1527 
1528  case OP_REDRAW:
1529  clearok(stdscr, true);
1530  menu->redraw = REDRAW_FULL;
1531  break;
1532 
1533  case OP_HELP:
1534  mutt_help(menu->type, menu->win_index->state.cols);
1535  menu->redraw = REDRAW_FULL;
1536  break;
1537 
1538  case OP_NULL:
1539  km_error_key(menu->type);
1540  break;
1541 
1542  case OP_END_COND:
1543  break;
1544 
1545  default:
1546  if (menu->is_mailbox_list)
1547  last_position = menu->current;
1548  return op;
1549  }
1550  }
1551  /* not reached */
1552 }
int km_dokey(enum MenuType menu)
Determine what a keypress should do.
Definition: keymap.c:658
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:45
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
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:1428
void mutt_enter_command(void)
enter a neomutt command
Definition: commands.c:872
#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_shell_escape(void)
invoke a command in a subshell
Definition: commands.c:844
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 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
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 1557 of file menu.c.

1558 {
1559  if (!nc->event_data)
1560  return -1;
1561  if (nc->event_type != NT_CONFIG)
1562  return 0;
1563 
1564  struct EventColor *ev_c = nc->event_data;
1565 
1566  int c = ev_c->color;
1567 
1568  bool simple = (c == MT_COLOR_INDEX_COLLAPSED) || (c == MT_COLOR_INDEX_DATE) ||
1569  (c == MT_COLOR_INDEX_LABEL) || (c == MT_COLOR_INDEX_NUMBER) ||
1570  (c == MT_COLOR_INDEX_SIZE) || (c == MT_COLOR_INDEX_TAGS);
1571  bool lists = (c == MT_COLOR_ATTACH_HEADERS) || (c == MT_COLOR_BODY) ||
1572  (c == MT_COLOR_HEADER) || (c == MT_COLOR_INDEX) ||
1573  (c == MT_COLOR_INDEX_AUTHOR) || (c == MT_COLOR_INDEX_FLAGS) ||
1574  (c == MT_COLOR_INDEX_SUBJECT) || (c == MT_COLOR_INDEX_TAG);
1575 
1576  // The changes aren't relevant to the index menu
1577  if (!simple && !lists)
1578  return 0;
1579 
1580  // Colour deleted from a list
1581  if ((nc->event_subtype == NT_COLOR_RESET) && lists && Context && Context->mailbox)
1582  {
1583  struct Mailbox *m = Context->mailbox;
1584  // Force re-caching of index colors
1585  for (int i = 0; i < m->msg_count; i++)
1586  {
1587  struct Email *e = m->emails[i];
1588  if (!e)
1589  break;
1590  e->pair = 0;
1591  }
1592  }
1593 
1595  return 0;
1596 }
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
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
struct Mailbox * mailbox
Definition: context.h:50
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 1601 of file menu.c.

1602 {
1603  if (!nc->event_data)
1604  return -1;
1605  if (nc->event_type != NT_CONFIG)
1606  return 0;
1607 
1608  struct EventConfig *ec = nc->event_data;
1609 
1610  const struct ConfigDef *cdef = ec->he->data;
1611  ConfigRedrawFlags flags = cdef->type & R_REDRAW_MASK;
1612 
1613  if (flags == R_REDRAW_NO_FLAGS)
1614  return 0;
1615 
1616  if (flags & R_INDEX)
1618  if (flags & R_PAGER)
1620  if (flags & R_PAGER_FLOW)
1621  {
1624  }
1625 
1626  if (flags & R_RESORT_SUB)
1627  OptSortSubthreads = true;
1628  if (flags & R_RESORT)
1629  OptNeedResort = true;
1630  if (flags & R_RESORT_INIT)
1631  OptResortInit = true;
1632  if (flags & R_TREE)
1633  OptRedrawTree = true;
1634 
1635  if (flags & R_REFLOW)
1636  mutt_window_reflow(NULL);
1637  if (flags & R_MENU)
1639 
1640  return 0;
1641 }
#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
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
unsigned int type
Variable type, e.g. DT_STRING.
Definition: set.h:64
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 54 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 55 of file menu.c.

◆ C_MenuScroll

bool C_MenuScroll

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

Definition at line 56 of file menu.c.

◆ SearchBuffers

char* SearchBuffers[MENU_MAX]

Definition at line 58 of file menu.c.