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

Paint the Menu. More...

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

Go to the source code of this file.

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 (struct MuttWindow *win, int index, int attr, unsigned char *s, bool do_color, struct ConfigSubset *sub)
 Display a string with embedded colours and graphics. More...
 
void menu_make_entry (struct Menu *menu, char *buf, size_t buflen, int i)
 Create string to display in a Menu (the index) More...
 
static void menu_pad_string (struct Menu *menu, char *buf, size_t buflen)
 Pad a string with spaces for display in the Menu. More...
 
void menu_redraw_full (struct Menu *menu)
 Force the redraw of the Menu. More...
 
void menu_redraw_status (struct Menu *menu)
 Force the redraw of the status bar. More...
 
void menu_redraw_index (struct Menu *menu)
 Force the redraw of the index. More...
 
void menu_redraw_motion (struct Menu *menu)
 Force the redraw of the list part of the menu. More...
 
void menu_redraw_current (struct Menu *menu)
 Redraw the current menu. More...
 
static void menu_redraw_prompt (struct Menu *menu)
 Force the redraw of the message window. More...
 
int menu_redraw (struct Menu *menu)
 Redraw the parts of the screen that have been flagged to be redrawn. More...
 

Detailed Description

Paint the Menu.

Authors
  • Richard Russon

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

Function Documentation

◆ get_color()

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

Choose a colour for a line of the index.

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

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

Definition at line 57 of file draw.c.

58 {
59  struct ColorLineList *color = NULL;
60  struct ColorLine *np = NULL;
62  int type = *s;
63 
64  switch (type)
65  {
67  color = mutt_color_index_author();
68  break;
70  color = mutt_color_index_flags();
71  break;
73  color = mutt_color_index_subject();
74  break;
75  case MT_COLOR_INDEX_TAG:
77  {
78  if (mutt_strn_equal((const char *) (s + 1), np->pattern, strlen(np->pattern)))
79  return np->pair;
80  const char *transform = mutt_hash_find(TagTransforms, np->pattern);
81  if (transform && mutt_strn_equal((const char *) (s + 1), transform, strlen(transform)))
82  {
83  return np->pair;
84  }
85  }
86  return 0;
87  default:
88  return mutt_color(type);
89  }
90 
91  STAILQ_FOREACH(np, color, entries)
92  {
95  {
96  return np->pair;
97  }
98  }
99 
100  return 0;
101 }
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
Definition: hash.c:354
The "current" mailbox.
Definition: context.h:37
The envelope/body of an email.
Definition: email.h:37
struct Email * mutt_get_virt_email(struct Mailbox *m, int vnum)
Get a virtual Email.
Definition: context.c:412
struct ColorLineList * mutt_color_index_subject(void)
Return the ColorLineList for subject in the index.
Definition: color.c:1499
struct ColorLineList * mutt_color_index_flags(void)
Return the ColorLineList for flags in the index.
Definition: color.c:1490
struct PatternList * color_pattern
Compiled pattern to speed up index color calculation.
Definition: color.h:104
char * pattern
Pattern to match.
Definition: color.h:103
int pair
Colour pair index.
Definition: color.h:107
struct ColorLineList * mutt_color_index_tags(void)
Return the ColorLineList for tags in the index.
Definition: color.c:1508
Index: author field (takes a pattern)
Definition: color.h:82
struct Mailbox * mailbox
Definition: context.h:49
Index: tag field (g, takes a pattern)
Definition: color.h:85
struct ColorLineList * mutt_color_index_author(void)
Return the ColorLineList for author in the index.
Definition: color.c:1481
#define SLIST_FIRST(head)
Definition: queue.h:229
struct HashTable * TagTransforms
Lookup table of alternative tag names.
Definition: tags.c:37
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
int mutt_color(enum ColorId id)
Return the color of an object.
Definition: color.c:1427
int mutt_pattern_exec(struct Pattern *pat, PatternExecFlags flags, struct Mailbox *m, struct Email *e, struct PatternCache *cache)
Match a pattern against an email header.
Definition: exec.c:1097
Index: subject field (takes a pattern)
Definition: color.h:84
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
Definition: string.c:593
int index
The absolute (unsorted) message number.
Definition: email.h:86
#define MUTT_MATCH_FULL_ADDRESS
Match the full address.
Definition: lib.h:95
Index: flags field (takes a pattern)
Definition: color.h:83
A regular expression and a color to highlight a line.
Definition: color.h:99
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_enriched_string()

