NeoMutt  2018-07-16 +2225-8687db
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 "core/lib.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 "sidebar.h"

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...
 
int mutt_menu_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

#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
Array of Emails.
Definition: mailbox.h:111
Index: subject field (takes a pattern)
Definition: mutt_curses.h:160
The "current" mailbox.
Definition: context.h:39
The envelope/body of an email.
Definition: email.h:37
struct Hash * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:40
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:53
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:2005
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:73
int * v2r
Mapping from virtual to real msgno.
Definition: mailbox.h:113
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:85
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
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:666
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:85
Left T-piece.
Definition: mutt_menu.h:63
Upper left corner.
Definition: mutt_menu.h:62
Horizontal line.
Definition: mutt_menu.h:64
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: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:750
int current
current entry
Definition: mutt_menu.h:87
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: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:988
WHERE bool C_ArrowCursor
Config: Use an arrow &#39;->&#39; instead of highlighting in the index.
Definition: globals.h:195
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:1161
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
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:1161
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
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
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
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
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
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:1505
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
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
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:715
#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:84
int current
current entry
Definition: mutt_menu.h:87
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:83
#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:84
int current
current entry
Definition: mutt_menu.h:87
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:83
#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
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:83
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:84
int current
current entry
Definition: mutt_menu.h:87
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
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
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
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
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
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:84
int current
current entry
Definition: mutt_menu.h:87
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:84
int current
current entry
Definition: mutt_menu.h:87
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:84
int current
current entry
Definition: mutt_menu.h:87
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:84
int current
current entry
Definition: mutt_menu.h:87
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:84
int current
current entry
Definition: mutt_menu.h:87
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:84
int current
current entry
Definition: mutt_menu.h:87
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:84
int current
current entry
Definition: mutt_menu.h:87
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:83
#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
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: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
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
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:36
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 }
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:50
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
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
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:114
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
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 }
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:114
WHERE int CurrentMenu
Current Menu, e.g. MENU_PAGER.
Definition: globals.h:86
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:81
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
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
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
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
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
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[0] != '\0') ? search_buf : "",
1170  sizeof(buf));
1171  if ((mutt_get_field(((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ?
1172  _("Search for: ") :
1173  _("Reverse search for: "),
1174  buf, sizeof(buf), MUTT_CLEAR) != 0) ||
1175  !buf[0])
1176  {
1177  return -1;
1178  }
1179  if ((menu->menu >= 0) && (menu->menu < MENU_MAX))
1180  {
1181  mutt_str_replace(&SearchBuffers[menu->menu], buf);
1182  search_buf = SearchBuffers[menu->menu];
1183  }
1184  menu->search_dir =
1185  ((op == OP_SEARCH) || (op == OP_SEARCH_NEXT)) ? MUTT_SEARCH_DOWN : MUTT_SEARCH_UP;
1186  }
1187 
1188  search_dir = (menu->search_dir == MUTT_SEARCH_UP) ? -1 : 1;
1189  if (op == OP_SEARCH_OPPOSITE)
1190  search_dir = -search_dir;
1191 
1192  if (search_buf)
1193  {
1194  int flags = mutt_mb_is_lower(search_buf) ? REG_ICASE : 0;
1195  rc = REG_COMP(&re, search_buf, REG_NOSUB | flags);
1196  }
1197 
1198  if (rc != 0)
1199  {
1200  regerror(rc, &re, buf, sizeof(buf));
1201  mutt_error("%s", buf);
1202  return -1;
1203  }
1204 
1205  rc = menu->current + search_dir;
1206 search_next:
1207  if (wrap)
1208  mutt_message(_("Search wrapped to top"));
1209  while ((rc >= 0) && (rc < menu->max))
1210  {
1211  if (menu->menu_search(menu, &re, rc) == 0)
1212  {
1213  regfree(&re);
1214  return rc;
1215  }
1216 
1217  rc += search_dir;
1218  }
1219 
1220  if (C_WrapSearch && (wrap++ == 0))
1221  {
1222  rc = (search_dir == 1) ? 0 : menu->max - 1;
1223  goto search_next;
1224  }
1225  regfree(&re);
1226  mutt_error(_("Not found"));
1227  return -1;
1228 }
#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: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:750
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:453
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: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
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 1235 of file menu.c.

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

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

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

