NeoMutt  2018-07-16 +2388-bcedc8
Teaching an old dog new tricks
DOXYGEN
curs_lib.c File Reference

GUI miscellaneous curses (window drawing) routines. More...

#include "config.h"
#include <stddef.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <langinfo.h>
#include <limits.h>
#include <regex.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <wchar.h>
#include "mutt/mutt.h"
#include "config/lib.h"
#include "mutt.h"
#include "curs_lib.h"
#include "browser.h"
#include "enter_state.h"
#include "globals.h"
#include "mutt_curses.h"
#include "mutt_logging.h"
#include "mutt_menu.h"
#include "mutt_window.h"
#include "opcodes.h"
#include "options.h"
#include "pager.h"
#include "protos.h"
+ Include dependency graph for curs_lib.c:

Go to the source code of this file.

Functions

void mutt_refresh (void)
 Force a refresh of the screen. More...
 
void mutt_need_hard_redraw (void)
 Force a hard refresh. More...
 
void mutt_getch_timeout (int delay)
 Set the getch() timeout. More...
 
struct KeyEvent mutt_getch (void)
 Read a character from the input buffer. More...
 
int mutt_get_field_full (const char *field, char *buf, size_t buflen, CompletionFlags complete, bool multiple, char ***files, int *numfiles)
 Ask the user for a string. More...
 
int mutt_get_field_unbuffered (const char *msg, char *buf, size_t buflen, CompletionFlags flags)
 Ask the user for a string (ignoring macro buffer) More...
 
void mutt_edit_file (const char *editor, const char *file)
 Let the user edit a file. More...
 
enum QuadOption mutt_yesorno (const char *msg, enum QuadOption def)
 Ask the user a Yes/No question. More...
 
void mutt_query_exit (void)
 Ask the user if they want to leave NeoMutt. More...
 
void mutt_show_error (void)
 Show the user an error message. More...
 
void mutt_endwin (void)
 Shutdown curses/slang. More...
 
void mutt_perror_debug (const char *s)
 Show the user an 'errno' message. More...
 
void mutt_flush_stdin (void)
 remove characters from stdin until '
' or EOF is encountered More...
 
int mutt_any_key_to_continue (const char *s)
 Prompt the user to 'press any key' and wait. More...
 
int mutt_do_pager (const char *banner, const char *tempfile, PagerFlags do_color, struct Pager *info)
 Display some page-able text to the user. More...
 
int mutt_enter_fname_full (const char *prompt, char *buf, size_t buflen, bool mailbox, bool multiple, char ***files, int *numfiles, SelectFileFlags flags)
 Ask the user to select a file. More...
 
int mutt_buffer_enter_fname_full (const char *prompt, struct Buffer *fname, bool mailbox, bool multiple, char ***files, int *numfiles, SelectFileFlags flags)
 Ask the user to select a file. More...
 
void mutt_unget_event (int ch, int op)
 Return a keystroke to the input buffer. More...
 
void mutt_unget_string (const char *s)
 Return a string to the input buffer. More...
 
void mutt_push_macro_event (int ch, int op)
 Add the character/operation to the macro buffer. More...
 
void mutt_flush_macro_to_endcond (void)
 Drop a macro from the input buffer. More...
 
void mutt_flush_unget_to_endcond (void)
 Clear entries from UngetKeyEvents. More...
 
void mutt_flushinp (void)
 Empty all the keyboard buffers. More...
 
int mutt_multi_choice (const char *prompt, const char *letters)
 Offer the user a multiple choice question. More...
 
int mutt_addwch (wchar_t wc)
 addwch would be provided by an up-to-date curses library More...
 
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() More...
 
void mutt_format_s_x (char *buf, size_t buflen, const char *prec, const char *s, bool arboreal)
 Format a string like snprintf() More...
 
void mutt_format_s (char *buf, size_t buflen, const char *prec, const char *s)
 Format a simple string. More...
 
void mutt_format_s_tree (char *buf, size_t buflen, const char *prec, const char *s)
 Format a simple string with tree characters. More...
 
void mutt_paddstr (int n, const char *s)
 Display a string on screen, padded if necessary. More...
 
size_t mutt_wstr_trunc (const char *src, size_t maxlen, size_t maxwid, size_t *width)
 Work out how to truncate a widechar string. More...
 
int mutt_strwidth (const char *s)
 Measure a string's width in screen cells. More...
 

Variables

bool C_MetaKey
 Config: Interpret 'ALT-x' as 'ESC-x'. More...
 
static size_t MacroBufferCount = 0
 
static size_t MacroBufferLen = 0
 
static struct KeyEventMacroEvents
 
static size_t UngetCount = 0
 
static size_t UngetLen = 0
 
static struct KeyEventUngetKeyEvents
 
int MuttGetchTimeout = -1
 Timeout in ms for mutt_getch() More...
 

Detailed Description

GUI miscellaneous curses (window drawing) routines.

Authors
  • Michael R. Elkins
  • g10 Code GmbH

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

Function Documentation

void mutt_refresh ( void  )

Force a refresh of the screen.

Definition at line 94 of file curs_lib.c.

95 {
96  /* don't refresh when we are waiting for a child. */
97  if (OptKeepQuiet)
98  return;
99 
100  /* don't refresh in the middle of macros unless necessary */
102  return;
103 
104  /* else */
105  refresh();
106 }
static size_t MacroBufferCount
Definition: curs_lib.c:78
WHERE bool OptIgnoreMacroEvents
(pseudo) don&#39;t process macro/push/exec events while set
Definition: options.h:36
WHERE bool OptForceRefresh
(pseudo) refresh even during macros
Definition: options.h:35
WHERE bool OptKeepQuiet
(pseudo) shut up the message and refresh functions while we are executing an external program...
Definition: options.h:37

+ Here is the caller graph for this function:

void mutt_need_hard_redraw ( void  )

Force a hard refresh.

Make sure that the next refresh does a full refresh. This could be optimized by not doing it at all if DISPLAY is set as this might indicate that a GUI based pinentry was used. Having an option to customize this is of course the NeoMutt way.

Definition at line 116 of file curs_lib.c.