static void print_enriched_string ( struct MuttWindow win,
int  index,
int  attr,
unsigned char *  s,
bool  do_color,
struct ConfigSubset sub 
)
static

Display a string with embedded colours and graphics.

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

Definition at line 112 of file draw.c.

114 {
115  wchar_t wc;
116  size_t k;
117  size_t n = mutt_str_len((char *) s);
118  mbstate_t mbstate;
119 
120  const bool c_ascii_chars = cs_subset_bool(sub, "ascii_chars");
121  memset(&mbstate, 0, sizeof(mbstate));
122  while (*s)
123  {
124  if (*s < MUTT_TREE_MAX)
125  {
126  if (do_color)
127  {
128 #if defined(HAVE_COLOR) && defined(HAVE_USE_DEFAULT_COLORS)
129  /* Combining tree fg color and another bg color requires having
130  * use_default_colors, because the other bg color may be undefined. */
132 #else
134 #endif
135  }
136 
137  while (*s && (*s < MUTT_TREE_MAX))
138  {
139  switch (*s)
140  {
141  case MUTT_TREE_LLCORNER:
142  if (c_ascii_chars)
143  mutt_window_addch(win, '`');
144 #ifdef WACS_LLCORNER
145  else
146  add_wch(WACS_LLCORNER);
147 #else
148  else if (CharsetIsUtf8)
149  mutt_window_addstr(win, "\342\224\224"); /* WACS_LLCORNER */
150  else
151  mutt_window_addch(win, ACS_LLCORNER);
152 #endif
153  break;
154  case MUTT_TREE_ULCORNER:
155  if (c_ascii_chars)
156  mutt_window_addch(win, ',');
157 #ifdef WACS_ULCORNER
158  else
159  add_wch(WACS_ULCORNER);
160 #else
161  else if (CharsetIsUtf8)
162  mutt_window_addstr(win, "\342\224\214"); /* WACS_ULCORNER */
163  else
164  mutt_window_addch(win, ACS_ULCORNER);
165 #endif
166  break;
167  case MUTT_TREE_LTEE:
168  if (c_ascii_chars)
169  mutt_window_addch(win, '|');
170 #ifdef WACS_LTEE
171  else
172  add_wch(WACS_LTEE);
173 #else
174  else if (CharsetIsUtf8)
175  mutt_window_addstr(win, "\342\224\234"); /* WACS_LTEE */
176  else
177  mutt_window_addch(win, ACS_LTEE);
178 #endif
179  break;
180  case MUTT_TREE_HLINE:
181  if (c_ascii_chars)
182  mutt_window_addch(win, '-');
183 #ifdef WACS_HLINE
184  else
185  add_wch(WACS_HLINE);
186 #else
187  else if (CharsetIsUtf8)
188  mutt_window_addstr(win, "\342\224\200"); /* WACS_HLINE */
189  else
190  mutt_window_addch(win, ACS_HLINE);
191 #endif
192  break;
193  case MUTT_TREE_VLINE:
194  if (c_ascii_chars)
195  mutt_window_addch(win, '|');
196 #ifdef WACS_VLINE
197  else
198  add_wch(WACS_VLINE);
199 #else
200  else if (CharsetIsUtf8)
201  mutt_window_addstr(win, "\342\224\202"); /* WACS_VLINE */
202  else
203  mutt_window_addch(win, ACS_VLINE);
204 #endif
205  break;
206  case MUTT_TREE_TTEE:
207  if (c_ascii_chars)
208  mutt_window_addch(win, '-');
209 #ifdef WACS_TTEE
210  else
211  add_wch(WACS_TTEE);
212 #else
213  else if (CharsetIsUtf8)
214  mutt_window_addstr(win, "\342\224\254"); /* WACS_TTEE */
215  else
216  mutt_window_addch(win, ACS_TTEE);
217 #endif
218  break;
219  case MUTT_TREE_BTEE:
220  if (c_ascii_chars)
221  mutt_window_addch(win, '-');
222 #ifdef WACS_BTEE
223  else
224  add_wch(WACS_BTEE);
225 #else
226  else if (CharsetIsUtf8)
227  mutt_window_addstr(win, "\342\224\264"); /* WACS_BTEE */
228  else
229  mutt_window_addch(win, ACS_BTEE);
230 #endif
231  break;
232  case MUTT_TREE_SPACE:
233  mutt_window_addch(win, ' ');
234  break;
235  case MUTT_TREE_RARROW:
236  mutt_window_addch(win, '>');
237  break;
238  case MUTT_TREE_STAR:
239  mutt_window_addch(win, '*'); /* fake thread indicator */
240  break;
241  case MUTT_TREE_HIDDEN:
242  mutt_window_addch(win, '&');
243  break;
244  case MUTT_TREE_EQUALS:
245  mutt_window_addch(win, '=');
246  break;
247  case MUTT_TREE_MISSING:
248  mutt_window_addch(win, '?');
249  break;
250  }
251  s++;
252  n--;
253  }
254  if (do_color)
255  mutt_curses_set_attr(attr);
256  }
257  else if (*s == MUTT_SPECIAL_INDEX)
258  {
259  s++;
260  if (do_color)
261  {
262  if (*s == MT_COLOR_INDEX)
263  {
264  attrset(attr);
265  }
266  else
267  {
268  if (get_color(index, s) == 0)
269  {
270  attron(attr);
271  }
272  else
273  {
274  attron(get_color(index, s));
275  }
276  }
277  }
278  s++;
279  n -= 2;
280  }
281  else if ((k = mbrtowc(&wc, (char *) s, n, &mbstate)) > 0)
282  {
283  mutt_window_addnstr(win, (char *) s, k);
284  s += k;
285  n -= k;
286  }
287  else
288  break;
289  }
290 }
Star character (for threads)
Definition: mutt_thread.h:49
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Ampersand character (for threads)
Definition: mutt_thread.h:50
static int get_color(int index, unsigned char *s)
Choose a colour for a line of the index.
Definition: draw.c:57
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:56
Lower left corner.
Definition: mutt_thread.h:42
Top T-piece.
Definition: mutt_thread.h:52
int mutt_window_addstr(struct MuttWindow *win, const char *str)
Write a string to a Window.
Definition: mutt_window.c:434
Index: tree-drawing characters.
Definition: color.h:77
Vertical line.
Definition: mutt_thread.h:46
Right arrow.
Definition: mutt_thread.h:48
Bottom T-piece.
Definition: mutt_thread.h:53
Left T-piece.
Definition: mutt_thread.h:44
Upper left corner.
Definition: mutt_thread.h:43
int mutt_color(enum ColorId id)
Return the color of an object.
Definition: color.c:1427
bool CharsetIsUtf8
Is the user&#39;s current character set utf-8?
Definition: charset.c:62
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:664
Horizontal line.
Definition: mutt_thread.h:45
int index
The absolute (unsorted) message number.
Definition: email.h:86
Colour indicator.
Definition: mutt_thread.h:57
int mutt_window_addnstr(struct MuttWindow *win, const char *str, int num)
Write a partial string to a Window.
Definition: mutt_window.c:415
Index: default colour (takes a pattern)
Definition: color.h:81
Blank space.
Definition: mutt_thread.h:47
int mutt_color_combine(uint32_t fg_attr, uint32_t bg_attr)
Combine two colours.
Definition: color.c:581
void mutt_curses_set_attr(int attr)
Set the attributes for text.
Definition: mutt_curses.c:39
Question mark.
Definition: mutt_thread.h:54
int mutt_window_addch(struct MuttWindow *win, int ch)
Write one character to a Window.
Definition: mutt_window.c:402
Equals (for threads)
Definition: mutt_thread.h:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_make_entry()

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

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 299 of file draw.c.

