NeoMutt  2018-07-16 +952-a2da0a
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 "menu.h"
#include "mutt_curses.h"
#include "mutt_logging.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, int complete, bool multiple, char ***files, int *numfiles)
 Ask the user for a string. More...
 
int mutt_get_field_unbuffered (char *msg, char *buf, size_t buflen, int 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...
 
int mutt_yesorno (const char *msg, int 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, int 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, int 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, int justify, char pad_char, const char *s, size_t n, int arboreal)
 Format a string, like snprintf() More...
 
static void format_s_x (char *buf, size_t buflen, const char *prec, const char *s, int 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...
 
bool message_is_visible (struct Context *ctx, int index)
 Is a message in the index within limit. More...
 
bool message_is_tagged (struct Context *ctx, int index)
 Is a message in the index tagged (and within limit) More...
 

Variables

bool 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) && MetaKey)
224  {
225  /* send ALT-x as ESC-x */
226  ch &= ~0x80;
227  mutt_unget_event(ch, 0);
228  ret.ch = '\033';
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 }
void mutt_sig_allow_interrupt(int disposition)
Allow/disallow Ctrl-C (SIGINT)
Definition: signal.c:231
bool MetaKey
Config: Interpret &#39;ALT-x&#39; as &#39;ESC-x&#39;.
Definition: curs_lib.c:73
static size_t MacroBufferCount
Definition: curs_lib.c:83
WHERE SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: globals.h:90
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:668
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:466
static size_t UngetCount
Definition: curs_lib.c:90
An event such as a keypress.
Definition: mutt_curses.h:107
static struct Event * MacroEvents
Definition: curs_lib.c:85
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:197
int ch
raw key pressed
Definition: mutt_curses.h:109
#define ctrl(c)
Definition: mutt_curses.h:96
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,
int  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 for completion, e.g. MUTT_FILE
[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 }
int mutt_enter_string_full(char *buf, size_t buflen, int col, int flags, bool multiple, char ***files, int *numfiles, struct EnterState *state)
Ask the user for a string.
Definition: enter.c:176
#define NORMAL_COLOR
Definition: mutt_curses.h:235
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:142
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:91
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:806
#define SETCOLOR(X)
Definition: mutt_curses.h:220
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41
struct EnterState * mutt_enter_state_new(void)
Create a new EnterState.
Definition: enter.c:125

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Ask the user for a string (ignoring macro buffer)

Parameters
msgPrompt
bufBuffer for the result
buflenLength of buffer
flagsFlags for completion, e.g. MUTT_FILE
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(A, B, C, D)
Definition: curs_lib.h:78

+ 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  char cmd[HUGE_STRING];
311 
312  mutt_endwin();
313  mutt_file_expand_fmt_quote(cmd, sizeof(cmd), editor, file);
314  if (mutt_system(cmd) != 0)
315  {
316  mutt_error(_("Error running \"%s\""), cmd);
317  }
318  /* the terminal may have been resized while the editor owned it */
320  keypad(stdscr, true);
321  clearok(stdscr, true);
322 }
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
#define HUGE_STRING
Definition: string2.h:37
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:498
#define mutt_error(...)
Definition: logging.h:88
void mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1323
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:50

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int mutt_yesorno ( const char *  msg,
int  def 
)

Ask the user a Yes/No question.

Parameters
msgPrompt
defDefault answer, e.g. MUTT_YES
Return values
numSelection made, e.g. MUTT_NO

Definition at line 330 of file curs_lib.c.