117 {
118  keypad(stdscr, true);
119  clearok(stdscr, true);
121 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_getch_timeout ( int  delay)

Set the getch() timeout.

Parameters
delayTimeout delay in ms

delay is just like for timeout() or poll(): the number of milliseconds mutt_getch() should block for input.

  • delay == 0 means mutt_getch() is non-blocking.
  • delay < 0 means mutt_getch is blocking.

Definition at line 132 of file curs_lib.c.

133 {
134  MuttGetchTimeout = delay;
135  timeout(delay);
136 }
int MuttGetchTimeout
Timeout in ms for mutt_getch()
Definition: curs_lib.c:89

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

struct KeyEvent mutt_getch ( void  )

Read a character from the input buffer.

Return values
objKeyEvent to process

The priority for reading events is:

  1. UngetKeyEvents buffer
  2. MacroEvents buffer
  3. Keyboard

This function can return:

  • Error { -1, OP_NULL }
  • Timeout { -2, OP_NULL }

Definition at line 175 of file curs_lib.c.

176 {
177  int ch;
178  struct KeyEvent err = { -1, OP_NULL }, ret;
179  struct KeyEvent timeout = { -2, OP_NULL };
180 
181  if (UngetCount)
182  return UngetKeyEvents[--UngetCount];
183 
185  return MacroEvents[--MacroBufferCount];
186 
187  SigInt = 0;
188 
190 #ifdef KEY_RESIZE
191  /* ncurses 4.2 sends this when the screen is resized */
192  ch = KEY_RESIZE;
193  while (ch == KEY_RESIZE)
194 #endif /* KEY_RESIZE */
195 #ifdef USE_INOTIFY
196  ch = mutt_monitor_getch();
197 #else
198  ch = getch();
199 #endif /* USE_INOTIFY */
201 
202  if (SigInt)
203  {
204  mutt_query_exit();
205  return err;
206  }
207 
208  /* either timeout, a sigwinch (if timeout is set), or the terminal
209  * has been lost */
210  if (ch == ERR)
211  {
212  if (!isatty(0))
213  mutt_exit(1);
214 
215  return timeout;
216  }
217 
218  if ((ch & 0x80) && C_MetaKey)
219  {
220  /* send ALT-x as ESC-x */
221  ch &= ~0x80;
222  mutt_unget_event(ch, 0);
223  ret.ch = '\033'; // Escape
224  ret.op = 0;
225  return ret;
226  }
227 
228  ret.ch = ch;
229  ret.op = 0;
230  return (ch == ctrl('G')) ? err : ret;
231 }
static struct KeyEvent * MacroEvents
Definition: curs_lib.c:80
static size_t MacroBufferCount
Definition: curs_lib.c:78
WHERE SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: globals.h:83
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
WHERE bool OptIgnoreMacroEvents
(pseudo) don&#39;t process macro/push/exec events while set
Definition: options.h:36
void mutt_query_exit(void)
Ask the user if they want to leave NeoMutt.
Definition: curs_lib.c:467
void mutt_sig_allow_interrupt(bool allow)
Allow/disallow Ctrl-C (SIGINT)
Definition: signal.c:238
static size_t UngetCount
Definition: curs_lib.c:85
#define ctrl(ch)
Definition: mutt_curses.h:97
static struct KeyEvent * UngetKeyEvents
Definition: curs_lib.c:87
An event such as a keypress.
Definition: mutt_curses.h:108
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:209
bool C_MetaKey
Config: Interpret &#39;ALT-x&#39; as &#39;ESC-x&#39;.
Definition: curs_lib.c:68

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_get_field_full ( const char *  field,
char *  buf,
size_t  buflen,
CompletionFlags  complete,
bool  multiple,
char ***  files,
int *  numfiles 
)

Ask the user for a string.

Parameters
[in]fieldPrompt
[in]bufBuffer for the result
[in]buflenLength of buffer
[in]completeFlags, see CompletionFlags
[in]multipleAllow multiple selections
[out]filesList of files selected
[out]numfilesNumber of files selected
Return values
1Redraw the screen and call the function again
0Selection made
-1Aborted

Definition at line 246 of file curs_lib.c.

248 {
249  int ret;
250  int x;
251 
252  struct EnterState *es = mutt_enter_state_new();
253 
254  do
255  {
256  if (SigWinch)
257  {
258  SigWinch = 0;
260  clearok(stdscr, true);
262  }
265  addstr(field);
266  NORMAL_COLOR;
267  mutt_refresh();
269  ret = mutt_enter_string_full(buf, buflen, x, complete, multiple, files, numfiles, es);
270  } while (ret == 1);
273 
274  return ret;
275 }
#define NORMAL_COLOR
Definition: mutt_curses.h:239
void mutt_resize_screen(void)
Update NeoMutt&#39;s opinion about the window size (CURSES)
Definition: resize.c:98
Question/user input.
Definition: mutt_curses.h:143
int mutt_enter_string_full(char *buf, size_t buflen, int col, CompletionFlags flags, bool multiple, char ***files, int *numfiles, struct EnterState *state)
Ask the user for a string.
Definition: enter.c:177
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:95
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: globals.h:84
void mutt_window_getxy(struct MuttWindow *win, int *x, int *y)
Get the cursor position in the Window.
Definition: mutt_window.c:152
Keep our place when entering a string.
Definition: enter_state.h:31
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:94
void mutt_enter_state_free(struct EnterState **esp)
Free an EnterState.
Definition: enter.c:822
#define SET_COLOR(X)
Definition: mutt_curses.h:224
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42
struct EnterState * mutt_enter_state_new(void)
Create a new EnterState.
Definition: enter.c:126

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_get_field_unbuffered ( const char *  msg,
char *  buf,
size_t  buflen,
CompletionFlags  flags 
)

Ask the user for a string (ignoring macro buffer)

Parameters
msgPrompt
bufBuffer for the result
buflenLength of buffer
flagsFlags, see CompletionFlags
Return values
1Redraw the screen and call the function again
0Selection made
-1Aborted

Definition at line 287 of file curs_lib.c.

288 {
289  bool reset_ignoremacro = false;
290 
292  {
293  OptIgnoreMacroEvents = true;
294  reset_ignoremacro = true;
295  }
296  int rc = mutt_get_field(msg, buf, buflen, flags);
297  if (reset_ignoremacro)
298  OptIgnoreMacroEvents = false;
299 
300  return rc;
301 }
WHERE bool OptIgnoreMacroEvents
(pseudo) don&#39;t process macro/push/exec events while set
Definition: options.h:36
#define mutt_get_field(field, buf, buflen, complete)
Definition: curs_lib.h:86

+ Here is the caller graph for this function:

void mutt_edit_file ( const char *  editor,
const char *  file 
)

Let the user edit a file.

Parameters
editorUser's editor config
fileFile to edit

Definition at line 308 of file curs_lib.c.

309 {
310  struct Buffer *cmd = mutt_buffer_pool_get();
311 
312  mutt_endwin();
313  mutt_buffer_file_expand_fmt_quote(cmd, editor, file);
314  if (mutt_system(mutt_b2s(cmd)) != 0)
315  {
316  mutt_error(_("Error running \"%s\""), mutt_b2s(cmd));
317  }
318  /* the terminal may have been resized while the editor owned it */
320  keypad(stdscr, true);
321  clearok(stdscr, true);
322 
324 }
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:75
void mutt_resize_screen(void)
Update NeoMutt&#39;s opinion about the window size (CURSES)
Definition: resize.c:98
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:86
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
#define mutt_b2s(buf)
Definition: buffer.h:41
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:499
#define mutt_error(...)
Definition: logging.h:84
void mutt_buffer_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1418
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

enum QuadOption mutt_yesorno ( const char *  msg,
enum QuadOption  def 
)

Ask the user a Yes/No question.

Parameters
msgPrompt
defDefault answer, MUTT_YES or MUTT_NO (see QuadOption)
Return values
numSelection made, see QuadOption

Definition at line 332 of file curs_lib.c.

333 {
334  struct KeyEvent ch;
335  char *yes = _("yes");
336  char *no = _("no");
337  char *answer_string = NULL;
338  int answer_string_wid, msg_wid;
339  size_t trunc_msg_len;
340  bool redraw = true;
341  int prompt_lines = 1;
342 
343  char *expr = NULL;
344  regex_t reyes;
345  regex_t reno;
346  char answer[2];
347 
348  answer[1] = '\0';
349 
350  bool reyes_ok = (expr = nl_langinfo(YESEXPR)) && (expr[0] == '^') &&
351  (REG_COMP(&reyes, expr, REG_NOSUB) == 0);
352  bool reno_ok = (expr = nl_langinfo(NOEXPR)) && (expr[0] == '^') &&
353  (REG_COMP(&reno, expr, REG_NOSUB) == 0);
354 
355  /* In order to prevent the default answer to the question to wrapped
356  * around the screen in the even the question is wider than the screen,
357  * ensure there is enough room for the answer and truncate the question
358  * to fit. */
359  mutt_str_asprintf(&answer_string, " ([%s]/%s): ", (def == MUTT_YES) ? yes : no,
360  (def == MUTT_YES) ? no : yes);
361  answer_string_wid = mutt_strwidth(answer_string);
362  msg_wid = mutt_strwidth(msg);
363 
364  while (true)
365  {
366  if (redraw || SigWinch)
367  {
368  redraw = false;
369  if (SigWinch)
370  {
371  SigWinch = 0;
373  clearok(stdscr, true);
375  }
376  if (MuttMessageWindow->cols)
377  {
378  prompt_lines = (msg_wid + answer_string_wid + MuttMessageWindow->cols - 1) /
380  prompt_lines = MAX(1, MIN(3, prompt_lines));
381  }
382  if (prompt_lines != MuttMessageWindow->rows)
383  {
384  mutt_window_reflow_message_rows(prompt_lines);
386  }
387 
388  /* maxlen here is sort of arbitrary, so pick a reasonable upper bound */
389  trunc_msg_len = mutt_wstr_trunc(
390  msg, 4 * prompt_lines * MuttMessageWindow->cols,
391  prompt_lines * MuttMessageWindow->cols - answer_string_wid, NULL);
392 
395  addnstr(msg, trunc_msg_len);
396  addstr(answer_string);
397  NORMAL_COLOR;
399  }
400 
401  mutt_refresh();
402  /* SigWinch is not processed unless timeout is set */
403  mutt_getch_timeout(30 * 1000);
404  ch = mutt_getch();
405  mutt_getch_timeout(-1);
406  if (ch.ch == -2)
407  continue;
408  if (CI_is_return(ch.ch))
409  break;
410  if (ch.ch < 0)
411  {
412  def = MUTT_ABORT;
413  break;
414  }
415 
416  answer[0] = ch.ch;
417  if (reyes_ok ? (regexec(&reyes, answer, 0, 0, 0) == 0) : (tolower(ch.ch) == 'y'))
418  {
419  def = MUTT_YES;
420  break;
421  }
422  else if (reno_ok ? (regexec(&reno, answer, 0, 0, 0) == 0) : (tolower(ch.ch) == 'n'))
423  {
424  def = MUTT_NO;
425  break;
426  }
427  else
428  {
429  BEEP();
430  }
431  }
432 
433  FREE(&answer_string);
434 
435  if (reyes_ok)
436  regfree(&reyes);
437  if (reno_ok)
438  regfree(&reno);
439 
440  if (MuttMessageWindow->rows != 1)
441  {
444  }
445  else
447 
448  if (def != MUTT_ABORT)
449  {
450  addstr((char *) ((def == MUTT_YES) ? yes : no));
451  mutt_refresh();
452  }
453  else
454  {
455  /* when the users cancels with ^G, clear the message stored with
456  * mutt_message() so it isn't displayed when the screen is refreshed. */
458  }
459  return def;
460 }
#define CI_is_return(ch)
Definition: mutt_curses.h:102
#define MIN(a, b)
Definition: memory.h:31
User aborted the question (with Ctrl-G)
Definition: quad.h:37
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
#define NORMAL_COLOR
Definition: mutt_curses.h:239
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:107
void mutt_resize_screen(void)
Update NeoMutt&#39;s opinion about the window size (CURSES)
Definition: resize.c:98
#define _(a)
Definition: message.h:28
Question/user input.
Definition: mutt_curses.h:143
int ch
raw key pressed
Definition: mutt_curses.h:110
#define MAX(a, b)
Definition: memory.h:30
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:95
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition: regex3.h:52
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:143
void mutt_window_reflow_message_rows(int mw_rows)
Resize the Message Window.
Definition: mutt_window.c:290
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:94
int mutt_strwidth(const char *s)
Measure a string&#39;s width in screen cells.
Definition: curs_lib.c:1262
#define BEEP()
Definition: mutt_curses.h:80
User answered &#39;No&#39;, or assume &#39;No&#39;.
Definition: quad.h:38
size_t mutt_wstr_trunc(const char *src, size_t maxlen, size_t maxwid, size_t *width)
Work out how to truncate a widechar string.
Definition: curs_lib.c:1212
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:175
#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:188
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:132
#define FREE(x)
Definition: memory.h:40
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1195

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_query_exit ( void  )

Ask the user if they want to leave NeoMutt.

This function is called when the user presses the abort key.

Definition at line 467 of file curs_lib.c.

468 {
469  mutt_flushinp();
470  curs_set(1);
471  if (C_Timeout)
472  mutt_getch_timeout(-1); /* restore blocking operation */
473  if (mutt_yesorno(_("Exit NeoMutt?"), MUTT_YES) == MUTT_YES)
474  {
475  mutt_exit(1);
476  }
478  mutt_curs_set(-1);
479  SigInt = 0;
480 }
#define curs_set(x)
Definition: mutt_curses.h:88
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
WHERE SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: globals.h:83
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:800
#define _(a)
Definition: message.h:28
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: curs_lib.c:332
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:143
WHERE short C_Timeout
Config: Time to wait for user input in menus.
Definition: globals.h:159
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:209
#define mutt_curs_set(x)
Definition: mutt_curses.h:94
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:132

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_show_error ( void  )

Show the user an error message.

Definition at line 485 of file curs_lib.c.

486 {
488  return;
489 
492  NORMAL_COLOR;
494 }
#define NORMAL_COLOR
Definition: mutt_curses.h:239
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:107
Informational message.
Definition: mutt_curses.h:137
WHERE char ErrorBuf[256]
Copy of the last error message.
Definition: globals.h:44
WHERE bool ErrorBufMessage
true if the last message was an error
Definition: globals.h:43
#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:202
Error message.
Definition: mutt_curses.h:132
WHERE bool OptMsgErr
(pseudo) used by mutt_error/mutt_message
Definition: options.h:39
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42
WHERE bool OptKeepQuiet
(pseudo) shut up the message and refresh functions while we are executing an external program...
Definition: options.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_endwin ( void  )

Shutdown curses/slang.

Definition at line 499 of file curs_lib.c.

500 {
501  if (OptNoCurses)
502  return;
503 
504  int e = errno;
505 
506  /* at least in some situations (screen + xterm under SuSE11/12) endwin()
507  * doesn't properly flush the screen without an explicit call. */
508  mutt_refresh();
509  endwin();
510 
511  errno = e;
512 }
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:46
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_perror_debug ( const char *  s)

Show the user an 'errno' message.

Parameters
sAdditional text to show

Definition at line 518 of file curs_lib.c.

519 {
520  char *p = strerror(errno);
521 
522  mutt_debug(LL_DEBUG1, "%s: %s (errno = %d)\n", s, p ? p : "unknown error", errno);
523  mutt_error("%s: %s (errno = %d)", s, p ? p : _("unknown error"), errno);
524 }
#define _(a)
Definition: message.h:28
Log at debug level 1.
Definition: logging.h:56
#define mutt_error(...)
Definition: logging.h:84
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
void mutt_flush_stdin ( void  )

remove characters from stdin until '
' or EOF is encountered

Definition at line 529 of file curs_lib.c.

530 {
531  int c;
532  do
533  {
534  c = fgetc(stdin);
535  } while ((c != '\n') && (c != EOF));
536 }

+ Here is the caller graph for this function:

int mutt_any_key_to_continue ( const char *  s)

Prompt the user to 'press any key' and wait.

Parameters
sMessage prompt
Return values
numKey pressed
EOFError, or prompt aborted

Definition at line 544 of file curs_lib.c.

545 {
546  struct termios t;
547  struct termios old;
548 
549  int fd = open("/dev/tty", O_RDONLY);
550  if (fd < 0)
551  return EOF;
552  tcgetattr(fd, &t);
553  memcpy((void *) &old, (void *) &t, sizeof(struct termios)); /* save original state */
554  t.c_lflag &= ~(ICANON | ECHO);
555  t.c_cc[VMIN] = 1;
556  t.c_cc[VTIME] = 0;
557  tcsetattr(fd, TCSADRAIN, &t);
558  fflush(stdout);
559  if (s)
560  fputs(s, stdout);
561  else
562  fputs(_("Press any key to continue..."), stdout);
563  fflush(stdout);
564  int ch = fgetc(stdin);
566  tcsetattr(fd, TCSADRAIN, &old);
567  close(fd);
568  fputs("\r\n", stdout);
570  return (ch >= 0) ? ch : EOF;
571 }
void mutt_flush_stdin(void)
remove characters from stdin until &#39; &#39; or EOF is encountered
Definition: curs_lib.c:529
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:143

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_do_pager ( const char *  banner,
const char *  tempfile,
PagerFlags  do_color,
struct Pager info 
)

Display some page-able text to the user.

Parameters
bannerMessage for status bar
tempfileFile to display
do_colorFlags, see PagerFlags
infoInfo about current mailbox (OPTIONAL)
Return values
0Success
-1Error

Definition at line 582 of file curs_lib.c.

584 {
585  int rc;
586 
587  if (!C_Pager || (mutt_str_strcmp(C_Pager, "builtin") == 0))
588  rc = mutt_pager(banner, tempfile, do_color, info);
589  else
590  {
591  struct Buffer *cmd = mutt_buffer_pool_get();
592 
593  mutt_endwin();
595  if (mutt_system(mutt_b2s(cmd)) == -1)
596  {
597  mutt_error(_("Error running \"%s\""), mutt_b2s(cmd));
598  rc = -1;
599  }
600  else
601  rc = 0;
602  mutt_file_unlink(tempfile);
604  }
605 
606  return rc;
607 }
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:75
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:86
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:191
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
#define mutt_b2s(buf)
Definition: buffer.h:41
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:499
#define mutt_error(...)
Definition: logging.h:84
void mutt_buffer_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1418
WHERE char * C_Pager
Config: External command for viewing messages, or &#39;builtin&#39; to use NeoMutt&#39;s.
Definition: globals.h:139
int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct Pager *extra)
Display a file, or help, in a window.
Definition: pager.c:2242
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:51

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_enter_fname_full ( const char *  prompt,
char *  buf,
size_t  buflen,
bool  mailbox,
bool  multiple,
char ***  files,
int *  numfiles,
SelectFileFlags  flags 
)

