NeoMutt  2018-07-16 +1360-3df4a2
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...
 
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...
 

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';
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:230
static size_t MacroBufferCount
Definition: curs_lib.c:83
WHERE SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
Definition: globals.h:91
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:465
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
#define ctrl(ch)
Definition: mutt_curses.h:96
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:201
int ch
raw key pressed
Definition: mutt_curses.h:109
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:237
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
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:92
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 SETCOLOR(X)
Definition: mutt_curses.h:222
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:77

+ 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[STR_COMMAND];
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
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:497
#define STR_COMMAND
Enough space for a long command line.
Definition: string2.h:34
#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:1320
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:

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 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  safe_asprintf(&answer_string, " ([%s]/%s): ", def == MUTT_YES ? yes : no,
358  def == MUTT_YES ? no : yes);
359  answer_string_wid = mutt_strwidth(answer_string);
360  msg_wid = mutt_strwidth(msg);
361 
362  while (true)
363  {
364  if (redraw || SigWinch)
365  {
366  redraw = false;
367  if (SigWinch)
368  {
369  SigWinch = 0;
371  clearok(stdscr, TRUE);
373  }
374  if (MuttMessageWindow->cols)
375  {
376  prompt_lines = (msg_wid + answer_string_wid + MuttMessageWindow->cols - 1) /
378  prompt_lines = MAX(1, MIN(3, prompt_lines));
379  }
380  if (prompt_lines != MuttMessageWindow->rows)
381  {
382  mutt_window_reflow_message_rows(prompt_lines);
384  }
385 
386  /* maxlen here is sort of arbitrary, so pick a reasonable upper bound */
387  trunc_msg_len = mutt_wstr_trunc(
388  msg, 4 * prompt_lines * MuttMessageWindow->cols,
389  prompt_lines * MuttMessageWindow->cols - answer_string_wid, NULL);
390 
393  addnstr(msg, trunc_msg_len);
394  addstr(answer_string);
395  NORMAL_COLOR;
397  }
398 
399  mutt_refresh();
400  /* SigWinch is not processed unless timeout is set */
401  mutt_getch_timeout(30 * 1000);
402  ch = mutt_getch();
403  mutt_getch_timeout(-1);
404  if (ch.ch == -2)
405  continue;
406  if (CI_is_return(ch.ch))
407  break;
408  if (ch.ch < 0)
409  {
410  def = MUTT_ABORT;
411  break;
412  }
413 
414  answer[0] = ch.ch;
415  if (reyes_ok ? (regexec(&reyes, answer, 0, 0, 0) == 0) : (tolower(ch.ch) == 'y'))
416  {
417  def = MUTT_YES;
418  break;
419  }
420  else if (reno_ok ? (regexec(&reno, answer, 0, 0, 0) == 0) : (tolower(ch.ch) == 'n'))
421  {
422  def = MUTT_NO;
423  break;
424  }
425  else
426  {
427  BEEP();
428  }
429  }
430 
431  FREE(&answer_string);
432 
433  if (reyes_ok)
434  regfree(&reyes);
435  if (reno_ok)
436  regfree(&reno);
437 
438  if (MuttMessageWindow->rows != 1)
439  {
442  }
443  else
445 
446  if (def != MUTT_ABORT)
447  {
448  addstr((char *) (def == MUTT_YES ? yes : no));
449  mutt_refresh();
450  }
451  else
452  {
453  /* when the users cancels with ^G, clear the message stored with
454  * mutt_message() so it isn't displayed when the screen is refreshed. */
456  }
457  return def;
458 }
#define CI_is_return(ch)
Definition: mutt_curses.h:101
#define MIN(a, b)
Definition: memory.h:31
int safe_asprintf(char **, const char *,...)
Definition: safe_asprintf.c:76
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:237
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:92
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
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:222
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:109
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:41
#define REGCOMP(preg, regex, cflags)
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 465 of file curs_lib.c.