331 {
332  struct Event ch;
333  char *yes = _("yes");
334  char *no = _("no");
335  char *answer_string = NULL;
336  int answer_string_wid, msg_wid;
337  size_t trunc_msg_len;
338  bool redraw = true;
339  int prompt_lines = 1;
340 
341  char *expr = NULL;
342  regex_t reyes;
343  regex_t reno;
344  char answer[2];
345 
346  answer[1] = '\0';
347 
348  bool reyes_ok = (expr = nl_langinfo(YESEXPR)) && (expr[0] == '^') &&
349  (REGCOMP(&reyes, expr, REG_NOSUB) == 0);
350  bool reno_ok = (expr = nl_langinfo(NOEXPR)) && (expr[0] == '^') &&
351  (REGCOMP(&reno, expr, REG_NOSUB) == 0);
352 
353  /* In order to prevent the default answer to the question to wrapped
354  * around the screen in the even the question is wider than the screen,
355  * ensure there is enough room for the answer and truncate the question
356  * to fit.
357  */
358  safe_asprintf(&answer_string, " ([%s]/%s): ", def == MUTT_YES ? yes : no,
359  def == MUTT_YES ? no : yes);
360  answer_string_wid = mutt_strwidth(answer_string);
361  msg_wid = mutt_strwidth(msg);
362 
363  while (true)
364  {
365  if (redraw || SigWinch)
366  {
367  redraw = false;
368  if (SigWinch)
369  {
370  SigWinch = 0;
372  clearok(stdscr, TRUE);
374  }
375  if (MuttMessageWindow->cols)
376  {
377  prompt_lines = (msg_wid + answer_string_wid + MuttMessageWindow->cols - 1) /
379  prompt_lines = MAX(1, MIN(3, prompt_lines));
380  }
381  if (prompt_lines != MuttMessageWindow->rows)
382  {
383  mutt_window_reflow_message_rows(prompt_lines);
385  }
386 
387  /* maxlen here is sort of arbitrary, so pick a reasonable upper bound */
388  trunc_msg_len = mutt_wstr_trunc(
389  msg, 4 * prompt_lines * MuttMessageWindow->cols,
390  prompt_lines * MuttMessageWindow->cols - answer_string_wid, NULL);
391 
394  addnstr(msg, trunc_msg_len);
395  addstr(answer_string);
396  NORMAL_COLOR;
398  }
399 
400  mutt_refresh();
401  /* SigWinch is not processed unless timeout is set */
402  mutt_getch_timeout(30 * 1000);
403  ch = mutt_getch();
404  mutt_getch_timeout(-1);
405  if (ch.ch == -2)
406  continue;
407  if (CI_is_return(ch.ch))
408  break;
409  if (ch.ch < 0)
410  {
411  def = MUTT_ABORT;
412  break;
413  }
414 
415  answer[0] = ch.ch;
416  if (reyes_ok ? (regexec(&reyes, answer, 0, 0, 0) == 0) : (tolower(ch.ch) == 'y'))
417  {
418  def = MUTT_YES;
419  break;
420  }
421  else if (reno_ok ? (regexec(&reno, answer, 0, 0, 0) == 0) : (tolower(ch.ch) == 'n'))
422  {
423  def = MUTT_NO;
424  break;
425  }
426  else
427  {
428  BEEP();
429  }
430  }
431 
432  FREE(&answer_string);
433 
434  if (reyes_ok)
435  regfree(&reyes);
436  if (reno_ok)
437  regfree(&reno);
438 
439  if (MuttMessageWindow->rows != 1)
440  {
443  }
444  else
446 
447  if (def != MUTT_ABORT)
448  {
449  addstr((char *) (def == MUTT_YES ? yes : no));
450  mutt_refresh();
451  }
452  else
453  {
454  /* when the users cancels with ^G, clear the message stored with
455  * mutt_message() so it isn't displayed when the screen is refreshed. */
457  }
458  return def;
459 }
#define MIN(a, b)
Definition: memory.h:31
int safe_asprintf(char **, const char *,...)
Definition: safe_asprintf.c:77
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:235
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:142
An event such as a keypress.
Definition: mutt_curses.h:107
#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:91
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:278
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:1176
#define BEEP()
Definition: mutt_curses.h:79
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:1126
#define CI_is_return(c)
Definition: mutt_curses.h:101
int mutt_window_move(struct MuttWindow *win, int row, int col)
Move the cursor in a Window.
Definition: mutt_window.c:162
#define SETCOLOR(X)
Definition: mutt_curses.h:220
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:137
#define FREE(x)
Definition: memory.h:46
int ch
raw key pressed
Definition: mutt_curses.h:109
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41
#define REGCOMP(X, Y, Z)
Compile a regular expression.
Definition: regex3.h:52

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

467 {
468  mutt_flushinp();
469  curs_set(1);
470  if (Timeout)
471  mutt_getch_timeout(-1); /* restore blocking operation */
472  if (mutt_yesorno(_("Exit NeoMutt?"), MUTT_YES) == MUTT_YES)
473  {
474  mutt_exit(1);
475  }
477  mutt_curs_set(-1);
478  SigInt = 0;
479 }
#define curs_set(x)
Definition: mutt_curses.h:87
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:90
int mutt_yesorno(const char *msg, int def)
Ask the user a Yes/No question.
Definition: curs_lib.c:330
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:753
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:141
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:197
#define mutt_curs_set(x)
Definition: mutt_curses.h:93
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:137
WHERE short Timeout
Config: Time to wait for user input in menus.
Definition: globals.h:155

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

485 {
487  return;
488 
491  NORMAL_COLOR;
493 }
#define NORMAL_COLOR
Definition: mutt_curses.h:235
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:81
WHERE char ErrorBuf[STRING]
Copy of the last error message.
Definition: globals.h:44
Informational message.
Definition: mutt_curses.h:136
WHERE bool ErrorBufMessage
true if the last message was an error
Definition: globals.h:43
int mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:190
#define SETCOLOR(X)
Definition: mutt_curses.h:220
Error message.
Definition: mutt_curses.h:131
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 498 of file curs_lib.c.

499 {
500  if (OptNoCurses)
501  return;
502 
503  int e = errno;
504 
505  /* at least in some situations (screen + xterm under SuSE11/12) endwin()
506  * doesn't properly flush the screen without an explicit call. */
507  mutt_refresh();
508  endwin();
509 
510  errno = e;
511 }
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 517 of file curs_lib.c.

518 {
519  char *p = strerror(errno);
520 
521  mutt_debug(1, "%s: %s (errno = %d)\n", s, p ? p : "unknown error", errno);
522  mutt_error("%s: %s (errno = %d)", s, p ? p : _("unknown error"), errno);
523 }
#define _(a)
Definition: message.h:28
#define mutt_error(...)
Definition: logging.h:88
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
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 531 of file curs_lib.c.

532 {
533  struct termios t;
534  struct termios old;
535  int f, ch;
536 
537  f = open("/dev/tty", O_RDONLY);
538  if (f < 0)
539  return EOF;
540  tcgetattr(f, &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(f, 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  ch = fgetc(stdin);
553  fflush(stdin);
554  tcsetattr(f, TCSADRAIN, &old);
555  close(f);
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,
int  do_color,
struct Pager info 
)

Display some page-able text to the user.

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

Definition at line 570 of file curs_lib.c.

571 {
572  int rc;
573 
574  if (!Pager || (mutt_str_strcmp(Pager, "builtin") == 0))
575  rc = mutt_pager(banner, tempfile, do_color, info);
576  else
577  {
578  char cmd[STRING];
579 
580  mutt_endwin();
581  mutt_file_expand_fmt_quote(cmd, sizeof(cmd), Pager, tempfile);
582  if (mutt_system(cmd) == -1)
583  {
584  mutt_error(_("Error running \"%s\""), cmd);
585  rc = -1;
586  }
587  else
588  rc = 0;
589  mutt_file_unlink(tempfile);
590  }
591 
592  return rc;
593 }
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:192
#define _(a)
Definition: message.h:28
An email being displayed.
Definition: pager.h:63
int mutt_pager(const char *banner, const char *fname, int flags, struct Pager *extra)
Display a file, or help, in a window.
Definition: pager.c:2203
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:498
#define STRING
Definition: string2.h:35
#define mutt_error(...)
Definition: logging.h:88
void mutt_file_expand_fmt_quote(char *dest, size_t destlen, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1323
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:612
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:50

+ 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,
int  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, e.g. MUTT_SEL_FOLDER
Return values
0Success
-1Error

Definition at line 608 of file curs_lib.c.

610 {
611  struct Event ch;
612 
614  mutt_window_mvaddstr(MuttMessageWindow, 0, 0, (char *) prompt);
615  addstr(_(" ('?' for list): "));
616  NORMAL_COLOR;
617  if (buf[0])
618  addstr(buf);
620  mutt_refresh();
621 
622  do
623  {
624  ch = mutt_getch();
625  } while (ch.ch == -2);
626  if (ch.ch < 0)
627  {
629  return -1;
630  }
631  else if (ch.ch == '?')
632  {
633  mutt_refresh();
634  buf[0] = '\0';
635 
636  if (!flags)
637  flags = MUTT_SEL_FOLDER;
638  if (multiple)
639  flags |= MUTT_SEL_MULTI;
640  if (mailbox)
641  flags |= MUTT_SEL_MAILBOX;
642  mutt_select_file(buf, buflen, flags, files, numfiles);
643  }
644  else
645  {
646  char *pc = mutt_mem_malloc(mutt_str_strlen(prompt) + 3);
647 
648  sprintf(pc, "%s: ", prompt);
649  mutt_unget_event(ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
650  if (mutt_get_field_full(pc, buf, buflen, (mailbox ? MUTT_EFILE : MUTT_FILE) | MUTT_CLEAR,
651  multiple, files, numfiles) != 0)
652  {
653  buf[0] = '\0';
654  }
655  FREE(&pc);
656  }
657 
658  return 0;
659 }
#define MUTT_CLEAR
clear input if printable character is pressed
Definition: mutt.h:63
void mutt_select_file(char *file, size_t filelen, int flags, char ***files, int *numfiles)
Let the user select a file.
Definition: browser.c:1087
#define NORMAL_COLOR
Definition: mutt_curses.h:235
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:81
int mutt_get_field_full(const char *field, char *buf, size_t buflen, int complete, bool multiple, char ***files, int *numfiles)
Ask the user for a string.
Definition: curs_lib.c:251
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:668
#define _(a)
Definition: message.h:28
Question/user input.
Definition: mutt_curses.h:142
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:663
#define MUTT_SEL_FOLDER
Definition: browser.h:42
An event such as a keypress.
Definition: mutt_curses.h:107
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:69
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
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:99
#define MUTT_SEL_MULTI
Definition: browser.h:41
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:59
#define SETCOLOR(X)
Definition: mutt_curses.h:220
#define MUTT_SEL_MAILBOX
Definition: browser.h:40
#define MUTT_EFILE
do file completion, plus incoming folders
Definition: mutt.h:60
#define FREE(x)
Definition: memory.h:46
int ch
raw key pressed
Definition: mutt_curses.h:109
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:

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

669 {
670  struct Event tmp;
671 
672  tmp.ch = ch;
673  tmp.op = op;
674 
675  if (UngetCount >= UngetLen)
676  mutt_mem_realloc(&UngetKeyEvents, (UngetLen += 16) * sizeof(struct Event));
677 
678  UngetKeyEvents[UngetCount++] = tmp;
679 }
int op
function op
Definition: mutt_curses.h:110
static size_t UngetCount
Definition: curs_lib.c:90
An event such as a keypress.
Definition: mutt_curses.h:107
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:124
int ch
raw key pressed
Definition: mutt_curses.h:109
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 687 of file curs_lib.c.

688 {
689  const char *p = s + mutt_str_strlen(s) - 1;
690 
691  while (p >= s)
692  {
693  mutt_unget_event((unsigned char) *p--, 0);
694  }
695 }
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:668
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:663

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

706 {
707  struct Event tmp;
708 
709  tmp.ch = ch;
710  tmp.op = op;
711 
713  mutt_mem_realloc(&MacroEvents, (MacroBufferLen += 128) * sizeof(struct Event));
714 
715  MacroEvents[MacroBufferCount++] = tmp;
716 }
static size_t MacroBufferCount
Definition: curs_lib.c:83
int op
function op
Definition: mutt_curses.h:110
An event such as a keypress.
Definition: mutt_curses.h:107
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:124
static size_t MacroBufferLen
Definition: curs_lib.c:84
int ch
raw key pressed
Definition: mutt_curses.h:109

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

725 {
726  UngetCount = 0;
727  while (MacroBufferCount > 0)
728  {
729  if (MacroEvents[--MacroBufferCount].op == OP_END_COND)
730  return;
731  }
732 }
static size_t MacroBufferCount
Definition: curs_lib.c:83
int op
function op
Definition: mutt_curses.h:110
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 741 of file curs_lib.c.

742 {
743  while (UngetCount > 0)
744  {
745  if (UngetKeyEvents[--UngetCount].op == OP_END_COND)
746  return;
747  }
748 }
int op
function op
Definition: mutt_curses.h:110
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 753 of file curs_lib.c.

754 {
755  UngetCount = 0;
756  MacroBufferCount = 0;
757  flushinp();
758 }
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 792 of file curs_lib.c.

793 {
794  struct Event ch;
795  int choice;
796  bool redraw = true;
797  int prompt_lines = 1;
798  char *p = NULL;
799 
800  while (true)
801  {
802  if (redraw || SigWinch)
803  {
804  redraw = false;
805  if (SigWinch)
806  {
807  SigWinch = 0;
809  clearok(stdscr, TRUE);
811  }
812  if (MuttMessageWindow->cols)
813  {
814  prompt_lines = (mutt_strwidth(prompt) + MuttMessageWindow->cols - 1) /
816  prompt_lines = MAX(1, MIN(3, prompt_lines));
817  }
818  if (prompt_lines != MuttMessageWindow->rows)
819  {
820  mutt_window_reflow_message_rows(prompt_lines);
822  }
823 
826  NORMAL_COLOR;
828  }
829 
830  mutt_refresh();
831  /* SigWinch is not processed unless timeout is set */
832  mutt_getch_timeout(30 * 1000);
833  ch = mutt_getch();
834  mutt_getch_timeout(-1);
835  if (ch.ch == -2)
836  continue;
837  /* (ch.ch == 0) is technically possible. Treat the same as < 0 (abort) */
838  if (ch.ch <= 0 || CI_is_return(ch.ch))
839  {
840  choice = -1;
841  break;
842  }
843  else
844  {
845  p = strchr(letters, ch.ch);
846  if (p)
847  {
848  choice = p - letters + 1;
849  break;
850  }
851  else if (ch.ch <= '9' && ch.ch > '0')
852  {
853  choice = ch.ch - '0';
854  if (choice <= mutt_str_strlen(letters))
855  break;
856  }
857  }
858  BEEP();
859  }
860  if (MuttMessageWindow->rows != 1)
861  {
864  }
865  else
867  mutt_refresh();
868  return choice;
869 }
#define MIN(a, b)
Definition: memory.h:31
#define NORMAL_COLOR
Definition: mutt_curses.h:235
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:142
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:663
An event such as a keypress.
Definition: mutt_curses.h:107
#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:91
void mutt_window_reflow_message_rows(int mw_rows)
Resize the Message Window.
Definition: mutt_window.c:278
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:1176
#define BEEP()
Definition: mutt_curses.h:79
#define CI_is_return(c)
Definition: mutt_curses.h:101
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 SETCOLOR(X)
Definition: mutt_curses.h:220
void mutt_getch_timeout(int delay)
Set the getch() timeout.
Definition: curs_lib.c:137
int ch
raw key pressed
Definition: mutt_curses.h:109
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 877 of file curs_lib.c.

878 {
879  char buf[MB_LEN_MAX * 2];
880  mbstate_t mbstate;
881  size_t n1, n2;
882 
883  memset(&mbstate, 0, sizeof(mbstate));
884  if ((n1 = wcrtomb(buf, wc, &mbstate)) == (size_t)(-1) ||
885  (n2 = wcrtomb(buf + n1, 0, &mbstate)) == (size_t)(-1))
886  {
887  return -1; /* ERR */
888  }
889  else
890  {
891  return addstr(buf);
892  }
893 }

+ Here is the caller graph for this function:

void mutt_simple_format ( char *  buf,
size_t  buflen,
int  min_width,
int  max_width,
int  justify,
char  pad_char,
const char *  s,
size_t  n,
int  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. FMT_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 911 of file curs_lib.c.

913 {
914  wchar_t wc;
915  int w;
916  size_t k, k2;
917  char scratch[MB_LEN_MAX];
918  mbstate_t mbstate1, mbstate2;
919  int escaped = 0;
920 
921  memset(&mbstate1, 0, sizeof(mbstate1));
922  memset(&mbstate2, 0, sizeof(mbstate2));
923  buflen--;
924  char *p = buf;
925  for (; n && (k = mbrtowc(&wc, s, n, &mbstate1)); s += k, n -= k)
926  {
927  if (k == (size_t)(-1) || k == (size_t)(-2))
928  {
929  if (k == (size_t)(-1) && errno == EILSEQ)
930  memset(&mbstate1, 0, sizeof(mbstate1));
931 
932  k = (k == (size_t)(-1)) ? 1 : n;
933  wc = ReplacementChar;
934  }
935  if (escaped)
936  {
937  escaped = 0;
938  w = 0;
939  }
940  else if (arboreal && wc == MUTT_SPECIAL_INDEX)
941  {
942  escaped = 1;
943  w = 0;
944  }
945  else if (arboreal && wc < MUTT_TREE_MAX)
946  {
947  w = 1; /* hack */
948  }
949  else
950  {
951 #ifdef HAVE_ISWBLANK
952  if (iswblank(wc))
953  wc = ' ';
954  else
955 #endif
956  if (!IsWPrint(wc))
957  wc = '?';
958  w = wcwidth(wc);
959  }
960  if (w >= 0)
961  {
962  if (w > max_width || (k2 = wcrtomb(scratch, wc, &mbstate2)) > buflen)
963  continue;
964  min_width -= w;
965  max_width -= w;
966  strncpy(p, scratch, k2);
967  p += k2;
968  buflen -= k2;
969  }
970  }
971  w = (int) buflen < min_width ? buflen : min_width;
972  if (w <= 0)
973  *p = '\0';
974  else if (justify == FMT_RIGHT) /* right justify */
975  {
976  p[w] = '\0';
977  while (--p >= buf)
978  p[w] = *p;
979  while (--w >= 0)
980  buf[w] = pad_char;
981  }
982  else if (justify == FMT_CENTER) /* center */
983  {
984  char *savedp = p;
985  int half = (w + 1) / 2; /* half of cushion space */
986 
987  p[w] = '\0';
988 
989  /* move str to center of buffer */
990  while (--p >= buf)
991  p[half] = *p;
992 
993  /* fill rhs */
994  p = savedp + half;
995  while (--w >= half)
996  *p++ = pad_char;
997 
998  /* fill lhs */
999  while (half--)
1000  buf[half] = pad_char;
1001  }
1002  else /* left justify */
1003  {
1004  while (--w >= 0)
1005  *p++ = pad_char;
1006  *p = '\0';
1007  }
1008 }
#define IsWPrint(wc)
Definition: mbyte.h:41
#define MUTT_TREE_MAX
Definition: mutt.h:96
wchar_t ReplacementChar
When a Unicode character can&#39;t be displayed, use this instead.
Definition: charset.c:57
#define FMT_RIGHT
Definition: curs_lib.h:43
#define MUTT_SPECIAL_INDEX
Definition: mutt.h:98
#define EILSEQ
Definition: charset.c:48
#define FMT_CENTER
Definition: curs_lib.h:42

+ Here is the caller graph for this function:

static void format_s_x ( char *  buf,
size_t  buflen,
const char *  prec,
const char *  s,
int  arboreal 
)
static

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

1025 {
1026  int justify = FMT_RIGHT;
1027  char *p = NULL;
1028  int min_width;
1029  int max_width = INT_MAX;
1030 
1031  if (*prec == '-')
1032  {
1033  prec++;
1034  justify = FMT_LEFT;
1035  }
1036  else if (*prec == '=')
1037  {
1038  prec++;
1039  justify = FMT_CENTER;
1040  }
1041  min_width = strtol(prec, &p, 10);
1042  if (*p == '.')
1043  {
1044  prec = p + 1;
1045  max_width = strtol(prec, &p, 10);
1046  if (p <= prec)
1047  max_width = INT_MAX;
1048  }
1049 
1050  mutt_simple_format(buf, buflen, min_width, max_width, justify, ' ', s,
1051  mutt_str_strlen(s), arboreal);
1052 }
void mutt_simple_format(char *buf, size_t buflen, int min_width, int max_width, int justify, char pad_char, const char *s, size_t n, int arboreal)
Format a string, like snprintf()
Definition: curs_lib.c:911
#define FMT_LEFT
Definition: curs_lib.h:41
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:663
#define FMT_RIGHT
Definition: curs_lib.h:43
#define FMT_CENTER
Definition: curs_lib.h:42

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

1062 {
1063  format_s_x(buf, buflen, prec, s, 0);
1064 }
static void format_s_x(char *buf, size_t buflen, const char *prec, const char *s, int arboreal)
Format a string like snprintf()
Definition: curs_lib.c:1024

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

1074 {
1075  format_s_x(buf, buflen, prec, s, 1);
1076 }
static void format_s_x(char *buf, size_t buflen, const char *prec, const char *s, int arboreal)
Format a string like snprintf()
Definition: curs_lib.c:1024

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

1084 {
1085  wchar_t wc;
1086  size_t k;
1087  size_t len = mutt_str_strlen(s);
1088  mbstate_t mbstate;
1089 
1090  memset(&mbstate, 0, sizeof(mbstate));
1091  for (; len && (k = mbrtowc(&wc, s, len, &mbstate)); s += k, len -= k)
1092  {
1093  if (k == (size_t)(-1) || k == (size_t)(-2))
1094  {
1095  if (k == (size_t)(-1))
1096  memset(&mbstate, 0, sizeof(mbstate));
1097  k = (k == (size_t)(-1)) ? 1 : len;
1098  wc = ReplacementChar;
1099  }
1100  if (!IsWPrint(wc))
1101  wc = '?';
1102  const int w = wcwidth(wc);
1103  if (w >= 0)
1104  {
1105  if (w > n)
1106  break;
1107  addnstr((char *) s, k);
1108  n -= w;
1109  }
1110  }
1111  while (n-- > 0)
1112  addch(' ');
1113 }
#define IsWPrint(wc)
Definition: mbyte.h:41
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:663
wchar_t ReplacementChar
When a Unicode character can&#39;t be displayed, use this instead.
Definition: charset.c:57

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

1127 {
1128  wchar_t wc;
1129  size_t n, w = 0, l = 0, cl;
1130  int cw;
1131  mbstate_t mbstate;
1132 
1133  if (!src)
1134  goto out;
1135 
1136  n = mutt_str_strlen(src);
1137 
1138  memset(&mbstate, 0, sizeof(mbstate));
1139  for (w = 0; n && (cl = mbrtowc(&wc, src, n, &mbstate)); src += cl, n -= cl)
1140  {
1141  if (cl == (size_t)(-1) || cl == (size_t)(-2))
1142  {
1143  if (cl == (size_t)(-1))
1144  memset(&mbstate, 0, sizeof(mbstate));
1145  cl = (cl == (size_t)(-1)) ? 1 : n;
1146  wc = ReplacementChar;
1147  }
1148  cw = wcwidth(wc);
1149  /* hack because MUTT_TREE symbols aren't turned into characters
1150  * until rendered by print_enriched_string (#3364) */
1151  if ((cw < 0) && (src[0] == MUTT_SPECIAL_INDEX))
1152  {
1153  cl = 2; /* skip the index coloring sequence */
1154  cw = 0;
1155  }
1156  else if (cw < 0 && cl == 1 && src[0] && src[0] < MUTT_TREE_MAX)
1157  cw = 1;
1158  else if (cw < 0)
1159  cw = 0; /* unprintable wchar */
1160  if (cl + l > maxlen || cw + w > maxwid)
1161  break;
1162  l += cl;
1163  w += cw;
1164  }
1165 out:
1166  if (width)
1167  *width = w;
1168  return l;
1169 }
#define MUTT_TREE_MAX
Definition: mutt.h:96
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:663
wchar_t ReplacementChar
When a Unicode character can&#39;t be displayed, use this instead.
Definition: charset.c:57
#define MUTT_SPECIAL_INDEX
Definition: mutt.h:98

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

1177 {
1178  wchar_t wc;
1179  int w;
1180  size_t k, n;
1181  mbstate_t mbstate;
1182 
1183  if (!s)
1184  return 0;
1185 
1186  n = mutt_str_strlen(s);
1187 
1188  memset(&mbstate, 0, sizeof(mbstate));
1189  for (w = 0; n && (k = mbrtowc(&wc, s, n, &mbstate)); s += k, n -= k)
1190  {
1191  if (*s == MUTT_SPECIAL_INDEX)
1192  {
1193  s += 2; /* skip the index coloring sequence */
1194  k = 0;
1195  continue;
1196  }
1197 
1198  if (k == (size_t)(-1) || k == (size_t)(-2))
1199  {
1200  if (k == (size_t)(-1))
1201  memset(&mbstate, 0, sizeof(mbstate));
1202  k = (k == (size_t)(-1)) ? 1 : n;
1203  wc = ReplacementChar;
1204  }
1205  if (!IsWPrint(wc))
1206  wc = '?';
1207  w += wcwidth(wc);
1208  }
1209  return w;
1210 }
#define IsWPrint(wc)
Definition: mbyte.h:41
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:663
wchar_t ReplacementChar
When a Unicode character can&#39;t be displayed, use this instead.
Definition: charset.c:57
#define MUTT_SPECIAL_INDEX
Definition: mutt.h:98

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool message_is_visible ( struct Context ctx,
int  index 
)

Is a message in the index within limit.

Parameters
ctxOpen mailbox
indexMessage ID (index into ctx->hdrs[]
Return values
trueThe message is within limit

If no limit is in effect, all the messages are visible.

Definition at line 1220 of file curs_lib.c.

1221 {
1222  if (!ctx || !ctx->mailbox->hdrs || (index >= ctx->mailbox->msg_count))
1223  return false;
1224 
1225  return !ctx->pattern || ctx->mailbox->hdrs[index]->limited;
1226 }
int msg_count
total number of messages
Definition: mailbox.h:86
struct Email ** hdrs
Definition: mailbox.h:93
struct Mailbox * mailbox
Definition: context.h:50
bool limited
is this message in a limited view?
Definition: email.h:76
char * pattern
limit pattern string
Definition: context.h:39

+ Here is the caller graph for this function:

bool message_is_tagged ( struct Context ctx,
int  index 
)

Is a message in the index tagged (and within limit)

Parameters
ctxOpen mailbox
indexMessage ID (index into ctx->hdrs[]
Return values
trueThe message is both tagged and within limit

If a limit is in effect, the message must be visible within it.

Definition at line 1236 of file curs_lib.c.

1237 {
1238  return message_is_visible(ctx, index) && ctx->mailbox->hdrs[index]->tagged;
1239 }
struct Email ** hdrs
Definition: mailbox.h:93
bool tagged
Definition: email.h:42
struct Mailbox * mailbox
Definition: context.h:50
bool message_is_visible(struct Context *ctx, int index)
Is a message in the index within limit.
Definition: curs_lib.c:1220

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

bool 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.