Ask the user to select a file.

Parameters
[in]promptPrompt
[in]bufBuffer for the result
[in]buflenLength of the buffer
[in]mailboxIf true, select mailboxes
[in]multipleAllow multiple selections
[out]filesList of files selected
[out]numfilesNumber of files selected
[in]flagsFlags, see SelectFileFlags
Return values
0Success
-1Error

Definition at line 622 of file curs_lib.c.

624 {
625  struct Buffer *fname = mutt_buffer_pool_get();
626 
627  mutt_buffer_addstr(fname, NONULL(buf));
628  int rc = mutt_buffer_enter_fname_full(prompt, fname, mailbox, multiple, files,
629  numfiles, flags);
630  mutt_str_strfcpy(buf, mutt_b2s(fname), buflen);
631 
632  mutt_buffer_pool_release(&fname);
633  return rc;
634 }
#define NONULL(x)
Definition: string2.h:37
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:75
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:86
String manipulation buffer.
Definition: buffer.h:33
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:256
int mutt_buffer_enter_fname_full(const char *prompt, struct Buffer *fname, bool mailbox, bool multiple, char ***files, int *numfiles, SelectFileFlags flags)
Ask the user to select a file.
Definition: curs_lib.c:648
#define mutt_b2s(buf)
Definition: buffer.h:41
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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_buffer_enter_fname_full ( const char *  prompt,
struct Buffer fname,
bool  mailbox,
bool  multiple,
char ***  files,
int *  numfiles,
SelectFileFlags  flags 
)

Ask the user to select a file.

Parameters
[in]promptPrompt
[in]fnameBuffer for the result
[in]mailboxIf true, select mailboxes
[in]multipleAllow multiple selections
[out]filesList of files selected
[out]numfilesNumber of files selected
[in]flagsFlags, see SelectFileFlags
Return values
0Success
-1Error

Definition at line 648 of file curs_lib.c.

651 {
652  struct KeyEvent ch;
653 
656  addstr(_(" ('?' for list): "));
657  NORMAL_COLOR;
658  if (mutt_buffer_len(fname))
659  addstr(mutt_b2s(fname));
661  mutt_refresh();
662 
663  do
664  {
665  ch = mutt_getch();
666  } while (ch.ch == -2);
667  if (ch.ch < 0)
668  {
670  return -1;
671  }
672  else if (ch.ch == '?')
673  {
674  mutt_refresh();
675  mutt_buffer_reset(fname);
676 
677  if (flags == MUTT_SEL_NO_FLAGS)
678  flags = MUTT_SEL_FOLDER;
679  if (multiple)
680  flags |= MUTT_SEL_MULTI;
681  if (mailbox)
682  flags |= MUTT_SEL_MAILBOX;
683  mutt_buffer_select_file(fname, flags, files, numfiles);
684  }
685  else
686  {
687  char *pc = mutt_mem_malloc(mutt_str_strlen(prompt) + 3);
688 
689  sprintf(pc, "%s: ", prompt);
690  if (ch.op == OP_NULL)
691  mutt_unget_event(ch.ch, 0);
692  else
693  mutt_unget_event(0, ch.op);
694 
695  mutt_buffer_increase_size(fname, 1024);
696  if (mutt_get_field_full(pc, fname->data, fname->dsize,
697  (mailbox ? MUTT_EFILE : MUTT_FILE) | MUTT_CLEAR,
698  multiple, files, numfiles) != 0)
699  mutt_buffer_reset(fname);
700  else
701  mutt_buffer_fix_dptr(fname);
702  FREE(&pc);
703  }
704 
705  return 0;
706 }
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
#define MUTT_CLEAR
Clear input if printable character is pressed.
Definition: mutt.h:69
void mutt_buffer_increase_size(struct Buffer *buf, size_t new_size)
Increase the allocated size of a buffer.
Definition: buffer.c:339
void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, char ***files, int *numfiles)
Let the user select a file.
Definition: browser.c:1135
#define NORMAL_COLOR
Definition: mutt_curses.h:239
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:107
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
Question/user input.
Definition: mutt_curses.h:143
int ch
raw key pressed
Definition: mutt_curses.h:110
#define MUTT_SEL_NO_FLAGS
No flags are set.
Definition: browser.h:44
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
#define MUTT_SEL_FOLDER
Select a local directory.
Definition: browser.h:47
size_t dsize
Length of data.
Definition: buffer.h:37
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:95
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:212
#define mutt_b2s(buf)
Definition: buffer.h:41
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:94
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:364
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
char * data
Pointer to data.
Definition: buffer.h:35
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:175
#define SET_COLOR(X)
Definition: mutt_curses.h:224
#define MUTT_SEL_MULTI
Multi-selection is enabled.
Definition: browser.h:46
int mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:202
#define MUTT_FILE
Do file completion.
Definition: mutt.h:65
#define MUTT_SEL_MAILBOX
Select a mailbox.
Definition: browser.h:45
#define MUTT_EFILE
Do file completion, plus incoming folders.
Definition: mutt.h:66
#define FREE(x)
Definition: memory.h:40
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42
int mutt_get_field_full(const char *field, char *buf, size_t buflen, CompletionFlags complete, bool multiple, char ***files, int *numfiles)
Ask the user for a string.
Definition: curs_lib.c:246

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_unget_event ( int  ch,
int  op 
)

