NeoMutt  2018-07-16 +1783-b00bd9
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 "email/lib.h"
#include "mutt.h"
#include "curs_lib.h"
#include "browser.h"
#include "context.h"
#include "enter_state.h"
#include "globals.h"
#include "mailbox.h"
#include "mutt_curses.h"
#include "mutt_logging.h"
#include "mutt_menu.h"
#include "mutt_window.h"
#include "muttlib.h"
#include "opcodes.h"
#include "options.h"
#include "pager.h"
#include "protos.h"
#include "sidebar.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 Event 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...
 
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 EventMacroEvents
 
static size_t UngetCount = 0
 
static size_t UngetLen = 0
 
static struct EventUngetKeyEvents
 
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 99 of file curs_lib.c.

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

+ 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 121 of file curs_lib.c.

122 {
123  keypad(stdscr, true);
124  clearok(stdscr, true);
126 }

+ 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 137 of file curs_lib.c.

138 {
139  MuttGetchTimeout = delay;
140  timeout(delay);
141 }
int MuttGetchTimeout
Timeout in ms for mutt_getch()
Definition: curs_lib.c:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

struct Event mutt_getch ( void  )

Read a character from the input buffer.

Return values
objEvent 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 180 of file curs_lib.c.

181 {
182  int ch;
183  struct Event err = { -1, OP_NULL }, ret;
184  struct Event timeout = { -2, OP_NULL };
185 
186  if (UngetCount)
187  return UngetKeyEvents[--UngetCount];
188 
190  return MacroEvents[--MacroBufferCount];
191 
192  SigInt = 0;
193 
195 #ifdef KEY_RESIZE
196  /* ncurses 4.2 sends this when the screen is resized */
197  ch = KEY_RESIZE;
198  while (ch == KEY_RESIZE)
199 #endif /* KEY_RESIZE */
200 #ifdef USE_INOTIFY
201  ch = mutt_monitor_getch();
202 #else
203  ch = getch();
204 #endif /* USE_INOTIFY */
206 
207  if (SigInt)
208  {
209  mutt_query_exit();
210  return err;
211  }
212 
213  /* either timeout, a sigwinch (if timeout is set), or the terminal
214  * has been lost */
215  if (ch == ERR)
216  {
217  if (!isatty(0))
218  mutt_exit(1);
219 
220  return timeout;
221  }
222 
223  if ((ch & 0x80) && C_MetaKey)
224  {
225  /* send ALT-x as ESC-x */
226  ch &= ~0x80;
227  mutt_unget_event(ch, 0);
228  ret.ch = '\033'; // Escape
229  ret.op = 0;
230  return ret;
231  }
232 
233  ret.ch = ch;
234  ret.op = 0;
235  return (ch == ctrl('G')) ? err : ret;
236 }
static size_t MacroBufferCount
Definition: curs_lib.c:83
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:700
WHERE bool OptIgnoreMacroEvents
(pseudo) don&#39;t process macro/push/exec events while set
Definition: options.h:35
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:230
static size_t UngetCount
Definition: curs_lib.c:90
An event such as a keypress.
Definition: mutt_curses.h:108
static struct Event * MacroEvents
Definition: curs_lib.c:85
#define ctrl(ch)
Definition: mutt_curses.h:97
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:202
int ch
raw key pressed
Definition: mutt_curses.h:110
bool C_MetaKey
Config: Interpret &#39;ALT-x&#39; as &#39;ESC-x&#39;.
Definition: curs_lib.c:73
static struct Event * UngetKeyEvents
Definition: curs_lib.c:92

+ 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 251 of file curs_lib.c.

253 {
254  int ret;
255  int x;
256 
257  struct EnterState *es = mutt_enter_state_new();
258 
259  do
260  {
261  if (SigWinch)
262  {
263  SigWinch = 0;
265  clearok(stdscr, TRUE);
267  }
270  addstr(field);
271  NORMAL_COLOR;
272  mutt_refresh();
274  ret = mutt_enter_string_full(buf, buflen, x, complete, multiple, files, numfiles, es);
275  } while (ret == 1);
278 
279  return ret;
280 }
#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:69
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:126
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:99
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:41
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 292 of file curs_lib.c.

293 {
294  int rc;
295 
296  OptIgnoreMacroEvents = true;
297  rc = mutt_get_field(msg, buf, buflen, flags);
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:35
#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 }
void mutt_resize_screen(void)
Update NeoMutt&#39;s opinion about the window size (CURSES)
Definition: resize.c:98
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
#define mutt_b2s(buf)
Definition: buffer.h:42
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:499
#define mutt_error(...)
Definition: logging.h:83
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:1393
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: buffer.c:409
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:50
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: buffer.c:398

+ 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, see QuadOption
Return values
numSelection made, see QuadOption

Definition at line 332 of file curs_lib.c.

333 {
334  struct Event 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:81
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
An event such as a keypress.
Definition: mutt_curses.h:108
#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:69
#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:141
void mutt_window_reflow_message_rows(int mw_rows)
Resize the Message Window.
Definition: mutt_window.c:293
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:99
struct Event mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:180
int mutt_strwidth(const char *s)
Measure a string&#39;s width in screen cells.
Definition: curs_lib.c:1239
#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:1189
#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
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:137
#define FREE(x)
Definition: memory.h:40
int ch
raw key pressed
Definition: mutt_curses.h:110
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41
int mutt_str_asprintf(char **strp, const char *fmt,...)
Definition: string.c:1258

+ 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:785
#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:141
WHERE short C_Timeout
Config: Time to wait for user input in menus.
Definition: globals.h:150
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:202
#define mutt_curs_set(x)
Definition: mutt_curses.h:94
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:137

+ 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:81
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:190
Error message.
Definition: mutt_curses.h:132
WHERE bool OptMsgErr
(pseudo) used by mutt_error/mutt_message
Definition: options.h:38
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41
WHERE bool OptKeepQuiet
(pseudo) shut up the message and refresh functions while we are executing an external program...
Definition: options.h:36

+ 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:45
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:99

+ 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:83
#define mutt_debug(LEVEL,...)
Definition: logging.h:80
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 532 of file curs_lib.c.

533 {
534  struct termios t;
535  struct termios old;
536 
537  int fd = open("/dev/tty", O_RDONLY);
538  if (fd < 0)
539  return EOF;
540  tcgetattr(fd, &t);
541  memcpy((void *) &old, (void *) &t, sizeof(struct termios)); /* save original state */
542  t.c_lflag &= ~(ICANON | ECHO);
543  t.c_cc[VMIN] = 1;
544  t.c_cc[VTIME] = 0;
545  tcsetattr(fd, TCSADRAIN, &t);
546  fflush(stdout);
547  if (s)
548  fputs(s, stdout);
549  else
550  fputs(_("Press any key to continue..."), stdout);
551  fflush(stdout);
552  int ch = fgetc(stdin);
553  fflush(stdin);
554  tcsetattr(fd, TCSADRAIN, &old);
555  close(fd);
556  fputs("\r\n", stdout);
558  return (ch >= 0) ? ch : EOF;
559 }
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:141

+ 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 570 of file curs_lib.c.

572 {
573  int rc;
574 
575  if (!C_Pager || (mutt_str_strcmp(C_Pager, "builtin") == 0))
576  rc = mutt_pager(banner, tempfile, do_color, info);
577  else
578  {
579  struct Buffer *cmd = mutt_buffer_pool_get();
580 
581  mutt_endwin();
583  if (mutt_system(mutt_b2s(cmd)) == -1)
584  {
585  mutt_error(_("Error running \"%s\""), mutt_b2s(cmd));
586  rc = -1;
587  }
588  else
589  rc = 0;
590  mutt_file_unlink(tempfile);
592  }
593 
594  return rc;
595 }
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:42
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:499
#define mutt_error(...)
Definition: logging.h:83
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:1393
WHERE char * C_Pager
Config: External command for viewing messages, or &#39;builtin&#39; to use NeoMutt&#39;s.
Definition: globals.h:130
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:2233
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: buffer.c:409
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:618
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:50
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: buffer.c:398

+ 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 610 of file curs_lib.c.

612 {
613  struct Buffer *fname = mutt_buffer_pool_get();
614 
615  mutt_buffer_addstr(fname, NONULL(buf));
616  int rc = mutt_buffer_enter_fname_full(prompt, fname, mailbox, multiple, files,
617  numfiles, flags);
618  mutt_str_strfcpy(buf, mutt_b2s(fname), buflen);
619 
620  mutt_buffer_pool_release(&fname);
621  return rc;
622 }
#define NONULL(x)
Definition: string2.h:36
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:264
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:636
#define mutt_b2s(buf)
Definition: buffer.h:42
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:753
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: buffer.c:409
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: buffer.c:398

+ 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 636 of file curs_lib.c.

639 {
640  struct Event ch;
641 
643  mutt_window_mvaddstr(MuttMessageWindow, 0, 0, (char *) prompt);
644  addstr(_(" ('?' for list): "));
645  NORMAL_COLOR;
646  if (mutt_buffer_len(fname))
647  addstr(mutt_b2s(fname));
649  mutt_refresh();
650 
651  do
652  {
653  ch = mutt_getch();
654  } while (ch.ch == -2);
655  if (ch.ch < 0)
656  {
658  return -1;
659  }
660  else if (ch.ch == '?')
661  {
662  mutt_refresh();
663  mutt_buffer_reset(fname);
664 
665  if (flags == MUTT_SEL_NO_FLAGS)
666  flags = MUTT_SEL_FOLDER;
667  if (multiple)
668  flags |= MUTT_SEL_MULTI;
669  if (mailbox)
670  flags |= MUTT_SEL_MAILBOX;
671  mutt_buffer_select_file(fname, flags, files, numfiles);
672  }
673  else
674  {
675  char *pc = mutt_mem_malloc(mutt_str_strlen(prompt) + 3);
676 
677  sprintf(pc, "%s: ", prompt);
678  mutt_unget_event(ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
679 
680  mutt_buffer_increase_size(fname, 1024);
681  if (mutt_get_field_full(pc, fname->data, fname->dsize,
682  (mailbox ? MUTT_EFILE : MUTT_FILE) | MUTT_CLEAR,
683  multiple, files, numfiles) != 0)
684  mutt_buffer_reset(fname);
685  else
686  mutt_buffer_fix_dptr(fname);
687  FREE(&pc);
688  }
689 
690  return 0;
691 }
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:83
#define MUTT_CLEAR
Clear input if printable character is pressed.
Definition: mutt.h:67
void mutt_buffer_increase_size(struct Buffer *buf, size_t new_size)
Increase the allocated size of a buffer.
Definition: buffer.c:347
void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, char ***files, int *numfiles)
Let the user select a file.
Definition: browser.c:1128
#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:81
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:700
#define _(a)
Definition: message.h:28
Question/user input.
Definition: mutt_curses.h:143
#define MUTT_SEL_NO_FLAGS
No flags are set.
Definition: browser.h:41
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:669
#define MUTT_SEL_FOLDER
Select a local directory.
Definition: browser.h:44
An event such as a keypress.
Definition: mutt_curses.h:108
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:69
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:221
#define mutt_b2s(buf)
Definition: buffer.h:42
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:99
struct Event mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:180
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:438
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:97
char * data
pointer to data
Definition: buffer.h:35
#define SET_COLOR(X)
Definition: mutt_curses.h:224
#define MUTT_SEL_MULTI
Multi-selection is enabled.
Definition: browser.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
#define MUTT_FILE
Do file completion.
Definition: mutt.h:63
#define MUTT_SEL_MAILBOX
Select a mailbox.
Definition: browser.h:42
#define MUTT_EFILE
Do file completion, plus incoming folders.
Definition: mutt.h:64
#define FREE(x)
Definition: memory.h:40
int ch
raw key pressed
Definition: mutt_curses.h:110
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41
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:251

+ 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 700 of file curs_lib.c.

701 {
702  struct Event tmp;
703 
704  tmp.ch = ch;
705  tmp.op = op;
706 
707  if (UngetCount >= UngetLen)
708  mutt_mem_realloc(&UngetKeyEvents, (UngetLen += 16) * sizeof(struct Event));
709 
710  UngetKeyEvents[UngetCount++] = tmp;
711 }
int op
function op
Definition: mutt_curses.h:111
static size_t UngetCount
Definition: curs_lib.c:90
An event such as a keypress.
Definition: mutt_curses.h:108
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:121
int ch
raw key pressed
Definition: mutt_curses.h:110
static size_t UngetLen
Definition: curs_lib.c:91
static struct Event * UngetKeyEvents
Definition: curs_lib.c:92

+ 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 719 of file curs_lib.c.

720 {
721  const char *p = s + mutt_str_strlen(s) - 1;
722 
723  while (p >= s)
724  {
725  mutt_unget_event((unsigned char) *p--, 0);
726  }
727 }
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:700
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:669

+ 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 737 of file curs_lib.c.

738 {
739  struct Event tmp;
740 
741  tmp.ch = ch;
742  tmp.op = op;
743 
745  mutt_mem_realloc(&MacroEvents, (MacroBufferLen += 128) * sizeof(struct Event));
746 
747  MacroEvents[MacroBufferCount++] = tmp;
748 }
static size_t MacroBufferCount
Definition: curs_lib.c:83
int op
function op
Definition: mutt_curses.h:111
An event such as a keypress.
Definition: mutt_curses.h:108
static struct Event * MacroEvents
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:121
static size_t MacroBufferLen
Definition: curs_lib.c:84
int ch
raw key pressed
Definition: mutt_curses.h:110

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 756 of file curs_lib.c.

757 {
758  UngetCount = 0;
759  while (MacroBufferCount > 0)
760  {
761  if (MacroEvents[--MacroBufferCount].op == OP_END_COND)
762  return;
763  }
764 }
static size_t MacroBufferCount
Definition: curs_lib.c:83
int op
function op
Definition: mutt_curses.h:111
static size_t UngetCount
Definition: curs_lib.c:90
static struct Event * MacroEvents
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 773 of file curs_lib.c.

774 {
775  while (UngetCount > 0)
776  {
777  if (UngetKeyEvents[--UngetCount].op == OP_END_COND)
778  return;
779  }
780 }
int op
function op
Definition: mutt_curses.h:111
static size_t UngetCount
Definition: curs_lib.c:90
static struct Event * UngetKeyEvents
Definition: curs_lib.c:92

+ Here is the caller graph for this function:

void mutt_flushinp ( void  )

Empty all the keyboard buffers.

Definition at line 785 of file curs_lib.c.

786 {
787  UngetCount = 0;
788  MacroBufferCount = 0;
789  flushinp();
790 }
static size_t MacroBufferCount
Definition: curs_lib.c:83
static size_t UngetCount
Definition: curs_lib.c:90

+ 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 824 of file curs_lib.c.

825 {
826  struct Event ch;
827  int choice;
828  bool redraw = true;
829  int prompt_lines = 1;
830 
831  while (true)
832  {
833  if (redraw || SigWinch)
834  {
835  redraw = false;
836  if (SigWinch)
837  {
838  SigWinch = 0;
840  clearok(stdscr, TRUE);
842  }
843  if (MuttMessageWindow->cols)
844  {
845  prompt_lines = (mutt_strwidth(prompt) + MuttMessageWindow->cols - 1) /
847  prompt_lines = MAX(1, MIN(3, prompt_lines));
848  }
849  if (prompt_lines != MuttMessageWindow->rows)
850  {
851  mutt_window_reflow_message_rows(prompt_lines);
853  }
854 
856 
857  if ((ColorDefs[MT_COLOR_OPTIONS] != 0) &&
859  {
860  char *cur = NULL;
861 
862  while ((cur = strchr(prompt, '(')))
863  {
864  // write the part between prompt and cur using MT_COLOR_PROMPT
865  SET_COLOR(MT_COLOR_PROMPT);
866  addnstr(prompt, cur - prompt);
867 
868  if (isalnum(cur[1]) && (cur[2] == ')'))
869  {
870  // we have a single letter within parentheses
872  addch(cur[1]);
873  prompt = cur + 3;
874  }
875  else
876  {
877  // we have a parenthesis followed by something else
878  addch(cur[0]);
879  prompt = cur + 1;
880  }
881  }
882  }
883 
884  SET_COLOR(MT_COLOR_PROMPT);
885  addstr(prompt);
886  NORMAL_COLOR;
887 
888  addch(' ');
890  }
891 
892  mutt_refresh();
893  /* SigWinch is not processed unless timeout is set */
894  mutt_getch_timeout(30 * 1000);
895  ch = mutt_getch();
896  mutt_getch_timeout(-1);
897  if (ch.ch == -2)
898  continue;
899  /* (ch.ch == 0) is technically possible. Treat the same as < 0 (abort) */
900  if ((ch.ch <= 0) || CI_is_return(ch.ch))
901  {
902  choice = -1;
903  break;
904  }
905  else
906  {
907  char *p = strchr(letters, ch.ch);
908  if (p)
909  {
910  choice = p - letters + 1;
911  break;
912  }
913  else if ((ch.ch <= '9') && (ch.ch > '0'))
914  {
915  choice = ch.ch - '0';
916  if (choice <= mutt_str_strlen(letters))
917  break;
918  }
919  }
920  BEEP();
921  }
922  if (MuttMessageWindow->rows != 1)
923  {
926  }
927  else
929  mutt_refresh();
930  return choice;
931 }
#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:81
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
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:669
An event such as a keypress.
Definition: mutt_curses.h:108
#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:69
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:293
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:99
struct Event mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:180
int mutt_strwidth(const char *s)
Measure a string&#39;s width in screen cells.
Definition: curs_lib.c:1239
#define BEEP()
Definition: mutt_curses.h:80
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
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:162
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:137
int ch
raw key pressed
Definition: mutt_curses.h:110
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41

+ 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 939 of file curs_lib.c.

940 {
941  char buf[MB_LEN_MAX * 2];
942  mbstate_t mbstate;
943  size_t n1, n2;
944 
945  memset(&mbstate, 0, sizeof(mbstate));
946  if (((n1 = wcrtomb(buf, wc, &mbstate)) == (size_t)(-1)) ||
947  ((n2 = wcrtomb(buf + n1, 0, &mbstate)) == (size_t)(-1)))
948  {
949  return -1; /* ERR */
950  }
951  else
952  {
953  return addstr(buf);
954  }
955 }

+ 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 973 of file curs_lib.c.

976 {
977  wchar_t wc;
978  int w;
979  size_t k, k2;
980  char scratch[MB_LEN_MAX];
981  mbstate_t mbstate1, mbstate2;
982  int escaped = 0;
983 
984  memset(&mbstate1, 0, sizeof(mbstate1));
985  memset(&mbstate2, 0, sizeof(mbstate2));
986  buflen--;
987  char *p = buf;
988  for (; n && (k = mbrtowc(&wc, s, n, &mbstate1)); s += k, n -= k)
989  {
990  if ((k == (size_t)(-1)) || (k == (size_t)(-2)))
991  {
992  if ((k == (size_t)(-1)) && (errno == EILSEQ))
993  memset(&mbstate1, 0, sizeof(mbstate1));
994 
995  k = (k == (size_t)(-1)) ? 1 : n;
996  wc = ReplacementChar;
997  }
998  if (escaped)
999  {
1000  escaped = 0;
1001  w = 0;
1002  }
1003  else if (arboreal && (wc == MUTT_SPECIAL_INDEX))
1004  {
1005  escaped = 1;
1006  w = 0;
1007  }
1008  else if (arboreal && (wc < MUTT_TREE_MAX))
1009  {
1010  w = 1; /* hack */
1011  }
1012  else
1013  {
1014 #ifdef HAVE_ISWBLANK
1015  if (iswblank(wc))
1016  wc = ' ';
1017  else
1018 #endif
1019  if (!IsWPrint(wc))
1020  wc = '?';
1021  w = wcwidth(wc);
1022  }
1023  if (w >= 0)
1024  {
1025  if ((w > max_width) || ((k2 = wcrtomb(scratch, wc, &mbstate2)) > buflen))
1026  continue;
1027  min_width -= w;
1028  max_width -= w;
1029  strncpy(p, scratch, k2);
1030  p += k2;
1031  buflen -= k2;
1032  }
1033  }
1034  w = ((int) buflen < min_width) ? buflen : min_width;
1035  if (w <= 0)
1036  *p = '\0';
1037  else if (justify == JUSTIFY_RIGHT) /* right justify */
1038  {
1039  p[w] = '\0';
1040  while (--p >= buf)
1041  p[w] = *p;
1042  while (--w >= 0)
1043  buf[w] = pad_char;
1044  }
1045  else if (justify == JUSTIFY_CENTER) /* center */
1046  {
1047  char *savedp = p;
1048  int half = (w + 1) / 2; /* half of cushion space */
1049 
1050  p[w] = '\0';
1051 
1052  /* move str to center of buffer */
1053  while (--p >= buf)
1054  p[half] = *p;
1055 
1056  /* fill rhs */
1057  p = savedp + half;
1058  while (--w >= half)
1059  *p++ = pad_char;
1060 
1061  /* fill lhs */
1062  while (half--)
1063  buf[half] = pad_char;
1064  }
1065  else /* left justify */
1066  {
1067  while (--w >= 0)
1068  *p++ = pad_char;
1069  *p = '\0';
1070  }
1071 }
#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 1087 of file curs_lib.c.

1088 {
1089  enum FormatJustify justify = JUSTIFY_RIGHT;
1090  char *p = NULL;
1091  int min_width;
1092  int max_width = INT_MAX;
1093 
1094  if (*prec == '-')
1095  {
1096  prec++;
1097  justify = JUSTIFY_LEFT;
1098  }
1099  else if (*prec == '=')
1100  {
1101  prec++;
1102  justify = JUSTIFY_CENTER;
1103  }
1104  min_width = strtol(prec, &p, 10);
1105  if (*p == '.')
1106  {
1107  prec = p + 1;
1108  max_width = strtol(prec, &p, 10);
1109  if (p <= prec)
1110  max_width = INT_MAX;
1111  }
1112 
1113  mutt_simple_format(buf, buflen, min_width, max_width, justify, ' ', s,
1114  mutt_str_strlen(s), arboreal);
1115 }
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:669
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:973

+ 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 1124 of file curs_lib.c.

1125 {
1126  mutt_format_s_x(buf, buflen, prec, s, false);
1127 }
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:1087

+ 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 1136 of file curs_lib.c.

1137 {
1138  mutt_format_s_x(buf, buflen, prec, s, true);
1139 }
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:1087

+ 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 1146 of file curs_lib.c.

1147 {
1148  wchar_t wc;
1149  size_t k;
1150  size_t len = mutt_str_strlen(s);
1151  mbstate_t mbstate;
1152 
1153  memset(&mbstate, 0, sizeof(mbstate));
1154  for (; len && (k = mbrtowc(&wc, s, len, &mbstate)); s += k, len -= k)
1155  {
1156  if ((k == (size_t)(-1)) || (k == (size_t)(-2)))
1157  {
1158  if (k == (size_t)(-1))
1159  memset(&mbstate, 0, sizeof(mbstate));
1160  k = (k == (size_t)(-1)) ? 1 : len;
1161  wc = ReplacementChar;
1162  }
1163  if (!IsWPrint(wc))
1164  wc = '?';
1165  const int w = wcwidth(wc);
1166  if (w >= 0)
1167  {
1168  if (w > n)
1169  break;
1170  addnstr((char *) s, k);
1171  n -= w;
1172  }
1173  }
1174  while (n-- > 0)
1175  addch(' ');
1176 }
#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:669
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 1189 of file curs_lib.c.

1190 {
1191  wchar_t wc;
1192  size_t n, w = 0, l = 0, cl;
1193  int cw;
1194  mbstate_t mbstate;
1195 
1196  if (!src)
1197  goto out;
1198 
1199  n = mutt_str_strlen(src);
1200 
1201  memset(&mbstate, 0, sizeof(mbstate));
1202  for (w = 0; n && (cl = mbrtowc(&wc, src, n, &mbstate)); src += cl, n -= cl)
1203  {
1204  if ((cl == (size_t)(-1)) || (cl == (size_t)(-2)))
1205  {
1206  if (cl == (size_t)(-1))
1207  memset(&mbstate, 0, sizeof(mbstate));
1208  cl = (cl == (size_t)(-1)) ? 1 : n;
1209  wc = ReplacementChar;
1210  }
1211  cw = wcwidth(wc);
1212  /* hack because MUTT_TREE symbols aren't turned into characters
1213  * until rendered by print_enriched_string (#3364) */
1214  if ((cw < 0) && (src[0] == MUTT_SPECIAL_INDEX))
1215  {
1216  cl = 2; /* skip the index coloring sequence */
1217  cw = 0;
1218  }
1219  else if ((cw < 0) && (cl == 1) && (src[0] != '\0') && (src[0] < MUTT_TREE_MAX))
1220  cw = 1;
1221  else if (cw < 0)
1222  cw = 0; /* unprintable wchar */
1223  if ((cl + l > maxlen) || (cw + w > maxwid))
1224  break;
1225  l += cl;
1226  w += cw;
1227  }
1228 out:
1229  if (width)
1230  *width = w;
1231  return l;
1232 }
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:669
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 1239 of file curs_lib.c.

1240 {
1241  if (!s)
1242  return 0;
1243 
1244  wchar_t wc;
1245  int w;
1246  size_t k;
1247  mbstate_t mbstate;
1248 
1249  size_t n = mutt_str_strlen(s);
1250 
1251  memset(&mbstate, 0, sizeof(mbstate));
1252  for (w = 0; n && (k = mbrtowc(&wc, s, n, &mbstate)); s += k, n -= k)
1253  {
1254  if (*s == MUTT_SPECIAL_INDEX)
1255  {
1256  s += 2; /* skip the index coloring sequence */
1257  k = 0;
1258  continue;
1259  }
1260 
1261  if ((k == (size_t)(-1)) || (k == (size_t)(-2)))
1262  {
1263  if (k == (size_t)(-1))
1264  memset(&mbstate, 0, sizeof(mbstate));
1265  k = (k == (size_t)(-1)) ? 1 : n;
1266  wc = ReplacementChar;
1267  }
1268  if (!IsWPrint(wc))
1269  wc = '?';
1270  w += wcwidth(wc);
1271  }
1272  return w;
1273 }
#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:669
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 73 of file curs_lib.c.

size_t MacroBufferCount = 0
static

Definition at line 83 of file curs_lib.c.

size_t MacroBufferLen = 0
static

Definition at line 84 of file curs_lib.c.

struct Event* MacroEvents
static

Definition at line 85 of file curs_lib.c.

size_t UngetCount = 0
static

Definition at line 90 of file curs_lib.c.

size_t UngetLen = 0
static

Definition at line 91 of file curs_lib.c.

struct Event* UngetKeyEvents
static

Definition at line 92 of file curs_lib.c.

int MuttGetchTimeout = -1

Timeout in ms for mutt_getch()

Definition at line 94 of file curs_lib.c.