1344 {
1345  static int last_position = -1;
1346  int i = OP_NULL;
1347 
1348  if (menu->max && menu->is_mailbox_list)
1349  {
1350  if (last_position > (menu->max - 1))
1351  last_position = -1;
1352  else if (last_position >= 0)
1353  menu->current = last_position;
1354  }
1355 
1356  while (true)
1357  {
1358  if (OptMenuCaller)
1359  {
1360  OptMenuCaller = false;
1361  return OP_NULL;
1362  }
1363 
1364  /* Clear the tag prefix unless we just started it. Don't clear
1365  * the prefix on a timeout (i==-2), but do clear on an abort (i==-1) */
1366  if (menu->tagprefix && (i != OP_TAG_PREFIX) && (i != OP_TAG_PREFIX_COND) && (i != -2))
1367  menu->tagprefix = false;
1368 
1369  mutt_curs_set(0);
1370 
1371  if (menu_redraw(menu) == OP_REDRAW)
1372  return OP_REDRAW;
1373 
1374  /* give visual indication that the next command is a tag- command */
1375  if (menu->tagprefix)
1376  {
1377  mutt_window_mvaddstr(menu->messagewin, 0, 0, "tag-");
1379  }
1380 
1381  menu->oldcurrent = menu->current;
1382 
1383  /* move the cursor out of the way */
1384  if (C_ArrowCursor)
1385  mutt_window_move(menu->indexwin, menu->current - menu->top + menu->offset, 2);
1386  else if (C_BrailleFriendly)
1387  mutt_window_move(menu->indexwin, menu->current - menu->top + menu->offset, 0);
1388  else
1389  {
1390  mutt_window_move(menu->indexwin, menu->current - menu->top + menu->offset,
1391  menu->indexwin->cols - 1);
1392  }
1393 
1394  mutt_refresh();
1395 
1396  /* try to catch dialog keys before ops */
1397  if (menu->dialog && (menu_dialog_dokey(menu, &i) == 0))
1398  return i;
1399 
1400  i = km_dokey(menu->menu);
1401  if ((i == OP_TAG_PREFIX) || (i == OP_TAG_PREFIX_COND))
1402  {
1403  if (menu->tagprefix)
1404  {
1405  menu->tagprefix = false;
1407  continue;
1408  }
1409 
1410  if (menu->tagged)
1411  {
1412  menu->tagprefix = true;
1413  continue;
1414  }
1415  else if (i == OP_TAG_PREFIX)
1416  {
1417  mutt_error(_("No tagged entries"));
1418  i = -1;
1419  }
1420  else /* None tagged, OP_TAG_PREFIX_COND */
1421  {
1423  mutt_message(_("Nothing to do"));
1424  i = -1;
1425  }
1426  }
1427  else if (menu->tagged && C_AutoTag)
1428  menu->tagprefix = true;
1429 
1430  mutt_curs_set(1);
1431 
1432  if (SigWinch)
1433  {
1435  SigWinch = 0;
1436  clearok(stdscr, true); /* force complete redraw */
1437  }
1438 
1439  if (i < 0)
1440  {
1441  if (menu->tagprefix)
1443  continue;
1444  }
1445 
1446  if (!menu->dialog)
1447  mutt_clear_error();
1448 
1449  /* Convert menubar movement to scrolling */
1450  if (menu->dialog)
1451  i = menu_dialog_translate_op(i);
1452 
1453  switch (i)
1454  {
1455  case OP_NEXT_ENTRY:
1456  menu_next_entry(menu);
1457  break;
1458  case OP_PREV_ENTRY:
1459  menu_prev_entry(menu);
1460  break;
1461  case OP_HALF_DOWN:
1462  menu_half_down(menu);
1463  break;
1464  case OP_HALF_UP:
1465  menu_half_up(menu);
1466  break;
1467  case OP_NEXT_PAGE:
1468  menu_next_page(menu);
1469  break;
1470  case OP_PREV_PAGE:
1471  menu_prev_page(menu);
1472  break;
1473  case OP_NEXT_LINE:
1474  menu_next_line(menu);
1475  break;
1476  case OP_PREV_LINE:
1477  menu_prev_line(menu);
1478  break;
1479  case OP_FIRST_ENTRY:
1480  menu_first_entry(menu);
1481  break;
1482  case OP_LAST_ENTRY:
1483  menu_last_entry(menu);
1484  break;
1485  case OP_TOP_PAGE:
1486  menu_top_page(menu);
1487  break;
1488  case OP_MIDDLE_PAGE:
1489  menu_middle_page(menu);
1490  break;
1491  case OP_BOTTOM_PAGE:
1492  menu_bottom_page(menu);
1493  break;
1494  case OP_CURRENT_TOP:
1495  menu_current_top(menu);
1496  break;
1497  case OP_CURRENT_MIDDLE:
1498  menu_current_middle(menu);
1499  break;
1500  case OP_CURRENT_BOTTOM:
1501  menu_current_bottom(menu);
1502  break;
1503  case OP_SEARCH:
1504  case OP_SEARCH_REVERSE:
1505  case OP_SEARCH_NEXT:
1506  case OP_SEARCH_OPPOSITE:
1507  if (menu->menu_search && !menu->dialog) /* Searching dialogs won't work */
1508  {
1509  menu->oldcurrent = menu->current;
1510  menu->current = menu_search(menu, i);
1511  if (menu->current != -1)
1512  menu->redraw = REDRAW_MOTION;
1513  else
1514  menu->current = menu->oldcurrent;
1515  }
1516  else
1517  mutt_error(_("Search is not implemented for this menu"));
1518  break;
1519 
1520  case OP_JUMP:
1521  if (menu->dialog)
1522  mutt_error(_("Jumping is not implemented for dialogs"));
1523  else
1524  menu_jump(menu);
1525  break;
1526 
1527  case OP_ENTER_COMMAND:
1529  break;
1530 
1531  case OP_TAG:
1532  if (menu->menu_tag && !menu->dialog)
1533  {
1534  if (menu->tagprefix && !C_AutoTag)
1535  {
1536  for (i = 0; i < menu->max; i++)
1537  menu->tagged += menu->menu_tag(menu, i, 0);
1538  menu->redraw |= REDRAW_INDEX;
1539  }
1540  else if (menu->max)
1541  {
1542  int j = menu->menu_tag(menu, menu->current, -1);
1543  menu->tagged += j;
1544  if (j && C_Resolve && (menu->current < menu->max - 1))
1545  {
1546  menu->current++;
1547  menu->redraw |= REDRAW_MOTION_RESYNC;
1548  }
1549  else
1550  menu->redraw |= REDRAW_CURRENT;
1551  }
1552  else
1553  mutt_error(_("No entries"));
1554  }
1555  else
1556  mutt_error(_("Tagging is not supported"));
1557  break;
1558 
1559  case OP_SHELL_ESCAPE:
1561  break;
1562 
1563  case OP_WHAT_KEY:
1564  mutt_what_key();
1565  break;
1566 
1567  case OP_CHECK_STATS:
1568  mutt_check_stats();
1569  break;
1570 
1571  case OP_REDRAW:
1572  clearok(stdscr, true);
1573  menu->redraw = REDRAW_FULL;
1574  break;
1575 
1576  case OP_HELP:
1577  mutt_help(menu->menu);
1578  menu->redraw = REDRAW_FULL;
1579  break;
1580 
1581  case OP_NULL:
1582  km_error_key(menu->menu);
1583  break;
1584 
1585  case OP_END_COND:
1586  break;
1587 
1588  default:
1589  if (menu->is_mailbox_list)
1590  last_position = menu->current;
1591  return i;
1592  }
1593  }
1594  /* not reached */
1595 }
#define REDRAW_FULL
Redraw everything.
Definition: mutt_menu.h:47
int km_dokey(int menu)
Determine what a keypress should do.
Definition: keymap.c:570
#define mutt_message(...)
Definition: logging.h:83
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:1339
char ** dialog
dialog lines themselves
Definition: mutt_menu.h:104
void mutt_enter_command(void)
enter a neomutt command
Definition: commands.c:820
#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:1037
void mutt_flush_macro_to_endcond(void)
Drop a macro from the input buffer.
Definition: curs_lib.c:771
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:1557
void mutt_shell_escape(void)
invoke a command in a subshell
Definition: commands.c:792
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:84
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
int mutt_menu_observer ( struct NotifyCallback nc)

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