Return a keystroke to the input buffer.

Parameters
chKey press
opOperation, e.g. OP_DELETE

This puts events into the UngetKeyEvents buffer

Definition at line 715 of file curs_lib.c.

716 {
717  struct KeyEvent tmp;
718 
719  tmp.ch = ch;
720  tmp.op = op;
721 
722  if (UngetCount >= UngetLen)
723  mutt_mem_realloc(&UngetKeyEvents, (UngetLen += 16) * sizeof(struct KeyEvent));
724 
725  UngetKeyEvents[UngetCount++] = tmp;
726 }
int op
function op
Definition: mutt_curses.h:111
int ch
raw key pressed
Definition: mutt_curses.h:110
static size_t UngetCount
Definition: curs_lib.c:85
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
static struct KeyEvent * UngetKeyEvents
Definition: curs_lib.c:87
An event such as a keypress.
Definition: mutt_curses.h:108
static size_t UngetLen
Definition: curs_lib.c:86

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_unget_string ( const char *  s)

Return a string to the input buffer.

Parameters
sString to return

This puts events into the UngetKeyEvents buffer

Definition at line 734 of file curs_lib.c.

735 {
736  const char *p = s + mutt_str_strlen(s) - 1;
737 
738  while (p >= s)
739  {
740  mutt_unget_event((unsigned char) *p--, 0);
741  }
742 }
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:715
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_push_macro_event ( int  ch,
int  op 
)

Add the character/operation to the macro buffer.

Parameters
chCharacter to add
opOperation to add

Adds the ch/op to the macro buffer. This should be used for macros, push, and exec commands only.

Definition at line 752 of file curs_lib.c.

753 {
754  struct KeyEvent tmp;
755 
756  tmp.ch = ch;
757  tmp.op = op;
758 
760  mutt_mem_realloc(&MacroEvents, (MacroBufferLen += 128) * sizeof(struct KeyEvent));
761 
762  MacroEvents[MacroBufferCount++] = tmp;
763 }
static struct KeyEvent * MacroEvents
Definition: curs_lib.c:80
static size_t MacroBufferCount
Definition: curs_lib.c:78
int op
function op
Definition: mutt_curses.h:111
int ch
raw key pressed
Definition: mutt_curses.h:110
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
An event such as a keypress.
Definition: mutt_curses.h:108
static size_t MacroBufferLen
Definition: curs_lib.c:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_flush_macro_to_endcond ( void  )

Drop a macro from the input buffer.

All the macro text is deleted until an OP_END_COND command, or the buffer is empty.

Definition at line 771 of file curs_lib.c.

