NeoMutt  2019-11-11
Teaching an old dog new tricks
DOXYGEN
menu.c File Reference

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

#include "config.h"
#include <regex.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include "mutt/mutt.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "mutt.h"
#include "commands.h"
#include "context.h"
#include "curs_lib.h"
#include "globals.h"
#include "keymap.h"
#include "mutt_curses.h"
#include "mutt_logging.h"
#include "mutt_menu.h"
#include "mutt_window.h"
#include "muttlib.h"
#include "opcodes.h"
#include "options.h"
#include "pattern.h"
#include "protos.h"
#include "color.h"
#include "sidebar.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

static int get_color (int index, unsigned char *s)
 Choose a colour for a line of the index. More...
 
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 menu_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_sidebar (struct Menu *menu)
 Force the redraw of the sidebar. 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::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::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 menu_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]
 
static size_t MenuStackCount = 0
 
static size_t MenuStackLen = 0
 
static struct Menu ** MenuStack = NULL
 

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)

Definition at line 73 of file menu.c.

◆ MUTT_SEARCH_UP

#define MUTT_SEARCH_UP   1

Definition at line 75 of file menu.c.

◆ MUTT_SEARCH_DOWN

#define MUTT_SEARCH_DOWN   2

Definition at line 76 of file menu.c.

Function Documentation

◆ get_color()

static int get_color ( int  index,
unsigned char *  s 
)
static

Choose a colour for a line of the index.

Parameters
indexIndex number
sString of embedded colour codes
Return values
numColour pair in an integer

Text is coloured by inserting special characters into the string, e.g. MT_COLOR_INDEX_AUTHOR

Definition at line 87 of file menu.c.

88 {
89  struct ColorLineList *color = NULL;
90  struct ColorLine *np = NULL;
91  struct Email *e = Context->mailbox->emails[Context->mailbox->v2r[index]];
92  int type = *s;
93 
94  switch (type)
95  {
97  color = &Colors->index_author_list;
98  break;
100  color = &Colors->index_flags_list;
101  break;
103  color = &Colors->index_subject_list;
104  break;
105  case MT_COLOR_INDEX_TAG:
106  STAILQ_FOREACH(np, &Colors->index_tag_list, entries)
107  {
108  if (strncmp((const char *) (s + 1), np->pattern, strlen(np->pattern)) == 0)
109  return np->pair;
110  const char *transform = mutt_hash_find(TagTransforms, np->pattern);
111  if (transform &&
112  (strncmp((const char *) (s + 1), transform, strlen(transform)) == 0))
113  {
114  return np->pair;
115  }
116  }
117  return 0;
118  default:
119  return Colors->defs[type];
120  }
121 
122  STAILQ_FOREACH(np, color, entries)
123  {
126  return np->pair;
127  }
128 
129  return 0;
130 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:110
struct ColorLineList index_tag_list
List of colours applied to tags in the index.
Definition: color.h:141
The "current" mailbox.
Definition: context.h:36
The envelope/body of an email.
Definition: email.h:37
struct Hash * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:38
int * defs
Array of all fixed colours, see enum ColorId.
Definition: color.h:132
struct PatternList * color_pattern
Compiled pattern to speed up index color calculation.
Definition: color.h:41
struct ColorLineList index_flags_list
List of colours applied to the flags in the index.
Definition: color.h:138
void * mutt_hash_find(const struct Hash *table, const char *strkey)
Find the HashElem data in a Hash table element using a key.
Definition: hash.c:378
char * pattern
Pattern to match.
Definition: color.h:40
int pair
Colour pair index.
Definition: color.h:44
struct ColorLineList index_subject_list
List of colours applied to the subject in the index.
Definition: color.h:140
Index: author field (takes a pattern)
Definition: color.h:102
struct Mailbox * mailbox
Definition: context.h:50
Index: tag field (g, takes a pattern)
Definition: color.h:105
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: pattern.c:2001
#define SLIST_FIRST(head)
Definition: queue.h:229
struct ColorLineList index_author_list
List of colours applied to the author in the index.
Definition: color.h:137
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
Definition: color.h:130
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition: pattern.h:75
int * v2r
Mapping from virtual to real msgno.
Definition: mailbox.h:112
Index: subject field (takes a pattern)
Definition: color.h:104
int index
The absolute (unsorted) message number.
Definition: email.h:85
Index: flags field (takes a pattern)
Definition: color.h:103
A regular expression and a color to highlight a line.
Definition: color.h:36
+ Here is the call graph for this function:
+ Here is the caller 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 139 of file menu.c.

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

◆ menu_make_entry()

static void menu_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 323 of file menu.c.

324 {
325  if (menu->dialog)
326  {
327  mutt_str_strfcpy(buf, NONULL(menu->dialog[i]), buflen);
328  menu->current = -1; /* hide menubar */
329  }
330  else
331  menu->menu_make_entry(buf, buflen, menu, i);
332 }
#define NONULL(x)
Definition: string2.h:37
char ** dialog
Dialog lines themselves.
Definition: mutt_menu.h:102
void(* menu_make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: mutt_menu.h:120
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 342 of file menu.c.

343 {
344  char *scratch = mutt_str_strdup(buf);
345  int shift = C_ArrowCursor ? 3 : 0;
346  int cols = menu->indexwin->cols - shift;
347 
348  mutt_simple_format(buf, buflen, cols, cols, JUSTIFY_LEFT, ' ', scratch,
349  mutt_str_strlen(scratch), true);
350  buf[buflen - 1] = '\0';
351  FREE(&scratch);
352 }
Left justify the text.
Definition: curs_lib.h:47
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
#define FREE(x)
Definition: memory.h:40
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:1021
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: globals.h:198
+ 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 358 of file menu.c.

359 {
362 
363  if (C_Help)
364  {
369  }
370  menu->offset = 0;
371  menu->pagelen = menu->indexwin->rows;
372 
373  mutt_show_error();
374 
376 #ifdef USE_SIDEBAR
377  menu->redraw |= REDRAW_SIDEBAR;
378 #endif
379 }
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:49
WHERE bool C_Help
Config: Display a help line with common key bindings.
Definition: globals.h:225
struct MuttWindow * MuttHelpWindow
Help Window.
Definition: mutt_window.c:39
#define REDRAW_SIDEBAR
Redraw the sidebar.
Definition: mutt_menu.h:51
void mutt_paddstr(int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:1194
void mutt_window_clear_screen(void)
Clear the entire screen.
Definition: mutt_window.c:437
Plain text.
Definition: color.h:78
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:46
Status bar (takes a pattern)
Definition: color.h:95
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:198
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
int offset
Row offset within the window to start the index.
Definition: mutt_menu.h:91
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:42
void mutt_show_error(void)
Show the user an error message.
Definition: curs_lib.c:530
char * help
Quickref for the current menu.
Definition: mutt_menu.h:85
+ 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 385 of file menu.c.

386 {
387  char buf[256];
388 
389  snprintf(buf, sizeof(buf), "-- NeoMutt: %s", menu->title);
391  mutt_window_move(menu->statuswin, 0, 0);
392  mutt_paddstr(menu->statuswin->cols, buf);
394  menu->redraw &= ~REDRAW_STATUS;
395 }
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:49
void mutt_paddstr(int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:1194
Plain text.
Definition: color.h:78
struct MuttWindow * statuswin
Definition: mutt_menu.h:96
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:46
Status bar (takes a pattern)
Definition: color.h:95
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:198
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
char * title
Title of this menu.
Definition: mutt_menu.h:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_sidebar()

void menu_redraw_sidebar ( struct Menu menu)

Force the redraw of the sidebar.

Parameters
menuCurrent Menu

Definition at line 402 of file menu.c.

403 {
404  menu->redraw &= ~REDRAW_SIDEBAR;
405  mutt_sb_draw();
406 }
#define REDRAW_SIDEBAR
Redraw the sidebar.
Definition: mutt_menu.h:51
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
+ 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 413 of file menu.c.

414 {
415  char buf[1024];
416  bool do_color;
417  int attr;
418 
419  for (int i = menu->top; i < menu->top + menu->pagelen; i++)
420  {
421  if (i < menu->max)
422  {
423  attr = menu->menu_color(i);
424 
425  menu_make_entry(buf, sizeof(buf), menu, i);
426  menu_pad_string(menu, buf, sizeof(buf));
427 
428  mutt_curses_set_attr(attr);
429  mutt_window_move(menu->indexwin, i - menu->top + menu->offset, 0);
430  do_color = true;
431 
432  if (i == menu->current)
433  {
435  if (C_ArrowCursor)
436  {
437  mutt_window_addstr("->");
438  mutt_curses_set_attr(attr);
439  mutt_window_addch(' ');
440  }
441  else
442  do_color = false;
443  }
444  else if (C_ArrowCursor)
445  mutt_window_addstr(" ");
446 
447  print_enriched_string(i, attr, (unsigned char *) buf, do_color);
448  }
449  else
450  {
452  mutt_window_clearline(menu->indexwin, i - menu->top + menu->offset);
453  }
454  }
456  menu->redraw = 0;
457 }
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:49
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:95
Plain text.
Definition: color.h:78
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:108
Selected item in list.
Definition: color.h:74
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:198
int(* menu_color)(int line)
Calculate the colour for a line of the menu.
Definition: mutt_menu.h:144
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
int mutt_window_addch(int ch)
Write one character to a Window.
Definition: mutt_window.c:366
int offset
Row offset within the window to start the index.
Definition: mutt_menu.h:91
int mutt_window_addstr(const char *str)
Write a string to a Window.
Definition: mutt_window.c:396
int current
Current entry.
Definition: mutt_menu.h:87
void mutt_curses_set_attr(int attr)
Set the attributes for text.
Definition: mutt_curses.c:34
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: globals.h:198
+ 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 463 of file menu.c.

464 {
465  char buf[1024];
466 
467  if (menu->dialog)
468  {
469  menu->redraw &= ~REDRAW_MOTION;
470  return;
471  }
472 
473  /* Note: menu->color() for the index can end up retrieving a message
474  * over imap (if matching against ~h for instance). This can
475  * generate status messages. So we want to call it *before* we
476  * position the cursor for drawing. */
477  const int old_color = menu->menu_color(menu->oldcurrent);
478  mutt_window_move(menu->indexwin, menu->oldcurrent + menu->offset - menu->top, 0);
479  mutt_curses_set_attr(old_color);
480 
481  if (C_ArrowCursor)
482  {
483  /* clear the pointer */
484  mutt_window_addstr(" ");
485 
486  if (menu->redraw & REDRAW_MOTION_RESYNC)
487  {
488  menu_make_entry(buf, sizeof(buf), menu, menu->oldcurrent);
489  menu_pad_string(menu, buf, sizeof(buf));
490  mutt_window_move(menu->indexwin, menu->oldcurrent + menu->offset - menu->top, 3);
491  print_enriched_string(menu->oldcurrent, old_color, (unsigned char *) buf, true);
492  }
493 
494  /* now draw it in the new location */
496  mutt_window_mvaddstr(menu->indexwin, menu->current + menu->offset - menu->top, 0, "->");
497  }
498  else
499  {
500  /* erase the current indicator */
501  menu_make_entry(buf, sizeof(buf), menu, menu->oldcurrent);
502  menu_pad_string(menu, buf, sizeof(buf));
503  print_enriched_string(menu->oldcurrent, old_color, (unsigned char *) buf, true);
504 
505  /* now draw the new one to reflect the change */
506  const int cur_color = menu->menu_color(menu->current);
507  menu_make_entry(buf, sizeof(buf), menu, menu->current);
508  menu_pad_string(menu, buf, sizeof(buf));
510  mutt_window_move(menu->indexwin, menu->current + menu->offset - menu->top, 0);
511  print_enriched_string(menu->current, cur_color, (unsigned char *) buf, false);
512  }
513  menu->redraw &= REDRAW_STATUS;
515 }
int oldcurrent
For driver use only.
Definition: mutt_menu.h:109
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:49
char ** dialog
Dialog lines themselves.
Definition: mutt_menu.h:102
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:43
Plain text.
Definition: color.h:78
#define REDRAW_MOTION_RESYNC
Redraw any changing the menu selection.
Definition: mutt_menu.h:44
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:46
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:108
Selected item in list.
Definition: color.h:74
int mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:212
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:198
int(* menu_color)(int line)
Calculate the colour for a line of the menu.
Definition: mutt_menu.h:144
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
int offset
Row offset within the window to start the index.
Definition: mutt_menu.h:91
int mutt_window_addstr(const char *str)
Write a string to a Window.
Definition: mutt_window.c:396
int current
Current entry.
Definition: mutt_menu.h:87
void mutt_curses_set_attr(int attr)
Set the attributes for text.
Definition: mutt_curses.c:34
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: globals.h:198
+ 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 521 of file menu.c.

522 {
523  char buf[1024];
524  int attr = menu->menu_color(menu->current);
525 
526  mutt_window_move(menu->indexwin, menu->current + menu->offset - menu->top, 0);
527  menu_make_entry(buf, sizeof(buf), menu, menu->current);
528  menu_pad_string(menu, buf, sizeof(buf));
529 
531  if (C_ArrowCursor)
532  {
533  mutt_window_addstr("->");
534  mutt_curses_set_attr(attr);
535  mutt_window_addch(' ');
536  menu_pad_string(menu, buf, sizeof(buf));
537  print_enriched_string(menu->current, attr, (unsigned char *) buf, true);
538  }
539  else
540  print_enriched_string(menu->current, attr, (unsigned char *) buf, false);
541  menu->redraw &= REDRAW_STATUS;
543 }
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:49
Plain text.
Definition: color.h:78
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:46
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:108
Selected item in list.
Definition: color.h:74
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:198
int(* menu_color)(int line)
Calculate the colour for a line of the menu.
Definition: mutt_menu.h:144
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
int mutt_window_addch(int ch)
Write one character to a Window.
Definition: mutt_window.c:366
int offset
Row offset within the window to start the index.
Definition: mutt_menu.h:91
int mutt_window_addstr(const char *str)
Write a string to a Window.
Definition: mutt_window.c:396
int current
Current entry.
Definition: mutt_menu.h:87
void mutt_curses_set_attr(int attr)
Set the attributes for text.
Definition: mutt_curses.c:34
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: globals.h:198
+ 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 549 of file menu.c.

550 {
551  if (!menu || !menu->dialog)
552  return;
553 
554  if (OptMsgErr)
555  {
556  mutt_sleep(1);
557  OptMsgErr = false;
558  }
559 
560  if (ErrorBufMessage)
562 
565 }
char * prompt
Prompt for user, similar to mutt_multi_choice.
Definition: mutt_menu.h:104
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:117
char ** dialog
Dialog lines themselves.
Definition: mutt_menu.h:102
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1546
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:115
WHERE bool ErrorBufMessage
true if the last message was an error
Definition: globals.h:46
int mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:212
WHERE bool OptMsgErr
(pseudo) used by mutt_error/mutt_message
Definition: options.h:39
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42
+ 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 571 of file menu.c.

572 {
573  int c = MIN(C_MenuContext, menu->pagelen / 2);
574  int old_top = menu->top;
575 
576  if (!C_MenuMoveOff && (menu->max <= menu->pagelen)) /* less entries than lines */
577  {
578  if (menu->top != 0)
579  {
580  menu->top = 0;
581  menu->redraw |= REDRAW_INDEX;
582  }
583  }
584  else
585  {
586  if (C_MenuScroll || (menu->pagelen <= 0) || (c < C_MenuContext))
587  {
588  if (menu->current < menu->top + c)
589  menu->top = menu->current - c;
590  else if (menu->current >= menu->top + menu->pagelen - c)
591  menu->top = menu->current - menu->pagelen + c + 1;
592  }
593  else
594  {
595  if (menu->current < menu->top + c)
596  {
597  menu->top -= (menu->pagelen - c) * ((menu->top + menu->pagelen - 1 - menu->current) /
598  (menu->pagelen - c)) -
599  c;
600  }
601  else if ((menu->current >= menu->top + menu->pagelen - c))
602  {
603  menu->top +=
604  (menu->pagelen - c) * ((menu->current - menu->top) / (menu->pagelen - c)) - c;
605  }
606  }
607  }
608 
609  if (!C_MenuMoveOff) /* make entries stick to bottom */
610  menu->top = MIN(menu->top, menu->max - menu->pagelen);
611  menu->top = MAX(menu->top, 0);
612 
613  if (menu->top != old_top)
614  menu->redraw |= REDRAW_INDEX;
615 }
#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:108
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:42
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 623 of file menu.c.

624 {
625  int n;
626 
627  if (menu->max)
628  {
630  char buf[128];
631  buf[0] = '\0';
632  if ((mutt_get_field(_("Jump to: "), buf, sizeof(buf), 0) == 0) && buf[0])
633  {
634  if ((mutt_str_atoi(buf, &n) == 0) && (n > 0) && (n < menu->max + 1))
635  {
636  n--; /* msg numbers are 0-based */
637  menu->current = n;
638  menu->redraw = REDRAW_MOTION;
639  }
640  else
641  mutt_error(_("Invalid index number"));
642  }
643  }
644  else
645  mutt_error(_("No entries"));
646 }
int mutt_str_atoi(const char *str, int *dst)
Convert ASCII string to an integer.
Definition: string.c:262
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:763
#define _(a)
Definition: message.h:28
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:91
int LastKey
contains the last key the user pressed
Definition: keymap.c:147
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:43
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 652 of file menu.c.

653 {
654  if (menu->max)
655  {
656  int c = MIN(C_MenuContext, menu->pagelen / 2);
657 
658  if ((menu->top + 1 < menu->max - c) &&
659  (C_MenuMoveOff ||
660  ((menu->max > menu->pagelen) && (menu->top < menu->max - menu->pagelen))))
661  {
662  menu->top++;
663  if ((menu->current < menu->top + c) && (menu->current < menu->max - 1))
664  menu->current++;
665  menu->redraw = REDRAW_INDEX;
666  }
667  else
668  mutt_message(_("You can't scroll down farther"));
669  }
670  else
671  mutt_error(_("No entries"));
672 }
#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:108
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:42
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 678 of file menu.c.

679 {
680  if (menu->top > 0)
681  {
682  int c = MIN(C_MenuContext, menu->pagelen / 2);
683 
684  menu->top--;
685  if ((menu->current >= menu->top + menu->pagelen - c) && (menu->current > 1))
686  menu->current--;
687  menu->redraw = REDRAW_INDEX;
688  }
689  else
690  mutt_message(_("You can't scroll up farther"));
691 }
#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:108
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:42
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 703 of file menu.c.

704 {
705  const int neg = (jumplen >= 0) ? 0 : -1;
706  const int c = MIN(C_MenuContext, menu->pagelen / 2);
707 
708  if (menu->max)
709  {
710  /* possible to scroll? */
711  int tmp;
712  if (DIRECTION * menu->top <
713  (tmp = (neg ? 0 : (menu->max /* -1 */) - (menu->pagelen /* -1 */))))
714  {
715  menu->top += jumplen;
716 
717  /* jumped too long? */
718  if ((neg || !C_MenuMoveOff) && (DIRECTION * menu->top > tmp))
719  menu->top = tmp;
720 
721  /* need to move the cursor? */
722  if ((DIRECTION *
723  (tmp = (menu->current - (menu->top + (neg ? (menu->pagelen - 1) - c : c))))) < 0)
724  {
725  menu->current -= tmp;
726  }
727 
728  menu->redraw = REDRAW_INDEX;
729  }
730  else if ((menu->current != (neg ? 0 : menu->max - 1)) && !menu->dialog)
731  {
732  menu->current += jumplen;
733  menu->redraw = REDRAW_MOTION;
734  }
735  else
736  {
737  mutt_message(neg ? _("You are on the first page") : _("You are on the last page"));
738  }
739 
740  menu->current = MIN(menu->current, menu->max - 1);
741  menu->current = MAX(menu->current, 0);
742  }
743  else
744  mutt_error(_("No entries"));
745 }
#define MIN(a, b)
Definition: memory.h:31
#define mutt_message(...)
Definition: logging.h:83
char ** dialog
Dialog lines themselves.
Definition: mutt_menu.h:102
#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:43
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:108
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:42
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 751 of file menu.c.

752 {
753  menu_length_jump(menu, MAX(menu->pagelen /* - MenuOverlap */, 0));
754 }
#define MAX(a, b)
Definition: memory.h:30
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
+ 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 760 of file menu.c.

761 {
762  menu_length_jump(menu, 0 - MAX(menu->pagelen /* - MenuOverlap */, 0));
763 }
#define MAX(a, b)
Definition: memory.h:30
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
+ 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 769 of file menu.c.

770 {
771  menu_length_jump(menu, menu->pagelen / 2);
772 }
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
+ 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 778 of file menu.c.

779 {
780  menu_length_jump(menu, 0 - menu->pagelen / 2);
781 }
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
+ 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 787 of file menu.c.

788 {
789  if (menu->current == menu->top)
790  return;
791 
792  menu->current = menu->top;
793  menu->redraw = REDRAW_MOTION;
794 }
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:43
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:108
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 800 of file menu.c.

801 {
802  if (menu->max)
803  {
804  menu->current = menu->top + menu->pagelen - 1;
805  if (menu->current > menu->max - 1)
806  menu->current = menu->max - 1;
807  menu->redraw = REDRAW_MOTION;
808  }
809  else
810  mutt_error(_("No entries"));
811 }
#define _(a)
Definition: message.h:28
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:43
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:108
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 817 of file menu.c.

818 {
819  if (menu->max)
820  {
821  int i = menu->top + menu->pagelen;
822  if (i > menu->max - 1)
823  i = menu->max - 1;
824  menu->current = menu->top + (i - menu->top) / 2;
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:43
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:108
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 835 of file menu.c.

836 {
837  if (menu->max)
838  {
839  menu->current = 0;
840  menu->redraw = REDRAW_MOTION;
841  }
842  else
843  mutt_error(_("No entries"));
844 }
#define _(a)
Definition: message.h:28
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:43
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 850 of file menu.c.

851 {
852  if (menu->max)
853  {
854  menu->current = menu->max - 1;
855  menu->redraw = REDRAW_MOTION;
856  }
857  else
858  mutt_error(_("No entries"));
859 }
#define _(a)
Definition: message.h:28
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:43
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 865 of file menu.c.

866 {
867  if (menu->max)
868  {
869  menu->top = menu->current;
870  menu->redraw = REDRAW_INDEX;
871  }
872  else
873  mutt_error(_("No entries"));
874 }
#define _(a)
Definition: message.h:28
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:108
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:42
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 880 of file menu.c.

881 {
882  if (menu->max)
883  {
884  menu->top = menu->current - menu->pagelen / 2;
885  if (menu->top < 0)
886  menu->top = 0;
887  menu->redraw = REDRAW_INDEX;
888  }
889  else
890  mutt_error(_("No entries"));
891 }
#define _(a)
Definition: message.h:28
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:108
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:42
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 897 of file menu.c.

898 {
899  if (menu->max)
900  {
901  menu->top = menu->current - menu->pagelen + 1;
902  if (menu->top < 0)
903  menu->top = 0;
904  menu->redraw = REDRAW_INDEX;
905  }
906  else
907  mutt_error(_("No entries"));
908 }
#define _(a)
Definition: message.h:28
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:108
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:42
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 914 of file menu.c.

915 {
916  if (menu->current < menu->max - 1)
917  {
918  menu->current++;
919  menu->redraw = REDRAW_MOTION;
920  }
921  else
922  mutt_message(_("You are on the last entry"));
923 }
#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:43
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
int current
Current entry.
Definition: mutt_menu.h:87
+ 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 929 of file menu.c.

930 {
931  if (menu->current)
932  {
933  menu->current--;
934  menu->redraw = REDRAW_MOTION;
935  }
936  else
937  mutt_message(_("You are on the first entry"));
938 }
#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:43
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
int current
Current entry.
Definition: mutt_menu.h:87
+ 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::menu_color()

Definition at line 943 of file menu.c.

944 {
945  return Colors->defs[MT_COLOR_NORMAL];
946 }
int * defs
Array of all fixed colours, see enum ColorId.
Definition: color.h:132
Plain text.
Definition: color.h:78
Definition: color.h:130
+ 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::menu_search()

Definition at line 951 of file menu.c.

952 {
953  char buf[1024];
954 
955  menu_make_entry(buf, sizeof(buf), menu, line);
956  return regexec(rx, buf, 0, NULL, 0);
957 }
const char * line
Definition: common.c:36
+ 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 962 of file menu.c.

963 {
964  for (int i = 0; i < MENU_MAX; i++)
965  SearchBuffers[i] = NULL;
966 }
+ 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 973 of file menu.c.

974 {
975  struct Menu *menu = mutt_mem_calloc(1, sizeof(struct Menu));
976 
977  if (type >= MENU_MAX)
978  type = MENU_GENERIC;
979 
980  menu->type = type;
981  menu->current = 0;
982  menu->top = 0;
983  menu->offset = 0;
984  menu->redraw = REDRAW_FULL;
985  menu->pagelen = MuttIndexWindow->rows;
986  menu->indexwin = MuttIndexWindow;
987  menu->statuswin = MuttStatusWindow;
988  menu->menu_color = default_color;
989  menu->menu_search = generic_search;
990 
991  return menu;
992 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:47
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct MuttWindow * MuttStatusWindow
Status Window.
Definition: mutt_window.c:41
GUI selectable list of items.
Definition: mutt_menu.h:82
enum MenuType type
Menu definition for keymap entries.
Definition: mutt_menu.h:90
struct MuttWindow * statuswin
Definition: mutt_menu.h:96
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:40
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:108
int pagelen
Number of entries per screen.
Definition: mutt_menu.h:92
int(* menu_color)(int line)
Calculate the colour for a line of the menu.
Definition: mutt_menu.h:144
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
int(* menu_search)(struct Menu *menu, regex_t *rx, int line)
Search a menu for a item matching a regex.
Definition: mutt_menu.h:129
int offset
Row offset within the window to start the index.
Definition: mutt_menu.h:91
int current
Current entry.
Definition: mutt_menu.h:87
Generic selection list.
Definition: keymap.h:76
+ 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 998 of file menu.c.

999 {
1000  if (!ptr || !*ptr)
1001  return;
1002 
1003  struct Menu *m = *ptr;
1004  if (m->dialog)
1005  {
1006  for (int i = 0; i < m->max; i++)
1007  FREE(&m->dialog[i]);
1008 
1009  FREE(&m->dialog);
1010  }
1011 
1012  FREE(ptr);
1013 }
GUI selectable list of items.
Definition: mutt_menu.h:82
char ** dialog
Dialog lines themselves.
Definition: mutt_menu.h:102
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
#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 1020 of file menu.c.

1021 {
1022  if (menu->dsize <= menu->max)
1023  {
1024  menu->dsize += 10;
1025  mutt_mem_realloc(&menu->dialog, menu->dsize * sizeof(char *));
1026  }
1027  menu->dialog[menu->max++] = mutt_str_strdup(row);
1028 }
char ** dialog
Dialog lines themselves.
Definition: mutt_menu.h:102
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
int dsize
Number of allocated dialog lines.
Definition: mutt_menu.h:103
+ 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 1034 of file menu.c.

1035 {
1036  return MenuStackCount ? MenuStack[MenuStackCount - 1] : NULL;
1037 }
+ 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 1045 of file menu.c.

1046 {
1048  {
1049  MenuStackLen += 5;
1050  mutt_mem_realloc(&MenuStack, MenuStackLen * sizeof(struct Menu *));
1051  }
1052 
1053  MenuStack[MenuStackCount++] = menu;
1054  CurrentMenu = menu->type;
1055 }
GUI selectable list of items.
Definition: mutt_menu.h:82
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:84
enum MenuType type
Menu definition for keymap entries.
Definition: mutt_menu.h:90
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
+ Here is the call graph for this function:
+ 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 1063 of file menu.c.

1064 {
1065  struct Menu *prev_menu = NULL;
1066 
1067  if (!MenuStackCount || (MenuStack[MenuStackCount - 1] != menu))
1068  {
1069  mutt_debug(LL_DEBUG1, "called with inactive menu\n");
1070  return;
1071  }
1072 
1073  MenuStackCount--;
1074  prev_menu = get_current_menu();
1075  if (prev_menu)
1076  {
1077  CurrentMenu = prev_menu->type;
1078  prev_menu->redraw = REDRAW_FULL;
1079  }
1080  else
1081  {
1084  }
1085 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:47
GUI selectable list of items.
Definition: mutt_menu.h:82
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:84
Index panel (list of emails)
Definition: keymap.h:77
void mutt_window_clear_screen(void)
Clear the entire screen.
Definition: mutt_window.c:437
enum MenuType type
Menu definition for keymap entries.
Definition: mutt_menu.h:90
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
Log at debug level 1.
Definition: logging.h:56
#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 1091 of file menu.c.

1092 {
1093  struct Menu *current_menu = get_current_menu();
1094  if (current_menu)
1095  current_menu->redraw |= redraw;
1096 }
GUI selectable list of items.
Definition: mutt_menu.h:82
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
+ 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 1101 of file menu.c.

1102 {
1103  struct Menu *current_menu = get_current_menu();
1104  if (current_menu)
1105  current_menu->redraw = REDRAW_FULL;
1106 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:47
GUI selectable list of items.
Definition: mutt_menu.h:82
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
+ 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 1115 of file menu.c.

1116 {
1117  if (CurrentMenu == menu)
1119 }
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:84
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
+ 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 1127 of file menu.c.

1128 {
1129  if (CurrentMenu == menu)
1131 }
WHERE enum MenuType CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:84
+ 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 1136 of file menu.c.

1137 {
1138  struct Menu *current_menu = get_current_menu();
1139  if (current_menu)
1140  {
1141  if (menu_redraw(current_menu) == OP_REDRAW)
1142  {
1143  /* On a REDRAW_FULL with a non-customized redraw, menu_redraw()
1144  * will return OP_REDRAW to give the calling menu-loop a chance to
1145  * customize output. */
1146  menu_redraw(current_menu);
1147  }
1148  }
1149 }
GUI selectable list of items.
Definition: mutt_menu.h:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_search()

static int menu_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 1158 of file menu.c.

1159 {
1160  int rc = 0, wrap = 0;
1161  int search_dir;
1162  regex_t re;
1163  char buf[128];
1164  char *search_buf = ((menu->type < MENU_MAX)) ? SearchBuffers[menu->type] : NULL;
1165 
1166  if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
1167  {
1168  mutt_str_strfcpy(buf, search_buf && (search_buf[0] != '\0') ? search_buf : "",
1169  sizeof(buf));
1170  if ((mutt_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
1171  _("Search for: ") :
1172  _("Reverse search for: "),
1173  buf, sizeof(buf), MUTT_CLEAR) != 0) ||
1174  !buf[0])
1175  {
1176  return -1;
1177  }
1178  if (menu->type < MENU_MAX)
1179  {
1180  mutt_str_replace(&SearchBuffers[menu->type], buf);
1181  search_buf = SearchBuffers[menu->type];
1182  }
1183  menu->search_dir =
1184  ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ? MUTT_SEARCH_DOWN : MUTT_SEARCH_UP;
1185  }
1186 
1187  search_dir = (menu->search_dir == MUTT_SEARCH_UP) ? -1 : 1;
1188  if (op == OP_SEARCH_OPPOSITE)
1189  search_dir = -search_dir;
1190 
1191  if (search_buf)
1192  {
1193  int flags = mutt_mb_is_lower(search_buf) ? REG_ICASE : 0;
1194  rc = REG_COMP(&re, search_buf, REG_NOSUB | flags);
1195  }
1196 
1197  if (rc != 0)
1198  {
1199  regerror(rc, &re, buf, sizeof(buf));
1200  mutt_error("%s", buf);
1201  return -1;
1202  }
1203 
1204  rc = menu->current + search_dir;
1205 search_next:
1206  if (wrap)
1207  mutt_message(_("Search wrapped to top"));
1208  while ((rc >= 0) && (rc < menu->max))
1209  {
1210  if (menu->menu_search(menu, &re, rc) == 0)
1211  {
1212  regfree(&re);
1213  return rc;
1214  }
1215 
1216  rc += search_dir;
1217  }
1218 
1219  if (C_WrapSearch && (wrap++ == 0))
1220  {
1221  rc = (search_dir == 1) ? 0 : menu->max - 1;
1222  goto search_next;
1223  }
1224  regfree(&re);
1225  mutt_error(_("Not found"));
1226  return -1;
1227 }
#define MUTT_CLEAR
Clear input if printable character is pressed.
Definition: mutt.h:68
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
WHERE bool C_WrapSearch
Config: Wrap around when the search hits the end.
Definition: globals.h:270
#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:90
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition: regex3.h:52
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
int search_dir
Direction of search.
Definition: mutt_menu.h:110
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:453
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
int(* menu_search)(struct Menu *menu, regex_t *rx, int line)
Search a menu for a item matching a regex.
Definition: mutt_menu.h:129
#define mutt_error(...)
Definition: logging.h:84
int current
Current entry.
Definition: mutt_menu.h:87
bool mutt_mb_is_lower(const char *s)
Does a multi-byte string contain only lowercase characters?
Definition: mbyte.c:358
+ 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 1234 of file menu.c.

1235 {
1236  switch (i)
1237  {
1238  case OP_NEXT_ENTRY:
1239  return OP_NEXT_LINE;
1240  case OP_PREV_ENTRY:
1241  return OP_PREV_LINE;
1242  case OP_CURRENT_TOP:
1243  case OP_FIRST_ENTRY:
1244  return OP_TOP_PAGE;
1245  case OP_CURRENT_BOTTOM:
1246  case OP_LAST_ENTRY:
1247  return OP_BOTTOM_PAGE;
1248  case OP_CURRENT_MIDDLE:
1249  return OP_MIDDLE_PAGE;
1250  }
1251 
1252  return i;
1253 }
+ 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 1262 of file menu.c.

1263 {
1264  struct KeyEvent ch;
1265  char *p = NULL;
1266 
1267  do
1268  {
1269  ch = mutt_getch();
1270  } while (ch.ch == -2);
1271 
1272  if (ch.ch < 0)
1273  {
1274  *ip = -1;
1275  return 0;
1276  }
1277 
1278  if (ch.ch && (p = strchr(menu->keys, ch.ch)))
1279  {
1280  *ip = OP_MAX + (p - menu->keys + 1);
1281  return 0;
1282  }
1283  else
1284  {
1285  if (ch.op == OP_NULL)
1286  mutt_unget_event(ch.ch, 0);
1287  else
1288  mutt_unget_event(0, ch.op);
1289  return -1;
1290  }
1291 }
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:763
int ch
raw key pressed
Definition: keymap.h:62
An event such as a keypress.
Definition: keymap.h:60
struct KeyEvent mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:186
char * keys
Keys used in the prompt.
Definition: mutt_menu.h:105
+ 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 1299 of file menu.c.

1300 {
1301  if (menu->menu_custom_redraw)
1302  {
1303  menu->menu_custom_redraw(menu);
1304  return OP_NULL;
1305  }
1306 
1307  /* See if all or part of the screen needs to be updated. */
1308  if (menu->redraw & REDRAW_FULL)
1309  {
1310  menu_redraw_full(menu);
1311  /* allow the caller to do any local configuration */
1312  return OP_REDRAW;
1313  }
1314 
1315  if (!menu->dialog)
1316  menu_check_recenter(menu);
1317 
1318  if (menu->redraw & REDRAW_STATUS)
1319  menu_redraw_status(menu);
1320 #ifdef USE_SIDEBAR
1321  if (menu->redraw & REDRAW_SIDEBAR)
1322  menu_redraw_sidebar(menu);
1323 #endif
1324  if (menu->redraw & REDRAW_INDEX)
1325  menu_redraw_index(menu);
1326  else if (menu->redraw & (REDRAW_MOTION | REDRAW_MOTION_RESYNC))
1327  menu_redraw_motion(menu);
1328  else if (menu->redraw == REDRAW_CURRENT)
1329  menu_redraw_current(menu);
1330 
1331  if (menu->dialog)
1332  menu_redraw_prompt(menu);
1333 
1334  return OP_NULL;
1335 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:47
char ** dialog
Dialog lines themselves.
Definition: mutt_menu.h:102
#define REDRAW_SIDEBAR
Redraw the sidebar.
Definition: mutt_menu.h:51
void(* menu_custom_redraw)(struct Menu *menu)
Redraw the menu.
Definition: mutt_menu.h:149
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:43
#define REDRAW_MOTION_RESYNC
Redraw any changing the menu selection.
Definition: mutt_menu.h:44
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:46
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:42
#define REDRAW_CURRENT
Redraw the current line of the menu.
Definition: mutt_menu.h:45
+ 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 1342 of file menu.c.

1343 {
1344  static int last_position = -1;
1345  int i = OP_NULL;
1346 
1347  if (menu->max && menu->is_mailbox_list)
1348  {
1349  if (last_position > (menu->max - 1))
1350  last_position = -1;
1351  else if (last_position >= 0)
1352  menu->current = last_position;
1353  }
1354 
1355  while (true)
1356  {
1357  if (OptMenuCaller)
1358  {
1359  OptMenuCaller = false;
1360  return OP_NULL;
1361  }
1362 
1363  /* Clear the tag prefix unless we just started it. Don't clear
1364  * the prefix on a timeout (i==-2), but do clear on an abort (i==-1) */
1365  if (menu->tagprefix && (i != OP_TAG_PREFIX) && (i != OP_TAG_PREFIX_COND) && (i != -2))
1366  menu->tagprefix = false;
1367 
1369 
1370  if (menu_redraw(menu) == OP_REDRAW)
1371  return OP_REDRAW;
1372 
1373  /* give visual indication that the next command is a tag- command */
1374  if (menu->tagprefix)
1375  {
1376  mutt_window_mvaddstr(MuttMessageWindow, 0, 0, "tag-");
1378  }
1379 
1380  menu->oldcurrent = menu->current;
1381 
1382  /* move the cursor out of the way */
1383  if (C_ArrowCursor)
1384  mutt_window_move(menu->indexwin, menu->current - menu->top + menu->offset, 2);
1385  else if (C_BrailleFriendly)
1386  mutt_window_move(menu->indexwin, menu->current - menu->top + menu->offset, 0);
1387  else
1388  {
1389  mutt_window_move(menu->indexwin, menu->current - menu->top + menu->offset,
1390  menu->indexwin->cols - 1);
1391  }
1392 
1393  mutt_refresh();
1394 
1395  /* try to catch dialog keys before ops */
1396  if (menu->dialog && (menu_dialog_dokey(menu, &i) == 0))
1397  return i;
1398 
1399  i = km_dokey(menu->type);
1400  if ((i == OP_TAG_PREFIX) || (i == OP_TAG_PREFIX_COND))
1401  {
1402  if (menu->tagprefix)
1403  {
1404  menu->tagprefix = false;
1406  continue;
1407  }
1408 
1409  if (menu->tagged)
1410  {
1411  menu->tagprefix = true;
1412  continue;
1413  }
1414  else if (i == OP_TAG_PREFIX)
1415  {
1416  mutt_error(_("No tagged entries"));
1417  i = -1;
1418  }
1419  else /* None tagged, OP_TAG_PREFIX_COND */
1420  {
1422  mutt_message(_("Nothing to do"));
1423  i = -1;
1424  }
1425  }
1426  else if (menu->tagged && C_AutoTag)
1427  menu->tagprefix = true;
1428 
1430 
1431  if (SigWinch)
1432  {
1433  SigWinch = 0;
1436  }
1437 
1438  if (i < 0)
1439  {
1440  if (menu->tagprefix)
1442  continue;
1443  }
1444 
1445  if (!menu->dialog)
1446  mutt_clear_error();
1447 
1448  /* Convert menubar movement to scrolling */
1449  if (menu->dialog)
1450  i = menu_dialog_translate_op(i);
1451 
1452  switch (i)
1453  {
1454  case OP_NEXT_ENTRY:
1455  menu_next_entry(menu);
1456  break;
1457  case OP_PREV_ENTRY:
1458  menu_prev_entry(menu);
1459  break;
1460  case OP_HALF_DOWN:
1461  menu_half_down(menu);
1462  break;
1463  case OP_HALF_UP:
1464  menu_half_up(menu);
1465  break;
1466  case OP_NEXT_PAGE:
1467  menu_next_page(menu);
1468  break;
1469  case OP_PREV_PAGE:
1470  menu_prev_page(menu);
1471  break;
1472  case OP_NEXT_LINE:
1473  menu_next_line(menu);
1474  break;
1475  case OP_PREV_LINE:
1476  menu_prev_line(menu);
1477  break;
1478  case OP_FIRST_ENTRY:
1479  menu_first_entry(menu);
1480  break;
1481  case OP_LAST_ENTRY:
1482  menu_last_entry(menu);
1483  break;
1484  case OP_TOP_PAGE:
1485  menu_top_page(menu);
1486  break;
1487  case OP_MIDDLE_PAGE:
1488  menu_middle_page(menu);
1489  break;
1490  case OP_BOTTOM_PAGE:
1491  menu_bottom_page(menu);
1492  break;
1493  case OP_CURRENT_TOP:
1494  menu_current_top(menu);
1495  break;
1496  case OP_CURRENT_MIDDLE:
1497  menu_current_middle(menu);
1498  break;
1499  case OP_CURRENT_BOTTOM:
1500  menu_current_bottom(menu);
1501  break;
1502  case OP_SEARCH:
1503  case OP_SEARCH_REVERSE:
1504  case OP_SEARCH_NEXT:
1505  case OP_SEARCH_OPPOSITE:
1506  if (menu->menu_search && !menu->dialog) /* Searching dialogs won't work */
1507  {
1508  menu->oldcurrent = menu->current;
1509  menu->current = menu_search(menu, i);
1510  if (menu->current != -1)
1511  menu->redraw = REDRAW_MOTION;
1512  else
1513  menu->current = menu->oldcurrent;
1514  }
1515  else
1516  mutt_error(_("Search is not implemented for this menu"));
1517  break;
1518 
1519  case OP_JUMP:
1520  if (menu->dialog)
1521  mutt_error(_("Jumping is not implemented for dialogs"));
1522  else
1523  menu_jump(menu);
1524  break;
1525 
1526  case OP_ENTER_COMMAND:
1528  break;
1529 
1530  case OP_TAG:
1531  if (menu->menu_tag && !menu->dialog)
1532  {
1533  if (menu->tagprefix && !C_AutoTag)
1534  {
1535  for (i = 0; i < menu->max; i++)
1536  menu->tagged += menu->menu_tag(menu, i, 0);
1537  menu->redraw |= REDRAW_INDEX;
1538  }
1539  else if (menu->max)
1540  {
1541  int j = menu->menu_tag(menu, menu->current, -1);
1542  menu->tagged += j;
1543  if (j && C_Resolve && (menu->current < menu->max - 1))
1544  {
1545  menu->current++;
1546  menu->redraw |= REDRAW_MOTION_RESYNC;
1547  }
1548  else
1549  menu->redraw |= REDRAW_CURRENT;
1550  }
1551  else
1552  mutt_error(_("No entries"));
1553  }
1554  else
1555  mutt_error(_("Tagging is not supported"));
1556  break;
1557 
1558  case OP_SHELL_ESCAPE:
1560  break;
1561 
1562  case OP_WHAT_KEY:
1563  mutt_what_key();
1564  break;
1565 
1566  case OP_CHECK_STATS:
1567  mutt_check_stats();
1568  break;
1569 
1570  case OP_REDRAW:
1572  menu->redraw = REDRAW_FULL;
1573  break;
1574 
1575  case OP_HELP:
1576  mutt_help(menu->type, menu->indexwin->cols);
1577  menu->redraw = REDRAW_FULL;
1578  break;
1579 
1580  case OP_NULL:
1581  km_error_key(menu->type);
1582  break;
1583 
1584  case OP_END_COND:
1585  break;
1586 
1587  default:
1588  if (menu->is_mailbox_list)
1589  last_position = menu->current;
1590  return i;
1591  }
1592  }
1593  /* not reached */
1594 }
int km_dokey(enum MenuType menu)
Determine what a keypress should do.
Definition: keymap.c:619
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:47
#define mutt_message(...)
Definition: logging.h:83
int oldcurrent
For driver use only.
Definition: mutt_menu.h:109
WHERE bool OptMenuCaller
(pseudo) tell menu to give caller a take
Definition: options.h:38
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:117
void mutt_resize_screen(void)
Update NeoMutt&#39;s opinion about the window size (CURSES)
Definition: resize.c:100
void mutt_check_stats(void)
Forcibly update mailbox stats.
Definition: commands.c:1382
char ** dialog
Dialog lines themselves.
Definition: mutt_menu.h:102
void mutt_enter_command(void)
enter a neomutt command
Definition: commands.c:853
#define _(a)
Definition: message.h:28
WHERE bool C_BrailleFriendly
Config: Move the cursor to the beginning of the line.
Definition: globals.h:210
void mutt_window_clear_screen(void)
Clear the entire screen.
Definition: mutt_window.c:437
void mutt_curses_set_cursor(enum MuttCursorState state)
Set the cursor state.
Definition: mutt_curses.c:70
enum MenuType type
Menu definition for keymap entries.
Definition: mutt_menu.h:90
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition: curs_lib.c:819
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:95
void mutt_what_key(void)
Ask the user to press a key.
Definition: keymap.c:1580
Display a normal cursor.
Definition: mutt_curses.h:82
void mutt_shell_escape(void)
invoke a command in a subshell
Definition: commands.c:825
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: globals.h:82
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:115
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:43
#define REDRAW_MOTION_RESYNC
Redraw any changing the menu selection.
Definition: mutt_menu.h:44
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:105
void km_error_key(enum MenuType menu)
Handle an unbound key sequence.
Definition: keymap.c:1054
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
int top
Entry that is the top of the current page.
Definition: mutt_menu.h:108
bool tagprefix
Definition: mutt_menu.h:93
WHERE bool C_Resolve
Config: Move to the next email whenever a command modifies an email.
Definition: globals.h:251
bool is_mailbox_list
Definition: mutt_menu.h:94
int mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:212
int tagged
Number of tagged entries.
Definition: mutt_menu.h:111
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:198
int max
Number of entries in the menu.
Definition: mutt_menu.h:88
int(* menu_tag)(struct Menu *menu, int sel, int act)
Tag some menu items.
Definition: mutt_menu.h:137
MuttRedrawFlags redraw
When to redraw the screen.
Definition: mutt_menu.h:89
int(* menu_search)(struct Menu *menu, regex_t *rx, int line)
Search a menu for a item matching a regex.
Definition: mutt_menu.h:129
int offset
Row offset within the window to start the index.
Definition: mutt_menu.h:91
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:42
void mutt_help(enum MenuType menu, int wraplen)
Display the help menu.
Definition: help.c:443
#define mutt_error(...)
Definition: logging.h:84
Hide the cursor.
Definition: mutt_curses.h:81
WHERE bool C_AutoTag
Config: Automatically apply actions to all tagged messages.
Definition: globals.h:207
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42
int current
Current entry.
Definition: mutt_menu.h:87
#define REDRAW_CURRENT
Redraw the current line of the menu.
Definition: mutt_menu.h:45
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: globals.h:198
+ 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 1599 of file menu.c.

1600 {
1601  if ((!nc) || (nc->event_type != NT_COLOR))
1602  return -1;
1603 
1604  int s = nc->event_subtype;
1605 
1606  bool simple = (s == MT_COLOR_INDEX_COLLAPSED) || (s == MT_COLOR_INDEX_DATE) ||
1607  (s == MT_COLOR_INDEX_LABEL) || (s == MT_COLOR_INDEX_NUMBER) ||
1608  (s == MT_COLOR_INDEX_SIZE) || (s == MT_COLOR_INDEX_TAGS);
1609  bool lists = (s == MT_COLOR_ATTACH_HEADERS) || (s == MT_COLOR_BODY) ||
1610  (s == MT_COLOR_HEADER) || (s == MT_COLOR_INDEX) ||
1611  (s == MT_COLOR_INDEX_AUTHOR) || (s == MT_COLOR_INDEX_FLAGS) ||
1612  (s == MT_COLOR_INDEX_SUBJECT) || (s == MT_COLOR_INDEX_TAG);
1613 
1614  // The changes aren't relevant to the index menu
1615  if (!simple && !lists)
1616  return 0;
1617 
1618  struct EventColor *ec = (struct EventColor *) nc->event;
1619 
1620  // Colour deleted from a list
1621  if (!ec->set && lists && Context && Context->mailbox)
1622  {
1623  // Force re-caching of index colors
1624  for (int i = 0; i < Context->mailbox->msg_count; i++)
1625  Context->mailbox->emails[i]->pair = 0;
1626  }
1627 
1629  return 0;
1630 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:110
MIME attachment test (takes a pattern)
Definition: color.h:63
The "current" mailbox.
Definition: context.h:36
Index: index number.
Definition: color.h:110
int msg_count
Total number of messages.
Definition: mailbox.h:102
Index: tags field (g, J)
Definition: color.h:112
An Event that happened to an Colour.
Definition: color.h:159
Pager: highlight body of message (takes a pattern)
Definition: color.h:64
intptr_t event
Send: event data.
Definition: observer.h:46
Index panel (list of emails)
Definition: keymap.h:77
Index: number of messages in collapsed thread.
Definition: color.h:107
int event_subtype
Send: event subtype.
Definition: observer.h:45
Index: author field (takes a pattern)
Definition: color.h:102
bool set
True if a colour has been set/added, false if reset/deleted.
Definition: color.h:161
struct Mailbox * mailbox
Definition: context.h:50
int event_type
Send: event type.
Definition: observer.h:44
Message headers (takes a pattern)
Definition: color.h:73
Index: tag field (g, takes a pattern)
Definition: color.h:105
Index: date field.
Definition: color.h:108
Colour has changed.
Definition: notify_type.h:39
Index: size field.
Definition: color.h:111
Index: label field.
Definition: color.h:109
Index: subject field (takes a pattern)
Definition: color.h:104
Index: default colour (takes a pattern)
Definition: color.h:101
int pair
Color-pair to use when displaying in the index.
Definition: email.h:79
Index: flags field (takes a pattern)
Definition: color.h:103
+ 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 1635 of file menu.c.

1636 {
1637  if (!nc)
1638  return -1;
1639 
1640  struct EventConfig *ec = (struct EventConfig *) nc->event;
1641 
1642  const struct ConfigDef *cdef = ec->he->data;
1643  ConfigRedrawFlags flags = cdef->type & R_REDRAW_MASK;
1644 
1645  if (flags == R_REDRAW_NO_FLAGS)
1646  return 0;
1647 
1648  if (flags & R_INDEX)
1650  if (flags & R_PAGER)
1652  if (flags & R_PAGER_FLOW)
1653  {
1656  }
1657 
1658  if (flags & R_RESORT_SUB)
1659  OptSortSubthreads = true;
1660  if (flags & R_RESORT)
1661  OptNeedResort = true;
1662  if (flags & R_RESORT_INIT)
1663  OptResortInit = true;
1664  if (flags & R_TREE)
1665  OptRedrawTree = true;
1666 
1667  if (flags & R_REFLOW)
1669 #ifdef USE_SIDEBAR
1670  if (flags & R_SIDEBAR)
1672 #endif
1673  if (flags & R_MENU)
1675 
1676  return 0;
1677 }
#define R_PAGER
Redraw the pager menu.
Definition: types.h:64
#define R_PAGER_FLOW
Reflow line_info and redraw the pager menu.
Definition: types.h:65
#define REDRAW_FLOW
Used by pager to reflow text.
Definition: mutt_menu.h:49
WHERE bool OptNeedResort
(pseudo) used to force a re-sort
Definition: options.h:41
A config-change event.
Definition: set.h:199
intptr_t event
Send: event data.
Definition: observer.h:46
Index panel (list of emails)
Definition: keymap.h:77
Config item definition.
Definition: set.h:153
#define R_RESORT
Resort the mailbox.
Definition: types.h:66
#define REDRAW_SIDEBAR
Redraw the sidebar.
Definition: mutt_menu.h:51
#define R_TREE
Redraw the thread tree.
Definition: types.h:69
Pager pager (email viewer)
Definition: keymap.h:78
#define R_REDRAW_NO_FLAGS
No refresh/resort flags.
Definition: types.h:62
struct HashElem * he
Config item that changed.
Definition: set.h:202
void mutt_window_reflow(void)
Resize the Windows to fit the screen.
Definition: mutt_window.c:264
#define R_MENU
Redraw all menus.
Definition: types.h:72
#define R_RESORT_SUB
Resort subthreads.
Definition: types.h:67
#define R_REFLOW
Reflow window layout and full redraw.
Definition: types.h:70
uint32_t ConfigRedrawFlags
Flags for redraw/resort, e.g. R_INDEX.
Definition: types.h:61
WHERE bool OptRedrawTree
(pseudo) redraw the thread tree
Definition: options.h:48
WHERE bool OptResortInit
(pseudo) used to force the next resort to be from scratch
Definition: options.h:49
void * data
Definition: hash.h:46
#define R_RESORT_INIT
Resort from scratch.
Definition: types.h:68
WHERE bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition: options.h:52
#define R_SIDEBAR
Redraw the sidebar.
Definition: types.h:71
#define R_REDRAW_MASK
Mask for the Redraw Flags.
Definition: types.h:74
#define R_INDEX
Redraw the index menu (MENU_MAIN)
Definition: types.h:63
+ 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 62 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 63 of file menu.c.

◆ C_MenuScroll

bool C_MenuScroll

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

Definition at line 64 of file menu.c.

◆ SearchBuffers

char* SearchBuffers[MENU_MAX]

Definition at line 66 of file menu.c.

◆ MenuStackCount

size_t MenuStackCount = 0
static

Definition at line 69 of file menu.c.

◆ MenuStackLen

size_t MenuStackLen = 0
static

Definition at line 70 of file menu.c.

◆ MenuStack

struct Menu** MenuStack = NULL
static

Definition at line 71 of file menu.c.