Definition at line 1600 of file menu.c.

1601 {
1602  if (!nc)
1603  return -1;
1604 
1605  struct EventConfig *ec = (struct EventConfig *) nc->event;
1606 
1607  const struct ConfigDef *cdef = ec->he->data;
1608  ConfigRedrawFlags flags = cdef->type & R_REDRAW_MASK;
1609 
1610  if (flags == R_REDRAW_NO_FLAGS)
1611  return 0;
1612 
1613  if (flags & R_INDEX)
1615  if (flags & R_PAGER)
1617  if (flags & R_PAGER_FLOW)
1618  {
1621  }
1622 
1623  if (flags & R_RESORT_SUB)
1624  OptSortSubthreads = true;
1625  if (flags & R_RESORT)
1626  OptNeedResort = true;
1627  if (flags & R_RESORT_INIT)
1628  OptResortInit = true;
1629  if (flags & R_TREE)
1630  OptRedrawTree = true;
1631 
1632  if (flags & R_REFLOW)
1634 #ifdef USE_SIDEBAR
1635  if (flags & R_SIDEBAR)
1637 #endif
1638  if (flags & R_MENU)
1640 
1641  return 0;
1642 }
#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:40
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:76
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:77
#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:237
#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: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
#define R_RESORT_INIT
Resort from scratch.
Definition: types.h:68
WHERE bool OptSortSubthreads
(pseudo) used when $sort_aux changes
Definition: options.h:51
#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

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.