772 {
773  UngetCount = 0;
774  while (MacroBufferCount > 0)
775  {
776  if (MacroEvents[--MacroBufferCount].op == OP_END_COND)
777  return;
778  }
779 }
static struct KeyEvent * MacroEvents
Definition: curs_lib.c:80
static size_t MacroBufferCount
Definition: curs_lib.c:78
int op
function op
Definition: mutt_curses.h:111
static size_t UngetCount
Definition: curs_lib.c:85

+ Here is the caller graph for this function:

void mutt_flush_unget_to_endcond ( void  )

Clear entries from UngetKeyEvents.

Normally, OP_END_COND should only be in the MacroEvent buffer. km_error_key() (ab)uses OP_END_COND as a barrier in the unget buffer, and calls this function to flush.

Definition at line 788 of file curs_lib.c.

789 {
790  while (UngetCount > 0)
791  {
792  if (UngetKeyEvents[--UngetCount].op == OP_END_COND)
793  return;
794  }
795 }
int op
function op
Definition: mutt_curses.h:111
static size_t UngetCount
Definition: curs_lib.c:85
static struct KeyEvent * UngetKeyEvents
Definition: curs_lib.c:87

+ Here is the caller graph for this function:

void mutt_flushinp ( void  )

Empty all the keyboard buffers.

Definition at line 800 of file curs_lib.c.

801 {
802  UngetCount = 0;
803  MacroBufferCount = 0;
804  flushinp();
805 }
static size_t MacroBufferCount
Definition: curs_lib.c:78
static size_t UngetCount
Definition: curs_lib.c:85

+ Here is the caller graph for this function:

int mutt_multi_choice ( const char *  prompt,
const char *  letters 
)

Offer the user a multiple choice question.

Parameters
promptMessage prompt
lettersAllowable selection keys
Return values
>=00-based user selection
-1Selection aborted

Definition at line 839 of file curs_lib.c.