300 {
301  if (!ARRAY_EMPTY(&menu->dialog))
302  {
303  mutt_str_copy(buf, NONULL(*ARRAY_GET(&menu->dialog, i)), buflen);
304  menu->current = -1; /* hide menubar */
305  }
306  else
307  menu->make_entry(menu, buf, buflen, i);
308 }
#define NONULL(x)
Definition: string2.h:37
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:105
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:105
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:749
int current
Current entry.
Definition: lib.h:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_pad_string()

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

Pad a string with spaces for display in the Menu.

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

Definition at line 318 of file draw.c.

319 {
320  char *scratch = mutt_str_dup(buf);
321  const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
322  const char *const c_arrow_string =
323  cs_subset_string(menu->sub, "arrow_string");
324  int shift = c_arrow_cursor ? mutt_strwidth(c_arrow_string) + 1 : 0;
325  int cols = menu->win->state.cols - shift;
326 
327  mutt_simple_format(buf, buflen, cols, cols, JUSTIFY_LEFT, ' ', scratch,
328  mutt_str_len(scratch), true);
329  buf[buflen - 1] = '\0';
330  FREE(&scratch);
331 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
Left justify the text.
Definition: curs_lib.h:43
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
int mutt_strwidth(const char *s)
Measure a string&#39;s width in screen cells.
Definition: curs_lib.c:983
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:664
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:78
#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:716
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_full()

void menu_redraw_full ( struct Menu menu)

Force the redraw of the Menu.

Parameters
menuCurrent Menu

Definition at line 337 of file draw.c.

338 {
340  mutt_window_clear(menu->win);
341 
342  window_redraw(NULL);
343  menu->pagelen = menu->win->state.rows;
344 
346 }
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:56
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:72
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:632
void mutt_window_clear(struct MuttWindow *win)
Clear a Window.
Definition: mutt_window.c:716
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
Plain text.
Definition: color.h:58
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
short rows
Number of rows, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:61
int pagelen
Number of entries per screen.
Definition: lib.h:74
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_status()

void menu_redraw_status ( struct Menu menu)

Force the redraw of the status bar.

Parameters
menuCurrent Menu

Definition at line 352 of file draw.c.

353 {
354  if (!menu || !menu->win_ibar)
355  return;
356 
357  char buf[256];
358 
359  snprintf(buf, sizeof(buf), "-- NeoMutt: %s", menu->title);
361  mutt_window_move(menu->win_ibar, 0, 0);
362  mutt_paddstr(menu->win_ibar, menu->win_ibar->state.cols, buf);
364  menu->redraw &= ~MENU_REDRAW_STATUS;
365 }
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:56
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:72
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:310
struct MuttWindow * win_ibar
Definition: lib.h:77
const char * title
Title of this menu.
Definition: lib.h:69
Plain text.
Definition: color.h:58
short cols
Number of columns, can be MUTT_WIN_SIZE_UNLIMITED.
Definition: mutt_window.h:60
struct WindowState state
Current state of the Window.
Definition: mutt_window.h:127
Status bar (takes a pattern)
Definition: color.h:75
void mutt_paddstr(struct MuttWindow *win, int n, const char *s)
Display a string on screen, padded if necessary.
Definition: curs_lib.c:890
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_index()

void menu_redraw_index ( struct Menu menu)

Force the redraw of the index.

Parameters
menuCurrent Menu

Definition at line 371 of file draw.c.

372 {
373  char buf[1024];
374  bool do_color;
375  int attr;
376 
377  for (int i = menu->top; i < (menu->top + menu->pagelen); i++)
378  {
379  if (i < menu->max)
380  {
381  attr = menu->color(menu, i);
382 
383  menu_make_entry(menu, buf, sizeof(buf), i);
384  menu_pad_string(menu, buf, sizeof(buf));
385 
386  mutt_curses_set_attr(attr);
387  mutt_window_move(menu->win, 0, i - menu->top);
388  do_color = true;
389 
390  const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
391  const char *const c_arrow_string =
392  cs_subset_string(menu->sub, "arrow_string");
393  if (i == menu->current)
394  {
396  if (c_arrow_cursor)
397  {
398  mutt_window_addstr(menu->win, c_arrow_string);
399  mutt_curses_set_attr(attr);
400  mutt_window_addch(menu->win, ' ');
401  }
402  else
403  do_color = false;
404  }
405  else if (c_arrow_cursor)
406  {
407  /* Print space chars to match the screen width of `$arrow_string` */
408  mutt_window_printf(menu->win, "%*s", mutt_strwidth(c_arrow_string) + 1, "");
409  }
410 
411  print_enriched_string(menu->win, i, attr, (unsigned char *) buf, do_color, menu->sub);
412  }
413  else
414  {
416  mutt_window_clearline(menu->win, i - menu->top);
417  }
418  }
421 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
void menu_make_entry(struct Menu *menu, char *buf, size_t buflen, int i)
Create string to display in a Menu (the index)
Definition: draw.c:299
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:56
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:72
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:310
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:247
int mutt_window_addstr(struct MuttWindow *win, const char *str)
Write a string to a Window.
Definition: mutt_window.c:434
Plain text.
Definition: color.h:58
int mutt_strwidth(const char *s)
Measure a string&#39;s width in screen cells.
Definition: curs_lib.c:983
int mutt_window_printf(struct MuttWindow *win, const char *fmt,...)
Write a formatted string to a Window.
Definition: mutt_window.c:453
int top
Entry that is the top of the current page.
Definition: lib.h:89
static void menu_pad_string(struct Menu *menu, char *buf, size_t buflen)
Pad a string with spaces for display in the Menu.
Definition: draw.c:318
Selected item in list.
Definition: color.h:54
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
int pagelen
Number of entries per screen.
Definition: lib.h:74
static void print_enriched_string(struct MuttWindow *win, int index, int attr, unsigned char *s, bool do_color, struct ConfigSubset *sub)
Display a string with embedded colours and graphics.
Definition: draw.c:112
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:78
int current
Current entry.
Definition: lib.h:70
void mutt_curses_set_attr(int attr)
Set the attributes for text.
Definition: mutt_curses.c:39
int mutt_window_addch(struct MuttWindow *win, int ch)
Write one character to a Window.
Definition: mutt_window.c:402
int(* color)(struct Menu *menu, int line)
Definition: lib.h:142
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_motion()

void menu_redraw_motion ( struct Menu menu)

Force the redraw of the list part of the menu.

Parameters
menuCurrent Menu

Definition at line 427 of file draw.c.

428 {
429  char buf[1024];
430 
431  if (!ARRAY_EMPTY(&menu->dialog))
432  {
433  menu->redraw &= ~MENU_REDRAW_MOTION;
434  return;
435  }
436 
437  /* Note: menu->color() for the index can end up retrieving a message
438  * over imap (if matching against ~h for instance). This can
439  * generate status messages. So we want to call it *before* we
440  * position the cursor for drawing. */
441  const int old_color = menu->color(menu, menu->oldcurrent);
442  mutt_window_move(menu->win, 0, menu->oldcurrent - menu->top);
443  mutt_curses_set_attr(old_color);
444 
445  const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
446  const char *const c_arrow_string =
447  cs_subset_string(menu->sub, "arrow_string");
448  if (c_arrow_cursor)
449  {
450  /* clear the arrow */
451  /* Print space chars to match the screen width of `$arrow_string` */
452  mutt_window_printf(menu->win, "%*s", mutt_strwidth(c_arrow_string) + 1, "");
453 
454  menu_make_entry(menu, buf, sizeof(buf), menu->oldcurrent);
455  menu_pad_string(menu, buf, sizeof(buf));
456  mutt_window_move(menu->win, mutt_strwidth(c_arrow_string) + 1,
457  menu->oldcurrent - menu->top);
458  print_enriched_string(menu->win, menu->oldcurrent, old_color,
459  (unsigned char *) buf, true, menu->sub);
460 
461  /* now draw it in the new location */
463  mutt_window_mvaddstr(menu->win, 0, menu->current - menu->top, c_arrow_string);
464  }
465  else
466  {
467  /* erase the current indicator */
468  menu_make_entry(menu, buf, sizeof(buf), menu->oldcurrent);
469  menu_pad_string(menu, buf, sizeof(buf));
470  print_enriched_string(menu->win, menu->oldcurrent, old_color,
471  (unsigned char *) buf, true, menu->sub);
472 
473  /* now draw the new one to reflect the change */
474  const int cur_color = menu->color(menu, menu->current);
475  menu_make_entry(menu, buf, sizeof(buf), menu->current);
476  menu_pad_string(menu, buf, sizeof(buf));
478  mutt_window_move(menu->win, 0, menu->current - menu->top);
479  print_enriched_string(menu->win, menu->current, cur_color,
480  (unsigned char *) buf, false, menu->sub);
481  }
482  menu->redraw &= MENU_REDRAW_STATUS;
484 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
void menu_make_entry(struct Menu *menu, char *buf, size_t buflen, int i)
Create string to display in a Menu (the index)
Definition: draw.c:299
int oldcurrent
For driver use only.
Definition: lib.h:90
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:56
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:72
int mutt_window_mvaddstr(struct MuttWindow *win, int col, int row, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:324
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:310
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
Plain text.
Definition: color.h:58
int mutt_strwidth(const char *s)
Measure a string&#39;s width in screen cells.
Definition: curs_lib.c:983
int mutt_window_printf(struct MuttWindow *win, const char *fmt,...)
Write a formatted string to a Window.
Definition: mutt_window.c:453
int top
Entry that is the top of the current page.
Definition: lib.h:89
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
static void menu_pad_string(struct Menu *menu, char *buf, size_t buflen)
Pad a string with spaces for display in the Menu.
Definition: draw.c:318
Selected item in list.
Definition: color.h:54
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
static void print_enriched_string(struct MuttWindow *win, int index, int attr, unsigned char *s, bool do_color, struct ConfigSubset *sub)
Display a string with embedded colours and graphics.
Definition: draw.c:112
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:78
int current
Current entry.
Definition: lib.h:70
void mutt_curses_set_attr(int attr)
Set the attributes for text.
Definition: mutt_curses.c:39
int(* color)(struct Menu *menu, int line)
Definition: lib.h:142
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_current()

void menu_redraw_current ( struct Menu menu)

Redraw the current menu.

Parameters
menuCurrent Menu

Definition at line 490 of file draw.c.

491 {
492  char buf[1024];
493  int attr = menu->color(menu, menu->current);
494 
495  mutt_window_move(menu->win, 0, menu->current - menu->top);
496  menu_make_entry(menu, buf, sizeof(buf), menu->current);
497  menu_pad_string(menu, buf, sizeof(buf));
498 
500  const bool c_arrow_cursor = cs_subset_bool(menu->sub, "arrow_cursor");
501  const char *const c_arrow_string =
502  cs_subset_string(menu->sub, "arrow_string");
503  if (c_arrow_cursor)
504  {
505  mutt_window_addstr(menu->win, c_arrow_string);
506  mutt_curses_set_attr(attr);
507  mutt_window_addch(menu->win, ' ');
508  menu_pad_string(menu, buf, sizeof(buf));
509  print_enriched_string(menu->win, menu->current, attr, (unsigned char *) buf,
510  true, menu->sub);
511  }
512  else
513  print_enriched_string(menu->win, menu->current, attr, (unsigned char *) buf,
514  false, menu->sub);
515  menu->redraw &= MENU_REDRAW_STATUS;
517 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
void menu_make_entry(struct Menu *menu, char *buf, size_t buflen, int i)
Create string to display in a Menu (the index)
Definition: draw.c:299
void mutt_curses_set_color(enum ColorId color)
Set the current colour for text.
Definition: mutt_curses.c:56
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:72
int mutt_window_move(struct MuttWindow *win, int col, int row)
Move the cursor in a Window.
Definition: mutt_window.c:310
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
int mutt_window_addstr(struct MuttWindow *win, const char *str)
Write a string to a Window.
Definition: mutt_window.c:434
Plain text.
Definition: color.h:58
int top
Entry that is the top of the current page.
Definition: lib.h:89
static void menu_pad_string(struct Menu *menu, char *buf, size_t buflen)
Pad a string with spaces for display in the Menu.
Definition: draw.c:318
Selected item in list.
Definition: color.h:54
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
static void print_enriched_string(struct MuttWindow *win, int index, int attr, unsigned char *s, bool do_color, struct ConfigSubset *sub)
Display a string with embedded colours and graphics.
Definition: draw.c:112
struct ConfigSubset * sub
Inherited config items.
Definition: lib.h:78
int current
Current entry.
Definition: lib.h:70
void mutt_curses_set_attr(int attr)
Set the attributes for text.
Definition: mutt_curses.c:39
int mutt_window_addch(struct MuttWindow *win, int ch)
Write one character to a Window.
Definition: mutt_window.c:402
int(* color)(struct Menu *menu, int line)
Definition: lib.h:142
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw_prompt()

static void menu_redraw_prompt ( struct Menu menu)
static

Force the redraw of the message window.

Parameters
menuCurrent Menu

Definition at line 523 of file draw.c.

524 {
525  if (!menu || ARRAY_EMPTY(&menu->dialog))
526  return;
527 
528  if (OptMsgErr)
529  {
530  mutt_sleep(1);
531  OptMsgErr = false;
532  }
533 
534  if (ErrorBufMessage)
536 
538 }
char * prompt
Prompt for user, similar to mutt_multi_choice.
Definition: lib.h:85
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1461
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:112
Plain text.
Definition: color.h:58
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
WHERE bool OptMsgErr
(pseudo) used by mutt_error/mutt_message
Definition: options.h:40
WHERE bool ErrorBufMessage
true if the last message was an error
Definition: mutt_globals.h:42
void msgwin_set_text(enum ColorId color, const char *text)
Set the text for the Message Window.
Definition: msgwin.c:223
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ menu_redraw()

int menu_redraw ( struct Menu menu)

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

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

Definition at line 546 of file draw.c.

547 {
548  if (menu->custom_redraw)
549  {
550  menu->custom_redraw(menu);
551  return OP_NULL;
552  }
553 
554  /* See if all or part of the screen needs to be updated. */
555  if (menu->redraw & MENU_REDRAW_FULL)
556  {
557  menu_redraw_full(menu);
558  /* allow the caller to do any local configuration */
559  return OP_REDRAW;
560  }
561 
562  if (menu->redraw & MENU_REDRAW_STATUS)
563  menu_redraw_status(menu);
564  if (menu->redraw & MENU_REDRAW_INDEX)
565  menu_redraw_index(menu);
566  else if (menu->redraw & MENU_REDRAW_MOTION)
567  menu_redraw_motion(menu);
568  else if (menu->redraw == MENU_REDRAW_CURRENT)
569  menu_redraw_current(menu);
570 
571  if (!ARRAY_EMPTY(&menu->dialog))
572  menu_redraw_prompt(menu);
573 
574  return OP_NULL;
575 }
void menu_redraw_motion(struct Menu *menu)
Force the redraw of the list part of the menu.
Definition: draw.c:427
MenuRedrawFlags redraw
When to redraw the screen.
Definition: lib.h:72
static void menu_redraw_prompt(struct Menu *menu)
Force the redraw of the message window.
Definition: draw.c:523
void menu_redraw_status(struct Menu *menu)
Force the redraw of the status bar.
Definition: draw.c:352
#define ARRAY_EMPTY(head)
Check if an array is empty.
Definition: array.h:70
void(* custom_redraw)(struct Menu *menu)
Definition: lib.h:151
void menu_redraw_index(struct Menu *menu)
Force the redraw of the index.
Definition: draw.c:371
void menu_redraw_full(struct Menu *menu)
Force the redraw of the Menu.
Definition: draw.c:337
void menu_redraw_current(struct Menu *menu)
Redraw the current menu.
Definition: draw.c:490
+ Here is the call graph for this function:
+ Here is the caller graph for this function: