NeoMutt  2018-07-16 +1783-b00bd9
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 "email/lib.h"
#include "mutt.h"
#include "color.h"
#include "commands.h"
#include "context.h"
#include "curs_lib.h"
#include "globals.h"
#include "keymap.h"
#include "mailbox.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 "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_destroy (struct Menu **p)
 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 (int menu_type, MuttRedrawFlags redraw)
 Set redraw flags on a menu. More...
 
void mutt_menu_set_redraw_full (int menu_type)
 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...
 
bool mutt_menu_listener (const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev)
 Listen for config changes affecting the menu - Implements cs_listener() 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

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

Definition at line 70 of file menu.c.

#define MUTT_SEARCH_UP   1

Definition at line 72 of file menu.c.

#define MUTT_SEARCH_DOWN   2

Definition at line 73 of file menu.c.

Function Documentation

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

85 {
86  struct ColorLineHead *color = NULL;
87  struct ColorLine *np = NULL;
88  struct Email *e = Context->mailbox->emails[Context->mailbox->v2r[index]];
89  int type = *s;
90 
91  switch (type)
92  {
94  color = &ColorIndexAuthorList;
95  break;
97  color = &ColorIndexFlagsList;
98  break;
100  color = &ColorIndexSubjectList;
101  break;
102  case MT_COLOR_INDEX_TAG:
103  STAILQ_FOREACH(np, &ColorIndexTagList, entries)
104  {
105  if (strncmp((const char *) (s + 1), np->pattern, strlen(np->pattern)) == 0)
106  return np->pair;
107  const char *transform = mutt_hash_find(TagTransforms, np->pattern);
108  if (transform &&
109  (strncmp((const char *) (s + 1), transform, strlen(transform)) == 0))
110  {
111  return np->pair;
112  }
113  }
114  return 0;
115  default:
116  return ColorDefs[type];
117  }
118 
119  STAILQ_FOREACH(np, color, entries)
120  {
123  return np->pair;
124  }
125 
126  return 0;
127 }
struct Email ** emails
Definition: mailbox.h:99
Index: subject field (takes a pattern)
Definition: mutt_curses.h:160
The "current" mailbox.
Definition: context.h:38
The envelope/body of an email.
Definition: email.h:37
struct Hash * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:39
struct ColorLineHead ColorIndexFlagsList
List of colours applied to the flags in the index.
Definition: color.c:58
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:379
char * pattern
Definition: mutt_curses.h:184
struct Mailbox * mailbox
Definition: context.h:52
struct ColorLineHead ColorIndexAuthorList
List of colours applied to the author in the index.
Definition: color.c:57
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:1970
Index: tag field (g, takes a pattern)
Definition: mutt_curses.h:159
Index: flags field (takes a pattern)
Definition: mutt_curses.h:158
#define SLIST_FIRST(head)
Definition: queue.h:229
Index: author field (takes a pattern)
Definition: mutt_curses.h:157
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:350
int ColorDefs[MT_COLOR_MAX]
Array of all fixed colours, see enum ColorId.
Definition: color.c:53
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition: pattern.h:72
int * v2r
mapping from virtual to real msgno
Definition: mailbox.h:101
struct ColorLineHead ColorIndexSubjectList
List of colours applied to the subject in the index.
Definition: color.c:60
struct ColorLineHead ColorIndexTagList
List of colours applied to tags in the index.
Definition: color.c:61
int index
the absolute (unsorted) message number
Definition: email.h:88
A regular expression and a color to highlight a line.
Definition: mutt_curses.h:180
struct PatternHead * color_pattern
compiled pattern to speed up index color calculation
Definition: mutt_curses.h:185

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