840 {
841  struct KeyEvent ch;
842  int choice;
843  bool redraw = true;
844  int prompt_lines = 1;
845 
846  bool opt_cols = ((ColorDefs[MT_COLOR_OPTIONS] != 0) &&
848 
849  while (true)
850  {
851  if (redraw || SigWinch)
852  {
853  redraw = false;
854  if (SigWinch)
855  {
856  SigWinch = 0;
858  clearok(stdscr, true);
860  }
861  if (MuttMessageWindow->cols)
862  {
863  int width = mutt_strwidth(prompt) + 2; // + '?' + space
864  /* If we're going to colour the options,
865  * make an assumption about the modified prompt size. */
866  if (opt_cols)
867  width -= 2 * mutt_str_strlen(letters);
868 
869  prompt_lines = (width + MuttMessageWindow->cols - 1) / MuttMessageWindow->cols;
870  prompt_lines = MAX(1, MIN(3, prompt_lines));
871  }
872  if (prompt_lines != MuttMessageWindow->rows)
873  {
874  mutt_window_reflow_message_rows(prompt_lines);
876  }
877 
879 
880  if ((ColorDefs[MT_COLOR_OPTIONS] != 0) &&
881  (ColorDefs[MT_COLOR_OPTIONS] != ColorDefs[MT_COLOR_PROMPT]))
882  {
883  char *cur = NULL;
884 
885  while ((cur = strchr(prompt, '(')))
886  {
887  // write the part between prompt and cur using MT_COLOR_PROMPT
888  SET_COLOR(MT_COLOR_PROMPT);
889  addnstr(prompt, cur - prompt);
890 
891  if (isalnum(cur[1]) && (cur[2] == ')'))
892  {
893  // we have a single letter within parentheses
895  addch(cur[1]);
896  prompt = cur + 3;
897  }
898  else
899  {
900  // we have a parenthesis followed by something else
901  addch(cur[0]);
902  prompt = cur + 1;
903  }
904  }
905  }
906 
907  SET_COLOR(MT_COLOR_PROMPT);
908  addstr(prompt);
909  NORMAL_COLOR;
910 
911  addch(' ');
913  }
914 
915  mutt_refresh();
916  /* SigWinch is not processed unless timeout is set */
917  mutt_getch_timeout(30 * 1000);
918  ch = mutt_getch();
919  mutt_getch_timeout(-1);
920  if (ch.ch == -2)
921  continue;
922  /* (ch.ch == 0) is technically possible. Treat the same as < 0 (abort) */
923  if ((ch.ch <= 0) || CI_is_return(ch.ch))
924  {
925  choice = -1;
926  break;
927  }
928  else
929  {
930  char *p = strchr(letters, ch.ch);
931  if (p)
932  {
933  choice = p - letters + 1;
934  break;
935  }
936  else if ((ch.ch <= '9') && (ch.ch > '0'))
937  {
938  choice = ch.ch - '0';
939  if (choice <= mutt_str_strlen(letters))
940  break;
941  }
942  }
943  BEEP();
944  }
945  if (MuttMessageWindow->rows != 1)
946  {
949  }
950  else
952  mutt_refresh();
953  return choice;
954 }
#define CI_is_return(ch)
Definition: mutt_curses.h:102
Options in prompt.
Definition: mutt_curses.h:173
#define MIN(a, b)
Definition: memory.h:31
#define NORMAL_COLOR
Definition: mutt_curses.h:239
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:107
void mutt_resize_screen(void)
Update NeoMutt&#39;s opinion about the window size (CURSES)
Definition: resize.c:98
Question/user input.
Definition: mutt_curses.h:143
int ch
raw key pressed
Definition: mutt_curses.h:110
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
#define MAX(a, b)
Definition: memory.h:30
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:95
WHERE SIG_ATOMIC_VOLATILE_T SigWinch
true after SIGWINCH is received
Definition: globals.h:84
void mutt_window_reflow_message_rows(int mw_rows)
Resize the Message Window.
Definition: mutt_window.c:290
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:94
int mutt_strwidth(const char *s)
Measure a string&#39;s width in screen cells.
Definition: curs_lib.c:1262
#define BEEP()
Definition: mutt_curses.h:80
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:175
int ColorDefs[MT_COLOR_MAX]
Array of all fixed colours, see enum ColorId.
Definition: color.c:55
#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:188
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:132
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_addwch ( wchar_t  wc)

addwch would be provided by an up-to-date curses library

Parameters
wcWide char to display
Return values
0Success
-1Error

Definition at line 962 of file curs_lib.c.

963 {
964  char buf[MB_LEN_MAX * 2];
965  mbstate_t mbstate;
966  size_t n1, n2;
967 
968  memset(&mbstate, 0, sizeof(mbstate));
969  if (((n1 = wcrtomb(buf, wc, &mbstate)) == (size_t)(-1)) ||
970  ((n2 = wcrtomb(buf + n1, 0, &mbstate)) == (size_t)(-1)))
971  {
972  return -1; /* ERR */
973  }
974  else
975  {
976  return addstr(buf);
977  }
978 }

+ Here is the caller graph for this function:

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()

Parameters
[out]bufBuffer in which to save string
[in]buflenBuffer length
[in]min_widthMinimum width
[in]max_widthMaximum width
[in]justifyJustification, e.g. JUSTIFY_RIGHT
[in]pad_charPadding character
[in]sString to format
[in]nNumber of bytes of string to format
[in]arborealIf true, string contains graphical tree characters

This formats a string, a bit like snprintf(buf, buflen, "%-*.*s", min_width, max_width, s), except that the widths refer to the number of character cells when printed.

Definition at line 996 of file curs_lib.c.

999 {
1000  wchar_t wc;
1001  int w;
1002  size_t k, k2;
1003  char scratch[MB_LEN_MAX];
1004  mbstate_t mbstate1, mbstate2;
1005  int escaped = 0;
1006 
1007  memset(&mbstate1, 0, sizeof(mbstate1));
1008  memset(&mbstate2, 0, sizeof(mbstate2));
1009  buflen--;
1010  char *p = buf;
1011  for (; n && (k = mbrtowc(&wc, s, n, &mbstate1)); s += k, n -= k)
1012  {
1013  if ((k == (size_t)(-1)) || (k == (size_t)(-2)))
1014  {
1015  if ((k == (size_t)(-1)) && (errno == EILSEQ))
1016  memset(&mbstate1, 0, sizeof(mbstate1));
1017 
1018  k = (k == (size_t)(-1)) ? 1 : n;
1019  wc = ReplacementChar;
1020  }
1021  if (escaped)
1022  {
1023  escaped = 0;
1024  w = 0;
1025  }
1026  else if (arboreal && (wc == MUTT_SPECIAL_INDEX))
1027  {
1028  escaped = 1;
1029  w = 0;
1030  }
1031  else if (arboreal && (wc < MUTT_TREE_MAX))
1032  {
1033  w = 1; /* hack */
1034  }
1035  else
1036  {
1037 #ifdef HAVE_ISWBLANK
1038  if (iswblank(wc))
1039  wc = ' ';
1040  else
1041 #endif
1042  if (!IsWPrint(wc))
1043  wc = '?';
1044  w = wcwidth(wc);
1045  }
1046  if (w >= 0)
1047  {
1048  if ((w > max_width) || ((k2 = wcrtomb(scratch, wc, &mbstate2)) > buflen))
1049  continue;
1050  min_width -= w;
1051  max_width -= w;
1052  strncpy(p, scratch, k2);
1053  p += k2;
1054  buflen -= k2;
1055  }
1056  }
1057  w = ((int) buflen < min_width) ? buflen : min_width;
1058  if (w <= 0)
1059  *p = '\0';
1060  else if (justify == JUSTIFY_RIGHT) /* right justify */
1061  {
1062  p[w] = '\0';
1063  while (--p >= buf)
1064  p[w] = *p;
1065  while (--w >= 0)
1066  buf[w] = pad_char;
1067  }
1068  else if (justify == JUSTIFY_CENTER) /* center */
1069  {
1070  char *savedp = p;
1071  int half = (w + 1) / 2; /* half of cushion space */
1072 
1073  p[w] = '\0';
1074 
1075  /* move str to center of buffer */
1076  while (--p >= buf)
1077  p[half] = *p;
1078 
1079  /* fill rhs */
1080  p = savedp + half;
1081  while (--w >= half)
1082  *p++ = pad_char;
1083 
1084  /* fill lhs */
1085  while (half--)
1086  buf[half] = pad_char;
1087  }
1088  else /* left justify */
1089  {
1090  while (--w >= 0)
1091  *p++ = pad_char;
1092  *p = '\0';
1093  }
1094 }
#define IsWPrint(wc)
Definition: mbyte.h:39
Right justify the text.
Definition: curs_lib.h:48
wchar_t ReplacementChar
When a Unicode character can&#39;t be displayed, use this instead.
Definition: charset.c:59
Centre the text.
Definition: curs_lib.h:47
Colour indicator.
Definition: mutt_menu.h:76
#define EILSEQ
Definition: charset.c:50

+ Here is the caller graph for this function:

void mutt_format_s_x ( char *  buf,
size_t  buflen,
const char *  prec,
const char *  s,
bool  arboreal 
)

Format a string like snprintf()

Parameters
[out]bufBuffer in which to save string
[in]buflenBuffer length
[in]precField precision, e.g. "-3.4"
[in]sString to format
[in]arborealIf true, string contains graphical tree characters

This formats a string rather like:

  • snprintf(fmt, sizeof(fmt), "%%%ss", prec);
  • snprintf(buf, buflen, fmt, s); except that the numbers in the conversion specification refer to the number of character cells when printed.

Definition at line 1110 of file curs_lib.c.

1111 {
1112  enum FormatJustify justify = JUSTIFY_RIGHT;
1113  char *p = NULL;
1114  int min_width;
1115  int max_width = INT_MAX;
1116 
1117  if (*prec == '-')
1118  {
1119  prec++;
1120  justify = JUSTIFY_LEFT;
1121  }
1122  else if (*prec == '=')
1123  {
1124  prec++;
1125  justify = JUSTIFY_CENTER;
1126  }
1127  min_width = strtol(prec, &p, 10);
1128  if (*p == '.')
1129  {
1130  prec = p + 1;
1131  max_width = strtol(prec, &p, 10);
1132  if (p <= prec)
1133  max_width = INT_MAX;
1134  }
1135 
1136  mutt_simple_format(buf, buflen, min_width, max_width, justify, ' ', s,
1137  mutt_str_strlen(s), arboreal);
1138 }
Left justify the text.
Definition: curs_lib.h:46
FormatJustify
Alignment for mutt_simple_format()
Definition: curs_lib.h:44
Right justify the text.
Definition: curs_lib.h:48
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
Centre the text.
Definition: curs_lib.h:47
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:996

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_format_s ( char *  buf,
size_t  buflen,
const char *  prec,
const char *  s 
)

Format a simple string.

Parameters
[out]bufBuffer in which to save string
[in]buflenBuffer length
[in]precField precision, e.g. "-3.4"
[in]sString to format

Definition at line 1147 of file curs_lib.c.

1148 {
1149  mutt_format_s_x(buf, buflen, prec, s, false);
1150 }
void mutt_format_s_x(char *buf, size_t buflen, const char *prec, const char *s, bool arboreal)
Format a string like snprintf()
Definition: curs_lib.c:1110

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_format_s_tree ( char *  buf,
size_t  buflen,
const char *  prec,
const char *  s 
)

Format a simple string with tree characters.

Parameters
[out]bufBuffer in which to save string
[in]buflenBuffer length
[in]precField precision, e.g. "-3.4"
[in]sString to format

Definition at line 1159 of file curs_lib.c.

1160 {
1161  mutt_format_s_x(buf, buflen, prec, s, true);
1162 }
void mutt_format_s_x(char *buf, size_t buflen, const char *prec, const char *s, bool arboreal)
Format a string like snprintf()
Definition: curs_lib.c:1110

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void mutt_paddstr ( int  n,
const char *  s 
)

Display a string on screen, padded if necessary.

Parameters
nFinal width of field
sString to display

Definition at line 1169 of file curs_lib.c.

1170 {
1171  wchar_t wc;
1172  size_t k;
1173  size_t len = mutt_str_strlen(s);
1174  mbstate_t mbstate;
1175 
1176  memset(&mbstate, 0, sizeof(mbstate));
1177  for (; len && (k = mbrtowc(&wc, s, len, &mbstate)); s += k, len -= k)
1178  {
1179  if ((k == (size_t)(-1)) || (k == (size_t)(-2)))
1180  {
1181  if (k == (size_t)(-1))
1182  memset(&mbstate, 0, sizeof(mbstate));
1183  k = (k == (size_t)(-1)) ? 1 : len;
1184  wc = ReplacementChar;
1185  }
1186  if (!IsWPrint(wc))
1187  wc = '?';
1188  const int w = wcwidth(wc);
1189  if (w >= 0)
1190  {
1191  if (w > n)
1192  break;
1193  addnstr((char *) s, k);
1194  n -= w;
1195  }
1196  }
1197  while (n-- > 0)
1198  addch(' ');
1199 }
#define IsWPrint(wc)
Definition: mbyte.h:39
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
wchar_t ReplacementChar
When a Unicode character can&#39;t be displayed, use this instead.
Definition: charset.c:59

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t mutt_wstr_trunc ( const char *  src,
size_t  maxlen,
size_t  maxwid,
size_t *  width 
)

Work out how to truncate a widechar string.

Parameters
[in]srcString to measure
[in]maxlenMaximum length of string in bytes
[in]maxwidMaximum width in screen columns
[out]widthSave the truncated screen column width
Return values
numBytes to use

See how many bytes to copy from string so it's at most maxlen bytes long and maxwid columns wide

Definition at line 1212 of file curs_lib.c.

1213 {
1214  wchar_t wc;
1215  size_t n, w = 0, l = 0, cl;
1216  int cw;
1217  mbstate_t mbstate;
1218 
1219  if (!src)
1220  goto out;
1221 
1222  n = mutt_str_strlen(src);
1223 
1224  memset(&mbstate, 0, sizeof(mbstate));
1225  for (w = 0; n && (cl = mbrtowc(&wc, src, n, &mbstate)); src += cl, n -= cl)
1226  {
1227  if ((cl == (size_t)(-1)) || (cl == (size_t)(-2)))
1228  {
1229  if (cl == (size_t)(-1))
1230  memset(&mbstate, 0, sizeof(mbstate));
1231  cl = (cl == (size_t)(-1)) ? 1 : n;
1232  wc = ReplacementChar;
1233  }
1234  cw = wcwidth(wc);
1235  /* hack because MUTT_TREE symbols aren't turned into characters
1236  * until rendered by print_enriched_string (#3364) */
1237  if ((cw < 0) && (src[0] == MUTT_SPECIAL_INDEX))
1238  {
1239  cl = 2; /* skip the index coloring sequence */
1240  cw = 0;
1241  }
1242  else if ((cw < 0) && (cl == 1) && (src[0] != '\0') && (src[0] < MUTT_TREE_MAX))
1243  cw = 1;
1244  else if (cw < 0)
1245  cw = 0; /* unprintable wchar */
1246  if ((cl + l > maxlen) || (cw + w > maxwid))
1247  break;
1248  l += cl;
1249  w += cw;
1250  }
1251 out:
1252  if (width)
1253  *width = w;
1254  return l;
1255 }
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
wchar_t ReplacementChar
When a Unicode character can&#39;t be displayed, use this instead.
Definition: charset.c:59
Colour indicator.
Definition: mutt_menu.h:76

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_strwidth ( const char *  s)

Measure a string's width in screen cells.

Parameters
sString to be measured
Return values
numScreen cells string would use

Definition at line 1262 of file curs_lib.c.

1263 {
1264  if (!s)
1265  return 0;
1266 
1267  wchar_t wc;
1268  int w;
1269  size_t k;
1270  mbstate_t mbstate;
1271 
1272  size_t n = mutt_str_strlen(s);
1273 
1274  memset(&mbstate, 0, sizeof(mbstate));
1275  for (w = 0; n && (k = mbrtowc(&wc, s, n, &mbstate)); s += k, n -= k)
1276  {
1277  if (*s == MUTT_SPECIAL_INDEX)
1278  {
1279  s += 2; /* skip the index coloring sequence */
1280  k = 0;
1281  continue;
1282  }
1283 
1284  if ((k == (size_t)(-1)) || (k == (size_t)(-2)))
1285  {
1286  if (k == (size_t)(-1))
1287  memset(&mbstate, 0, sizeof(mbstate));
1288  k = (k == (size_t)(-1)) ? 1 : n;
1289  wc = ReplacementChar;
1290  }
1291  if (!IsWPrint(wc))
1292  wc = '?';
1293  w += wcwidth(wc);
1294  }
1295  return w;
1296 }
#define IsWPrint(wc)
Definition: mbyte.h:39
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
wchar_t ReplacementChar
When a Unicode character can&#39;t be displayed, use this instead.
Definition: charset.c:59
Colour indicator.
Definition: mutt_menu.h:76

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

bool C_MetaKey

Config: Interpret 'ALT-x' as 'ESC-x'.

interpret ALT-x as ESC-x

Definition at line 68 of file curs_lib.c.

size_t MacroBufferCount = 0
static

Definition at line 78 of file curs_lib.c.

size_t MacroBufferLen = 0
static

Definition at line 79 of file curs_lib.c.

struct KeyEvent* MacroEvents
static

Definition at line 80 of file curs_lib.c.

size_t UngetCount = 0
static

Definition at line 85 of file curs_lib.c.

size_t UngetLen = 0
static

Definition at line 86 of file curs_lib.c.

struct KeyEvent* UngetKeyEvents
static

Definition at line 87 of file curs_lib.c.

int MuttGetchTimeout = -1

Timeout in ms for mutt_getch()

Definition at line 89 of file curs_lib.c.