466 {
467  mutt_flushinp();
468  curs_set(1);
469  if (C_Timeout)
470  mutt_getch_timeout(-1); /* restore blocking operation */
471  if (mutt_yesorno(_("Exit NeoMutt?"), MUTT_YES) == MUTT_YES)
472  {
473  mutt_exit(1);
474  }
476  mutt_curs_set(-1);
477  SigInt = 0;
478 }
#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:91
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:753
#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:330
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:158
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:201
#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

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

484 {
486  return;
487 
490  NORMAL_COLOR;
492 }
#define NORMAL_COLOR
Definition: mutt_curses.h:237
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:136
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
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:222
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 497 of file curs_lib.c.

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

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

531 {
532  struct termios t;
533  struct termios old;
534  int f, ch;
535 
536  f = open("/dev/tty", O_RDONLY);
537  if (f < 0)
538  return EOF;
539  tcgetattr(f, &t);
540  memcpy((void *) &old, (void *) &t, sizeof(struct termios)); /* save original state */
541  t.c_lflag &= ~(ICANON | ECHO);
542  t.c_cc[VMIN] = 1;
543  t.c_cc[VTIME] = 0;
544  tcsetattr(f, TCSADRAIN, &t);
545  fflush(stdout);
546  if (s)
547  fputs(s, stdout);
548  else
549  fputs(_("Press any key to continue..."), stdout);
550  fflush(stdout);
551  ch = fgetc(stdin);
552  fflush(stdin);
553  tcsetattr(f, TCSADRAIN, &old);
554  close(f);
555  fputs("\r\n", stdout);
557  return (ch >= 0) ? ch : EOF;
558 }
#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 569 of file curs_lib.c.

571 {
572  int rc;
573 
574  if (!C_Pager || (mutt_str_strcmp(C_Pager, "builtin") == 0))
575  rc = mutt_pager(banner, tempfile, do_color, info);
576  else
577  {
578  char cmd[256];
579 
580  mutt_endwin();
581  mutt_file_expand_fmt_quote(cmd, sizeof(cmd), C_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:191
#define _(a)
Definition: message.h:28
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:497
#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:1320
WHERE char * C_Pager
Config: External command for viewing messages, or &#39;builtin&#39; to use NeoMutt&#39;s.
Definition: globals.h:138
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:2231
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:611
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,
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 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:66
#define NORMAL_COLOR
Definition: mutt_curses.h:237
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: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:662
#define MUTT_SEL_FOLDER
Select a local directory.
Definition: browser.h:44
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_select_file(char *file, size_t filelen, SelectFileFlags flags, char ***files, int *numfiles)
Let the user select a file.
Definition: browser.c:1085
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:99
#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:62
#define SETCOLOR(X)
Definition: mutt_curses.h:222
#define MUTT_SEL_MAILBOX
Select a mailbox.
Definition: browser.h:42
#define MUTT_EFILE
Do file completion, plus incoming folders.
Definition: mutt.h:63
#define FREE(x)
Definition: memory.h:40
int ch
raw key pressed
Definition: mutt_curses.h:109
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 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:662

+ 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 CI_is_return(ch)
Definition: mutt_curses.h:101
#define MIN(a, b)
Definition: memory.h:31
#define NORMAL_COLOR
Definition: mutt_curses.h:237
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:662
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:92
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
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:222
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:39
wchar_t ReplacementChar
When a Unicode character can&#39;t be displayed, use this instead.
Definition: charset.c:59
#define FMT_RIGHT
Definition: curs_lib.h:44
Colour indicator.
Definition: mutt_menu.h:76
#define EILSEQ
Definition: charset.c:50
#define FMT_CENTER
Definition: curs_lib.h:43

+ 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:42
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:662
#define FMT_RIGHT
Definition: curs_lib.h:44
#define FMT_CENTER
Definition: curs_lib.h:43

+ 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:39
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:662
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 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] != '\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 }
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:662
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 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:39
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:662
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.