137 {
138  wchar_t wc;
139  size_t k;
140  size_t n = mutt_str_strlen((char *) s);
141  mbstate_t mbstate;
142 
143  if (!stdscr)
144  return;
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  addch('`');
168 #ifdef WACS_LLCORNER
169  else
170  add_wch(WACS_LLCORNER);
171 #else
172  else if (CharsetIsUtf8)
173  addstr("\342\224\224"); /* WACS_LLCORNER */
174  else
175  addch(ACS_LLCORNER);
176 #endif
177  break;
178  case MUTT_TREE_ULCORNER:
179  if (C_AsciiChars)
180  addch(',');
181 #ifdef WACS_ULCORNER
182  else
183  add_wch(WACS_ULCORNER);
184 #else
185  else if (CharsetIsUtf8)
186  addstr("\342\224\214"); /* WACS_ULCORNER */
187  else
188  addch(ACS_ULCORNER);
189 #endif
190  break;
191  case MUTT_TREE_LTEE:
192  if (C_AsciiChars)
193  addch('|');
194 #ifdef WACS_LTEE
195  else
196  add_wch(WACS_LTEE);
197 #else
198  else if (CharsetIsUtf8)
199  addstr("\342\224\234"); /* WACS_LTEE */
200  else
201  addch(ACS_LTEE);
202 #endif
203  break;
204  case MUTT_TREE_HLINE:
205  if (C_AsciiChars)
206  addch('-');
207 #ifdef WACS_HLINE
208  else
209  add_wch(WACS_HLINE);
210 #else
211  else if (CharsetIsUtf8)
212  addstr("\342\224\200"); /* WACS_HLINE */
213  else
214  addch(ACS_HLINE);
215 #endif
216  break;
217  case MUTT_TREE_VLINE:
218  if (C_AsciiChars)
219  addch('|');
220 #ifdef WACS_VLINE
221  else
222  add_wch(WACS_VLINE);
223 #else
224  else if (CharsetIsUtf8)
225  addstr("\342\224\202"); /* WACS_VLINE */
226  else
227  addch(ACS_VLINE);
228 #endif
229  break;
230  case MUTT_TREE_TTEE:
231  if (C_AsciiChars)
232  addch('-');
233 #ifdef WACS_TTEE
234  else
235  add_wch(WACS_TTEE);
236 #else
237  else if (CharsetIsUtf8)
238  addstr("\342\224\254"); /* WACS_TTEE */
239  else
240  addch(ACS_TTEE);
241 #endif
242  break;
243  case MUTT_TREE_BTEE:
244  if (C_AsciiChars)
245  addch('-');
246 #ifdef WACS_BTEE
247  else
248  add_wch(WACS_BTEE);
249 #else
250  else if (CharsetIsUtf8)
251  addstr("\342\224\264"); /* WACS_BTEE */
252  else
253  addch(ACS_BTEE);
254 #endif
255  break;
256  case MUTT_TREE_SPACE:
257  addch(' ');
258  break;
259  case MUTT_TREE_RARROW:
260  addch('>');
261  break;
262  case MUTT_TREE_STAR:
263  addch('*'); /* fake thread indicator */
264  break;
265  case MUTT_TREE_HIDDEN:
266  addch('&');
267  break;
268  case MUTT_TREE_EQUALS:
269  addch('=');
270  break;
271  case MUTT_TREE_MISSING:
272  addch('?');
273  break;
274  }
275  s++;
276  n--;
277  }
278  if (do_color)
279  ATTR_SET(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  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
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:669
Right arrow.
Definition: mutt_menu.h:67
Bottom T-piece.
Definition: mutt_menu.h:72
int mutt_combine_color(uint32_t fg_attr, uint32_t bg_attr)
Blank space.
Definition: mutt_menu.h:66
Vertical line.
Definition: mutt_menu.h:65
Top T-piece.
Definition: mutt_menu.h:71
Index: default colour (takes a pattern)
Definition: mutt_curses.h:156
Star character (for threads)
Definition: mutt_menu.h:68
Equals (for threads)
Definition: mutt_menu.h:70
Ampersand character (for threads)
Definition: mutt_menu.h:69
Question mark.
Definition: mutt_menu.h:73
#define ATTR_SET
Definition: mutt_curses.h:232
WHERE bool C_AsciiChars
Config: Use plain ASCII characters, when drawing email threads.
Definition: globals.h:196
Index: tree-drawing characters.
Definition: mutt_curses.h:130
int ColorDefs[MT_COLOR_MAX]
Array of all fixed colours, see enum ColorId.
Definition: color.c:53
#define SET_COLOR(X)
Definition: mutt_curses.h:224
Colour indicator.
Definition: mutt_menu.h:76
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:88
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:

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:36
char ** dialog
dialog lines themselves
Definition: mutt_menu.h:104
void(* menu_make_entry)(char *buf, size_t buflen, struct Menu *menu, int line)
Format a item for a menu.
Definition: mutt_menu.h:122
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:753
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:

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:46
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:669
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:973
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: globals.h:195

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 {
361  NORMAL_COLOR;
362  /* clear() doesn't optimize screen redraws */
363  move(0, 0);
364  clrtobot();
365 
366  if (C_Help)
367  {
369  mutt_window_move(menu->helpwin, 0, 0);
370  mutt_paddstr(menu->helpwin->cols, menu->help);
371  NORMAL_COLOR;
372  }
373  menu->offset = 0;
374  menu->pagelen = menu->indexwin->rows;
375 
376  mutt_show_error();
377 
379 #ifdef USE_SIDEBAR
380  menu->redraw |= REDRAW_SIDEBAR;
381 #endif
382 }
#define NORMAL_COLOR
Definition: mutt_curses.h:239
WHERE bool C_Help
Config: Display a help line with common key bindings.
Definition: globals.h:218
#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:1146
struct MuttWindow * helpwin
Definition: mutt_menu.h:97
void mutt_window_reflow(void)
Resize the Windows to fit the screen.
Definition: mutt_window.c:237
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:46
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
int pagelen
number of entries per screen
Definition: mutt_menu.h:92
#define SET_COLOR(X)
Definition: mutt_curses.h:224
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:162
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
Status bar.
Definition: mutt_curses.h:129
void mutt_show_error(void)
Show the user an error message.
Definition: curs_lib.c:485
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:

void menu_redraw_status ( struct Menu menu)

Force the redraw of the status bar.

Parameters
menuCurrent Menu

Definition at line 388 of file menu.c.

389 {
390  char buf[256];
391 
392  snprintf(buf, sizeof(buf), "-- NeoMutt: %s", menu->title);
394  mutt_window_move(menu->statuswin, 0, 0);
395  mutt_paddstr(menu->statuswin->cols, buf);
396  NORMAL_COLOR;
397  menu->redraw &= ~REDRAW_STATUS;
398 }
#define NORMAL_COLOR
Definition: mutt_curses.h:239
void mutt_paddstr(int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:1146
struct MuttWindow * statuswin
Definition: mutt_menu.h:96
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:46
#define SET_COLOR(X)
Definition: mutt_curses.h:224
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:162
MuttRedrawFlags redraw
when to redraw the screen
Definition: mutt_menu.h:89
char * title
the title of this menu
Definition: mutt_menu.h:84
Status bar.
Definition: mutt_curses.h:129

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void menu_redraw_sidebar ( struct Menu menu)

Force the redraw of the sidebar.

Parameters
menuCurrent Menu

Definition at line 405 of file menu.c.

406 {
407  menu->redraw &= ~REDRAW_SIDEBAR;
408  mutt_sb_draw();
409 }
#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:

void menu_redraw_index ( struct Menu menu)

Force the redraw of the index.

Parameters
menuCurrent Menu

Definition at line 416 of file menu.c.

417 {
418  char buf[1024];
419  bool do_color;
420  int attr;
421 
422  for (int i = menu->top; i < menu->top + menu->pagelen; i++)
423  {
424  if (i < menu->max)
425  {
426  attr = menu->menu_color(i);
427 
428  menu_make_entry(buf, sizeof(buf), menu, i);
429  menu_pad_string(menu, buf, sizeof(buf));
430 
431  ATTR_SET(attr);
432  mutt_window_move(menu->indexwin, i - menu->top + menu->offset, 0);
433  do_color = true;
434 
435  if (i == menu->current)
436  {
438  if (C_ArrowCursor)
439  {
440  addstr("->");
441  ATTR_SET(attr);
442  addch(' ');
443  }
444  else
445  do_color = false;
446  }
447  else if (C_ArrowCursor)
448  addstr(" ");
449 
450  print_enriched_string(i, attr, (unsigned char *) buf, do_color);
451  }
452  else
453  {
454  NORMAL_COLOR;
455  mutt_window_clearline(menu->indexwin, i - menu->top + menu->offset);
456  }
457  }
458  NORMAL_COLOR;
459  menu->redraw = 0;
460 }
#define NORMAL_COLOR
Definition: mutt_curses.h:239
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:69
#define ATTR_SET
Definition: mutt_curses.h:232
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
int top
entry that is the top of the current page
Definition: mutt_menu.h:110
int pagelen
number of entries per screen
Definition: mutt_menu.h:92
#define SET_COLOR(X)
Definition: mutt_curses.h:224
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:162
int(* menu_color)(int line)
Calculate the colour for a line of the menu.
Definition: mutt_menu.h:146
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
Selected item in list.
Definition: mutt_curses.h:128
int current
current entry
Definition: mutt_menu.h:87
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: globals.h:195

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void menu_redraw_motion ( struct Menu menu)

Force the redraw of the list part of the menu.

Parameters
menuCurrent Menu

Definition at line 466 of file menu.c.

467 {
468  char buf[1024];
469 
470  if (menu->dialog)
471  {
472  menu->redraw &= ~REDRAW_MOTION;
473  return;
474  }
475 
476  /* Note: menu->color() for the index can end up retrieving a message
477  * over imap (if matching against ~h for instance). This can
478  * generate status messages. So we want to call it *before* we
479  * position the cursor for drawing. */
480  const int old_color = menu->menu_color(menu->oldcurrent);
481  mutt_window_move(menu->indexwin, menu->oldcurrent + menu->offset - menu->top, 0);
482  ATTR_SET(old_color);
483 
484  if (C_ArrowCursor)
485  {
486  /* clear the pointer */
487  addstr(" ");
488 
489  if (menu->redraw & REDRAW_MOTION_RESYNC)
490  {
491  menu_make_entry(buf, sizeof(buf), menu, menu->oldcurrent);
492  menu_pad_string(menu, buf, sizeof(buf));
493  mutt_window_move(menu->indexwin, menu->oldcurrent + menu->offset - menu->top, 3);
494  print_enriched_string(menu->oldcurrent, old_color, (unsigned char *) buf, 1);
495  }
496 
497  /* now draw it in the new location */
499  mutt_window_mvaddstr(menu->indexwin, menu->current + menu->offset - menu->top, 0, "->");
500  }
501  else
502  {
503  /* erase the current indicator */
504  menu_make_entry(buf, sizeof(buf), menu, menu->oldcurrent);
505  menu_pad_string(menu, buf, sizeof(buf));
506  print_enriched_string(menu->oldcurrent, old_color, (unsigned char *) buf, 1);
507 
508  /* now draw the new one to reflect the change */
509  const int cur_color = menu->menu_color(menu->current);
510  menu_make_entry(buf, sizeof(buf), menu, menu->current);
511  menu_pad_string(menu, buf, sizeof(buf));
513  mutt_window_move(menu->indexwin, menu->current + menu->offset - menu->top, 0);
514  print_enriched_string(menu->current, cur_color, (unsigned char *) buf, 0);
515  }
516  menu->redraw &= REDRAW_STATUS;
517  NORMAL_COLOR;
518 }
int oldcurrent
for driver use only
Definition: mutt_menu.h:111
#define NORMAL_COLOR
Definition: mutt_curses.h:239
char ** dialog
dialog lines themselves
Definition: mutt_menu.h:104
#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
#define ATTR_SET
Definition: mutt_curses.h:232
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
int top
entry that is the top of the current page
Definition: mutt_menu.h:110
#define SET_COLOR(X)
Definition: mutt_curses.h:224
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:190
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:162
int(* menu_color)(int line)
Calculate the colour for a line of the menu.
Definition: mutt_menu.h:146
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
Selected item in list.
Definition: mutt_curses.h:128
int current
current entry
Definition: mutt_menu.h:87
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: globals.h:195

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void menu_redraw_current ( struct Menu menu)

Redraw the current menu.

Parameters
menuCurrent Menu

Definition at line 524 of file menu.c.

525 {
526  char buf[1024];
527  int attr = menu->menu_color(menu->current);
528 
529  mutt_window_move(menu->indexwin, menu->current + menu->offset - menu->top, 0);
530  menu_make_entry(buf, sizeof(buf), menu, menu->current);
531  menu_pad_string(menu, buf, sizeof(buf));
532 
534  if (C_ArrowCursor)
535  {
536  addstr("->");
537  ATTR_SET(attr);
538  addch(' ');
539  menu_pad_string(menu, buf, sizeof(buf));
540  print_enriched_string(menu->current, attr, (unsigned char *) buf, 1);
541  }
542  else
543  print_enriched_string(menu->current, attr, (unsigned char *) buf, 0);
544  menu->redraw &= REDRAW_STATUS;
545  NORMAL_COLOR;
546 }
#define NORMAL_COLOR
Definition: mutt_curses.h:239
#define REDRAW_STATUS
Redraw the status bar.
Definition: mutt_menu.h:46
#define ATTR_SET
Definition: mutt_curses.h:232
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
int top
entry that is the top of the current page
Definition: mutt_menu.h:110
#define SET_COLOR(X)
Definition: mutt_curses.h:224
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:162
int(* menu_color)(int line)
Calculate the colour for a line of the menu.
Definition: mutt_menu.h:146
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
Selected item in list.
Definition: mutt_curses.h:128
int current
current entry
Definition: mutt_menu.h:87
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: globals.h:195

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void menu_redraw_prompt ( struct Menu menu)
static

Force the redraw of the message window.

Parameters
menuCurrent Menu

Definition at line 552 of file menu.c.

553 {
554  if (!menu || !menu->dialog)
555  return;
556 
557  if (OptMsgErr)
558  {
559  mutt_sleep(1);
560  OptMsgErr = false;
561  }
562 
563  if (ErrorBufMessage)
565 
566  mutt_window_mvaddstr(menu->messagewin, 0, 0, menu->prompt);
568 }
char * prompt
prompt for user, similar to mutt_multi_choice
Definition: mutt_menu.h:106
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:81
char ** dialog
dialog lines themselves
Definition: mutt_menu.h:104
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1498
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:141
WHERE bool ErrorBufMessage
true if the last message was an error
Definition: globals.h:43
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:190
struct MuttWindow * messagewin
Definition: mutt_menu.h:98
WHERE bool OptMsgErr
(pseudo) used by mutt_error/mutt_message
Definition: options.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void menu_check_recenter ( struct Menu menu)

Recentre the menu on screen.

Parameters
menuCurrent Menu

Definition at line 574 of file menu.c.

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

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

627 {
628  int n;
629 
630  if (menu->max)
631  {
633  char buf[128];
634  buf[0] = '\0';
635  if ((mutt_get_field(_("Jump to: "), buf, sizeof(buf), 0) == 0) && buf[0])
636  {
637  if ((mutt_str_atoi(buf, &n) == 0) && (n > 0) && (n < menu->max + 1))
638  {
639  n--; /* msg numbers are 0-based */
640  menu->current = n;
641  menu->redraw = REDRAW_MOTION;
642  }
643  else
644  mutt_error(_("Invalid index number"));
645  }
646  }
647  else
648  mutt_error(_("No entries"));
649 }
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:700
#define _(a)
Definition: message.h:28
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:86
int LastKey
contains the last key the user pressed
Definition: keymap.c:145
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:43
int max
the 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:83
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:

void menu_next_line ( struct Menu menu)

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

Parameters
menuCurrent Menu

Definition at line 655 of file menu.c.

656 {
657  if (menu->max)
658  {
659  int c = MIN(C_MenuContext, menu->pagelen / 2);
660 
661  if ((menu->top + 1 < menu->max - c) &&
662  (C_MenuMoveOff ||
663  ((menu->max > menu->pagelen) && (menu->top < menu->max - menu->pagelen))))
664  {
665  menu->top++;
666  if ((menu->current < menu->top + c) && (menu->current < menu->max - 1))
667  menu->current++;
668  menu->redraw = REDRAW_INDEX;
669  }
670  else
671  mutt_message(_("You can't scroll down farther"));
672  }
673  else
674  mutt_error(_("No entries"));
675 }
#define MIN(a, b)
Definition: memory.h:31
#define mutt_message(...)
Definition: logging.h:82
#define _(a)
Definition: message.h:28
int top
entry that is the top of the current page
Definition: mutt_menu.h:110
int pagelen
number of entries per screen
Definition: mutt_menu.h:92
int max
the 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:83
int current
current entry
Definition: mutt_menu.h:87

+ Here is the caller graph for this function:

void menu_prev_line ( struct Menu menu)

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

Parameters
menuCurrent Menu

Definition at line 681 of file menu.c.

682 {
683  if (menu->top > 0)
684  {
685  int c = MIN(C_MenuContext, menu->pagelen / 2);
686 
687  menu->top--;
688  if ((menu->current >= menu->top + menu->pagelen - c) && (menu->current > 1))
689  menu->current--;
690  menu->redraw = REDRAW_INDEX;
691  }
692  else
693  mutt_message(_("You can't scroll up farther"));
694 }
#define MIN(a, b)
Definition: memory.h:31
#define mutt_message(...)
Definition: logging.h:82
#define _(a)
Definition: message.h:28
int top
entry that is the top of the current page
Definition: mutt_menu.h:110
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:

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

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

+ Here is the caller graph for this function:

void menu_next_page ( struct Menu menu)

Move the focus to the next page in the menu.

Parameters
menuCurrent Menu

Definition at line 754 of file menu.c.

755 {
756  menu_length_jump(menu, MAX(menu->pagelen /* - MenuOverlap */, 0));
757 }
#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:

void menu_prev_page ( struct Menu menu)

Move the focus to the previous page in the menu.

Parameters
menuCurrent Menu

Definition at line 763 of file menu.c.

764 {
765  menu_length_jump(menu, 0 - MAX(menu->pagelen /* - MenuOverlap */, 0));
766 }
#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:

void menu_half_down ( struct Menu menu)

Move the focus down half a page in the menu.

Parameters
menuCurrent Menu

Definition at line 772 of file menu.c.

773 {
774  menu_length_jump(menu, menu->pagelen / 2);
775 }
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:

void menu_half_up ( struct Menu menu)

Move the focus up half a page in the menu.

Parameters
menuCurrent Menu

Definition at line 781 of file menu.c.

782 {
783  menu_length_jump(menu, 0 - menu->pagelen / 2);
784 }
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:

void menu_top_page ( struct Menu menu)

Move the focus to the top of the page.

Parameters
menuCurrent Menu

Definition at line 790 of file menu.c.

791 {
792  if (menu->current == menu->top)
793  return;
794 
795  menu->current = menu->top;
796  menu->redraw = REDRAW_MOTION;
797 }
#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:110
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:

void menu_bottom_page ( struct Menu menu)

Move the focus to the bottom of the page.

Parameters
menuCurrent Menu

Definition at line 803 of file menu.c.

804 {
805  if (menu->max)
806  {
807  menu->current = menu->top + menu->pagelen - 1;
808  if (menu->current > menu->max - 1)
809  menu->current = menu->max - 1;
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:43
int top
entry that is the top of the current page
Definition: mutt_menu.h:110
int pagelen
number of entries per screen
Definition: mutt_menu.h:92
int max
the 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:83
int current
current entry
Definition: mutt_menu.h:87

+ Here is the caller graph for this function:

void menu_middle_page ( struct Menu menu)

Move the focus to the centre of the page.

Parameters
menuCurrent Menu

Definition at line 820 of file menu.c.

821 {
822  if (menu->max)
823  {
824  int i = menu->top + menu->pagelen;
825  if (i > menu->max - 1)
826  i = menu->max - 1;
827  menu->current = menu->top + (i - menu->top) / 2;
828  menu->redraw = REDRAW_MOTION;
829  }
830  else
831  mutt_error(_("No entries"));
832 }
#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:110
int pagelen
number of entries per screen
Definition: mutt_menu.h:92
int max
the 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:83
int current
current entry
Definition: mutt_menu.h:87

+ Here is the caller graph for this function:

void menu_first_entry ( struct Menu menu)

Move the focus to the first entry in the menu.

Parameters
menuCurrent Menu

Definition at line 838 of file menu.c.

839 {
840  if (menu->max)
841  {
842  menu->current = 0;
843  menu->redraw = REDRAW_MOTION;
844  }
845  else
846  mutt_error(_("No entries"));
847 }
#define _(a)
Definition: message.h:28
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:43
int max
the 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:83
int current
current entry
Definition: mutt_menu.h:87

+ Here is the caller graph for this function:

void menu_last_entry ( struct Menu menu)

Move the focus to the last entry in the menu.

Parameters
menuCurrent Menu

Definition at line 853 of file menu.c.

854 {
855  if (menu->max)
856  {
857  menu->current = menu->max - 1;
858  menu->redraw = REDRAW_MOTION;
859  }
860  else
861  mutt_error(_("No entries"));
862 }
#define _(a)
Definition: message.h:28
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:43
int max
the 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:83
int current
current entry
Definition: mutt_menu.h:87

+ Here is the caller graph for this function:

void menu_current_top ( struct Menu menu)

Move the current selection to the top of the window.

Parameters
menuCurrent Menu

Definition at line 868 of file menu.c.

869 {
870  if (menu->max)
871  {
872  menu->top = menu->current;
873  menu->redraw = REDRAW_INDEX;
874  }
875  else
876  mutt_error(_("No entries"));
877 }
#define _(a)
Definition: message.h:28
int top
entry that is the top of the current page
Definition: mutt_menu.h:110
int max
the 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:83
int current
current entry
Definition: mutt_menu.h:87

+ Here is the caller graph for this function:

void menu_current_middle ( struct Menu menu)

Move the current selection to the centre of the window.

Parameters
menuCurrent Menu

Definition at line 883 of file menu.c.

884 {
885  if (menu->max)
886  {
887  menu->top = menu->current - menu->pagelen / 2;
888  if (menu->top < 0)
889  menu->top = 0;
890  menu->redraw = REDRAW_INDEX;
891  }
892  else
893  mutt_error(_("No entries"));
894 }
#define _(a)
Definition: message.h:28
int top
entry that is the top of the current page
Definition: mutt_menu.h:110
int pagelen
number of entries per screen
Definition: mutt_menu.h:92
int max
the 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:83
int current
current entry
Definition: mutt_menu.h:87

+ Here is the caller graph for this function:

void menu_current_bottom ( struct Menu menu)

Move the current selection to the bottom of the window.

Parameters
menuCurrent Menu

Definition at line 900 of file menu.c.

901 {
902  if (menu->max)
903  {
904  menu->top = menu->current - menu->pagelen + 1;
905  if (menu->top < 0)
906  menu->top = 0;
907  menu->redraw = REDRAW_INDEX;
908  }
909  else
910  mutt_error(_("No entries"));
911 }
#define _(a)
Definition: message.h:28
int top
entry that is the top of the current page
Definition: mutt_menu.h:110
int pagelen
number of entries per screen
Definition: mutt_menu.h:92
int max
the 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:83
int current
current entry
Definition: mutt_menu.h:87

+ Here is the caller graph for this function:

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

918 {
919  if (menu->current < menu->max - 1)
920  {
921  menu->current++;
922  menu->redraw = REDRAW_MOTION;
923  }
924  else
925  mutt_message(_("You are on the last entry"));
926 }
#define mutt_message(...)
Definition: logging.h:82
#define _(a)
Definition: message.h:28
#define REDRAW_MOTION
Redraw after moving the menu list.
Definition: mutt_menu.h:43
int max
the 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:

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

933 {
934  if (menu->current)
935  {
936  menu->current--;
937  menu->redraw = REDRAW_MOTION;
938  }
939  else
940  mutt_message(_("You are on the first entry"));
941 }
#define mutt_message(...)
Definition: logging.h:82
#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:

static int default_color ( int  line)
static

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

Definition at line 946 of file menu.c.

947 {
948  return ColorDefs[MT_COLOR_NORMAL];
949 }
Plain text.
Definition: mutt_curses.h:131
int ColorDefs[MT_COLOR_MAX]
Array of all fixed colours, see enum ColorId.
Definition: color.c:53

+ Here is the caller graph for this function:

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

955 {
956  char buf[1024];
957 
958  menu_make_entry(buf, sizeof(buf), menu, line);
959  return regexec(rx, buf, 0, NULL, 0);
960 }
const char * line
Definition: common.c:35

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_menu_init ( void  )

Initialise all the Menus.

Definition at line 965 of file menu.c.

966 {
967  for (int i = 0; i < MENU_MAX; i++)
968  SearchBuffers[i] = NULL;
969 }

+ Here is the caller graph for this function:

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

977 {
978  struct Menu *menu = mutt_mem_calloc(1, sizeof(struct Menu));
979 
980  if (type >= MENU_MAX)
981  type = MENU_GENERIC;
982 
983  menu->menu = type;
984  menu->current = 0;
985  menu->top = 0;
986  menu->offset = 0;
987  menu->redraw = REDRAW_FULL;
988  menu->pagelen = MuttIndexWindow->rows;
989  menu->indexwin = MuttIndexWindow;
990  menu->statuswin = MuttStatusWindow;
991  menu->helpwin = MuttHelpWindow;
993  menu->menu_color = default_color;
994  menu->menu_search = generic_search;
995 
996  return menu;
997 }
#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:51
struct MuttWindow * MuttStatusWindow
Status Window.
Definition: mutt_window.c:40
GUI selectable list of items.
Definition: mutt_menu.h:82
struct MuttWindow * MuttHelpWindow
Help Window.
Definition: mutt_window.c:38
int menu
menu definition for keymap entries.
Definition: mutt_menu.h:90
struct MuttWindow * helpwin
Definition: mutt_menu.h:97
struct MuttWindow * statuswin
Definition: mutt_menu.h:96
struct MuttWindow * MuttIndexWindow
Index Window.
Definition: mutt_window.c:39
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
int top
entry that is the top of the current page
Definition: mutt_menu.h:110
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:146
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:131
int offset
row offset within the window to start the index
Definition: mutt_menu.h:91
struct MuttWindow * messagewin
Definition: mutt_menu.h:98
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41
int current
current entry
Definition: mutt_menu.h:87
Generic selection list.
Definition: keymap.h:75

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_menu_destroy ( struct Menu **  p)

Destroy a menu.

Parameters
[out]pMenu to destroy

Definition at line 1003 of file menu.c.

1004 {
1005  if ((*p)->dialog)
1006  {
1007  for (int i = 0; i < (*p)->max; i++)
1008  FREE(&(*p)->dialog[i]);
1009 
1010  FREE(&(*p)->dialog);
1011  }
1012 
1013  FREE(p);
1014 }
#define FREE(x)
Definition: memory.h:40

+ Here is the caller graph for this function:

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

1022 {
1023  if (menu->dsize <= menu->max)
1024  {
1025  menu->dsize += 10;
1026  mutt_mem_realloc(&menu->dialog, menu->dsize * sizeof(char *));
1027  }
1028  menu->dialog[menu->max++] = mutt_str_strdup(row);
1029 }
char ** dialog
dialog lines themselves
Definition: mutt_menu.h:104
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:121
int max
the 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:105

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static struct Menu* get_current_menu ( void  )
static

Get the current Menu.

Return values
ptrCurrent Menu

Definition at line 1035 of file menu.c.

1036 {
1037  return MenuStackCount ? MenuStack[MenuStackCount - 1] : NULL;
1038 }

+ Here is the caller graph for this function:

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

1047 {
1049  {
1050  MenuStackLen += 5;
1051  mutt_mem_realloc(&MenuStack, MenuStackLen * sizeof(struct Menu *));
1052  }
1053 
1055  CurrentMenu = menu->menu;
1056 }
GUI selectable list of items.
Definition: mutt_menu.h:82
int menu
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:121
WHERE int CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:86

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

1065 {
1066  struct Menu *prev_menu = NULL;
1067 
1068  if (!MenuStackCount || (MenuStack[MenuStackCount - 1] != menu))
1069  {
1070  mutt_debug(LL_DEBUG1, "called with inactive menu\n");
1071  return;
1072  }
1073 
1074  MenuStackCount--;
1075  prev_menu = get_current_menu();
1076  if (prev_menu)
1077  {
1078  CurrentMenu = prev_menu->menu;
1079  prev_menu->redraw = REDRAW_FULL;
1080  }
1081  else
1082  {
1084  }
1085 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:47
GUI selectable list of items.
Definition: mutt_menu.h:82
Index panel (list of emails)
Definition: keymap.h:76
int menu
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
WHERE int CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:86
#define mutt_debug(LEVEL,...)
Definition: logging.h:80

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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:

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:

void mutt_menu_set_redraw ( int  menu_type,
MuttRedrawFlags  redraw 
)

Set redraw flags on a menu.

Parameters
menu_typeMenu 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_type)
1119 }
MuttRedrawFlags redraw
when to redraw the screen
Definition: mutt_menu.h:89
WHERE int CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:86

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_menu_set_redraw_full ( int  menu_type)

Flag a menu to be fully redrawn.

Parameters
menu_typeMenu 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_type)
1131 }
WHERE int CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:86

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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:

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 =
1165  ((menu->menu >= 0) && (menu->menu < MENU_MAX)) ? SearchBuffers[menu->menu] : NULL;
1166 
1167  if (!(search_buf && *search_buf) || ((op != OP_SEARCH_NEXT) && (op != OP_SEARCH_OPPOSITE)))
1168  {
1169  mutt_str_strfcpy(buf, search_buf && *search_buf ? search_buf : "", 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->menu >= 0) && (menu->menu < MENU_MAX))
1179  {
1180  mutt_str_replace(&SearchBuffers[menu->menu], buf);
1181  search_buf = SearchBuffers[menu->menu];
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:67
#define mutt_message(...)
Definition: logging.h:82
#define _(a)
Definition: message.h:28
WHERE bool C_WrapSearch
Config: Wrap around when the search hits the end.
Definition: globals.h:259
int menu
menu definition for keymap entries.
Definition: mutt_menu.h:90
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:86
#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:753
int search_dir
direction of search
Definition: mutt_menu.h:112
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:456
int max
the 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:131
#define mutt_error(...)
Definition: logging.h:83
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:

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:

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

Check if there are any menu key events to process.

Parameters
menuCurrent Menu
ipEvent 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 Event 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  mutt_unget_event(ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
1286  return -1;
1287  }
1288 }
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:700
An event such as a keypress.
Definition: mutt_curses.h:108
struct Event mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:180
char * keys
keys used in the prompt
Definition: mutt_menu.h:107
int ch
raw key pressed
Definition: mutt_curses.h:110

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

1297 {
1298  if (menu->menu_custom_redraw)
1299  {
1300  menu->menu_custom_redraw(menu);
1301  return OP_NULL;
1302  }
1303 
1304  /* See if all or part of the screen needs to be updated. */
1305  if (menu->redraw & REDRAW_FULL)
1306  {
1307  menu_redraw_full(menu);
1308  /* allow the caller to do any local configuration */
1309  return OP_REDRAW;
1310  }
1311 
1312  if (!menu->dialog)
1313  menu_check_recenter(menu);
1314 
1315  if (menu->redraw & REDRAW_STATUS)
1316  menu_redraw_status(menu);
1317 #ifdef USE_SIDEBAR
1318  if (menu->redraw & REDRAW_SIDEBAR)
1319  menu_redraw_sidebar(menu);
1320 #endif
1321  if (menu->redraw & REDRAW_INDEX)
1322  menu_redraw_index(menu);
1323  else if (menu->redraw & (REDRAW_MOTION | REDRAW_MOTION_RESYNC))
1324  menu_redraw_motion(menu);
1325  else if (menu->redraw == REDRAW_CURRENT)
1326  menu_redraw_current(menu);
1327 
1328  if (menu->dialog)
1329  menu_redraw_prompt(menu);
1330 
1331  return OP_NULL;
1332 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:47
char ** dialog
dialog lines themselves
Definition: mutt_menu.h:104
#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:151
#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:

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

1340 {
1341  static int last_position = -1;
1342  int i = OP_NULL;
1343 
1344  if (menu->max && menu->is_mailbox_list)
1345  {
1346  if (last_position > (menu->max - 1))
1347  last_position = -1;
1348  else if (last_position >= 0)
1349  menu->current = last_position;
1350  }
1351 
1352  while (true)
1353  {
1354  if (OptMenuCaller)
1355  {
1356  OptMenuCaller = false;
1357  return OP_NULL;
1358  }
1359 
1360  /* Clear the tag prefix unless we just started it. Don't clear
1361  * the prefix on a timeout (i==-2), but do clear on an abort (i==-1) */
1362  if (menu->tagprefix && (i != OP_TAG_PREFIX) && (i != OP_TAG_PREFIX_COND) && (i != -2))
1363  menu->tagprefix = false;
1364 
1365  mutt_curs_set(0);
1366 
1367  if (menu_redraw(menu) == OP_REDRAW)
1368  return OP_REDRAW;
1369 
1370  /* give visual indication that the next command is a tag- command */
1371  if (menu->tagprefix)
1372  {
1373  mutt_window_mvaddstr(menu->messagewin, 0, 0, "tag-");
1375  }
1376 
1377  menu->oldcurrent = menu->current;
1378 
1379  /* move the cursor out of the way */
1380  if (C_ArrowCursor)
1381  mutt_window_move(menu->indexwin, menu->current - menu->top + menu->offset, 2);
1382  else if (C_BrailleFriendly)
1383  mutt_window_move(menu->indexwin, menu->current - menu->top + menu->offset, 0);
1384  else
1385  {
1386  mutt_window_move(menu->indexwin, menu->current - menu->top + menu->offset,
1387  menu->indexwin->cols - 1);
1388  }
1389 
1390  mutt_refresh();
1391 
1392  /* try to catch dialog keys before ops */
1393  if (menu->dialog && (menu_dialog_dokey(menu, &i) == 0))
1394  return i;
1395 
1396  i = km_dokey(menu->menu);
1397  if ((i == OP_TAG_PREFIX) || (i == OP_TAG_PREFIX_COND))
1398  {
1399  if (menu->tagprefix)
1400  {
1401  menu->tagprefix = false;
1403  continue;
1404  }
1405 
1406  if (menu->tagged)
1407  {
1408  menu->tagprefix = true;
1409  continue;
1410  }
1411  else if (i == OP_TAG_PREFIX)
1412  {
1413  mutt_error(_("No tagged entries"));
1414  i = -1;
1415  }
1416  else /* None tagged, OP_TAG_PREFIX_COND */
1417  {
1419  mutt_message(_("Nothing to do"));
1420  i = -1;
1421  }
1422  }
1423  else if (menu->tagged && C_AutoTag)
1424  menu->tagprefix = true;
1425 
1426  mutt_curs_set(1);
1427 
1428  if (SigWinch)
1429  {
1431  SigWinch = 0;
1432  clearok(stdscr, true); /* force complete redraw */
1433  }
1434 
1435  if (i < 0)
1436  {
1437  if (menu->tagprefix)
1439  continue;
1440  }
1441 
1442  if (!menu->dialog)
1443  mutt_clear_error();
1444 
1445  /* Convert menubar movement to scrolling */
1446  if (menu->dialog)
1447  i = menu_dialog_translate_op(i);
1448 
1449  switch (i)
1450  {
1451  case OP_NEXT_ENTRY:
1452  menu_next_entry(menu);
1453  break;
1454  case OP_PREV_ENTRY:
1455  menu_prev_entry(menu);
1456  break;
1457  case OP_HALF_DOWN:
1458  menu_half_down(menu);
1459  break;
1460  case OP_HALF_UP:
1461  menu_half_up(menu);
1462  break;
1463  case OP_NEXT_PAGE:
1464  menu_next_page(menu);
1465  break;
1466  case OP_PREV_PAGE:
1467  menu_prev_page(menu);
1468  break;
1469  case OP_NEXT_LINE:
1470  menu_next_line(menu);
1471  break;
1472  case OP_PREV_LINE:
1473  menu_prev_line(menu);
1474  break;
1475  case OP_FIRST_ENTRY:
1476  menu_first_entry(menu);
1477  break;
1478  case OP_LAST_ENTRY:
1479  menu_last_entry(menu);
1480  break;
1481  case OP_TOP_PAGE:
1482  menu_top_page(menu);
1483  break;
1484  case OP_MIDDLE_PAGE:
1485  menu_middle_page(menu);
1486  break;
1487  case OP_BOTTOM_PAGE:
1488  menu_bottom_page(menu);
1489  break;
1490  case OP_CURRENT_TOP:
1491  menu_current_top(menu);
1492  break;
1493  case OP_CURRENT_MIDDLE:
1494  menu_current_middle(menu);
1495  break;
1496  case OP_CURRENT_BOTTOM:
1497  menu_current_bottom(menu);
1498  break;
1499  case OP_SEARCH:
1500  case OP_SEARCH_REVERSE:
1501  case OP_SEARCH_NEXT:
1502  case OP_SEARCH_OPPOSITE:
1503  if (menu->menu_search && !menu->dialog) /* Searching dialogs won't work */
1504  {
1505  menu->oldcurrent = menu->current;
1506  menu->current = menu_search(menu, i);
1507  if (menu->current != -1)
1508  menu->redraw = REDRAW_MOTION;
1509  else
1510  menu->current = menu->oldcurrent;
1511  }
1512  else
1513  mutt_error(_("Search is not implemented for this menu"));
1514  break;
1515 
1516  case OP_JUMP:
1517  if (menu->dialog)
1518  mutt_error(_("Jumping is not implemented for dialogs"));
1519  else
1520  menu_jump(menu);
1521  break;
1522 
1523  case OP_ENTER_COMMAND:
1525  break;
1526 
1527  case OP_TAG:
1528  if (menu->menu_tag && !menu->dialog)
1529  {
1530  if (menu->tagprefix && !C_AutoTag)
1531  {
1532  for (i = 0; i < menu->max; i++)
1533  menu->tagged += menu->menu_tag(menu, i, 0);
1534  menu->redraw |= REDRAW_INDEX;
1535  }
1536  else if (menu->max)
1537  {
1538  int j = menu->menu_tag(menu, menu->current, -1);
1539  menu->tagged += j;
1540  if (j && C_Resolve && (menu->current < menu->max - 1))
1541  {
1542  menu->current++;
1543  menu->redraw |= REDRAW_MOTION_RESYNC;
1544  }
1545  else
1546  menu->redraw |= REDRAW_CURRENT;
1547  }
1548  else
1549  mutt_error(_("No entries"));
1550  }
1551  else
1552  mutt_error(_("Tagging is not supported"));
1553  break;
1554 
1555  case OP_SHELL_ESCAPE:
1557  break;
1558 
1559  case OP_WHAT_KEY:
1560  mutt_what_key();
1561  break;
1562 
1563  case OP_CHECK_STATS:
1564  mutt_check_stats();
1565  break;
1566 
1567  case OP_REDRAW:
1568  clearok(stdscr, true);
1569  menu->redraw = REDRAW_FULL;
1570  break;
1571 
1572  case OP_HELP:
1573  mutt_help(menu->menu);
1574  menu->redraw = REDRAW_FULL;
1575  break;
1576 
1577  case OP_NULL:
1578  km_error_key(menu->menu);
1579  break;
1580 
1581  case OP_END_COND:
1582  break;
1583 
1584  default:
1585  if (menu->is_mailbox_list)
1586  last_position = menu->current;
1587  return i;
1588  }
1589  }
1590  /* not reached */
1591 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:47
int km_dokey(int menu)
Determine what a keypress should do.
Definition: keymap.c:569
#define mutt_message(...)
Definition: logging.h:82
int oldcurrent
for driver use only
Definition: mutt_menu.h:111
WHERE bool OptMenuCaller
(pseudo) tell menu to give caller a take
Definition: options.h:37
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:81
void mutt_resize_screen(void)
Update NeoMutt&#39;s opinion about the window size (CURSES)
Definition: resize.c:98
void mutt_check_stats(void)
Forcibly update mailbox stats.
Definition: commands.c:1329
char ** dialog
dialog lines themselves
Definition: mutt_menu.h:104
void mutt_enter_command(void)
enter a neomutt command
Definition: commands.c:818
#define _(a)
Definition: message.h:28
WHERE bool C_BrailleFriendly
Config: Move the cursor to the beginning of the line.
Definition: globals.h:203
int menu
menu definition for keymap entries.
Definition: mutt_menu.h:90
void km_error_key(int menu)
Handle an unbound key sequence.
Definition: keymap.c:1036
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition: curs_lib.c:756
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:69
void mutt_what_key(void)
Ask the user to press a key.
Definition: keymap.c:1555
void mutt_shell_escape(void)
invoke a command in a subshell
Definition: commands.c:790
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: globals.h:84
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:141
#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:99
struct MuttWindow * indexwin
Definition: mutt_menu.h:95
int top
entry that is the top of the current page
Definition: mutt_menu.h:110
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:244
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:190
int tagged
number of tagged entries
Definition: mutt_menu.h:113
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:162
void mutt_help(int menu)
Display the help menu.
Definition: help.c:438
int max
the 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:139
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:131
int offset
row offset within the window to start the index
Definition: mutt_menu.h:91
#define mutt_curs_set(x)
Definition: mutt_curses.h:94
#define REDRAW_INDEX
Redraw the index.
Definition: mutt_menu.h:42
#define mutt_error(...)
Definition: logging.h:83
struct MuttWindow * messagewin
Definition: mutt_menu.h:98
WHERE bool C_AutoTag
Config: Automatically apply actions to all tagged messages.
Definition: globals.h:200
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:195

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool mutt_menu_listener ( const struct ConfigSet cs,
struct HashElem he,
const char *  name,
enum ConfigEvent  ev 
)

Listen for config changes affecting the menu - Implements cs_listener()

Definition at line 1596 of file menu.c.

1598 {
1599  const struct ConfigDef *cdef = he->data;
1600  ConfigRedrawFlags flags = cdef->flags;
1601 
1602  if (flags == 0)
1603  return true;
1604 
1605  if (flags & R_INDEX)
1607  if (flags & R_PAGER)
1609  if (flags & R_PAGER_FLOW)
1610  {
1613  }
1614 
1615  if (flags & R_RESORT_SUB)
1616  OptSortSubthreads = true;
1617  if (flags & R_RESORT)
1618  OptNeedResort = true;
1619  if (flags & R_RESORT_INIT)
1620  OptResortInit = true;
1621  if (flags & R_TREE)
1622  OptRedrawTree = true;
1623 
1624  if (flags & R_REFLOW)
1626 #ifdef USE_SIDEBAR
1627  if (flags & R_SIDEBAR)
1629 #endif
1630  if (flags & R_MENU)
1632 
1633  return true;
1634 }
#define R_PAGER
Redraw the pager menu.
Definition: types.h:62
#define R_PAGER_FLOW
Reflow line_info and redraw the pager menu.
Definition: types.h:63
#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:40
Index panel (list of emails)
Definition: keymap.h:76
Config item definition.
Definition: set.h:162
#define R_RESORT
Resort the mailbox.
Definition: types.h:64
#define REDRAW_SIDEBAR
Redraw the sidebar.
Definition: mutt_menu.h:51
#define R_TREE
Redraw the thread tree.
Definition: types.h:67
Pager pager (email viewer)
Definition: keymap.h:77
void mutt_window_reflow(void)
Resize the Windows to fit the screen.
Definition: mutt_window.c:237
#define R_MENU
Redraw all menus.
Definition: types.h:70
#define R_RESORT_SUB
Resort subthreads.
Definition: types.h:65
#define R_REFLOW
Reflow window layout and full redraw.
Definition: types.h:68
intptr_t flags
Notification flags, see ConfigRedrawFlags.
Definition: set.h:166
WHERE bool OptRedrawTree
(pseudo) redraw the thread tree
Definition: options.h:47
WHERE bool OptResortInit
(pseudo) used to force the next resort to be from scratch
Definition: options.h:48
void * data
Definition: hash.h:46
uint16_t ConfigRedrawFlags
Flags for redraw/resort, e.g. R_INDEX.
Definition: types.h:59
#define R_RESORT_INIT
Resort from scratch.
Definition: types.h:66
WHERE bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition: options.h:51
#define R_SIDEBAR
Redraw the sidebar.
Definition: types.h:69
#define R_INDEX
Redraw the index menu (MENU_MAIN)
Definition: types.h:61

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

short C_MenuContext

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

Definition at line 59 of file menu.c.

bool C_MenuMoveOff

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

Definition at line 60 of file menu.c.

bool C_MenuScroll

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

Definition at line 61 of file menu.c.

char* SearchBuffers[MENU_MAX]

Definition at line 63 of file menu.c.

size_t MenuStackCount = 0
static

Definition at line 66 of file menu.c.

size_t MenuStackLen = 0
static

Definition at line 67 of file menu.c.

struct Menu** MenuStack = NULL
static

Definition at line 68 of file menu.c.