NeoMutt  2018-07-16 +2481-68dcde
Teaching an old dog new tricks
DOXYGEN
curs_lib.h File Reference

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

#include <stddef.h>
#include <stdbool.h>
#include <stdio.h>
#include "config/lib.h"
#include "mutt.h"
#include "browser.h"
#include "pager.h"
+ Include dependency graph for curs_lib.h:

Go to the source code of this file.

Macros

#define mutt_buffer_enter_fname(prompt, fname, mailbox)   mutt_buffer_enter_fname_full(prompt, fname, mailbox, false, NULL, NULL, MUTT_SEL_NO_FLAGS)
 
#define mutt_enter_fname(prompt, buf, buflen, mailbox)   mutt_enter_fname_full(prompt, buf, buflen, mailbox, false, NULL, NULL, 0)
 
#define mutt_get_field(field, buf, buflen, complete)   mutt_get_field_full(field, buf, buflen, complete, false, NULL, NULL)
 
#define mutt_get_password(msg, buf, buflen)   mutt_get_field_unbuffered(msg, buf, buflen, MUTT_PASS)
 

Enumerations

enum  FormatJustify { JUSTIFY_LEFT = -1, JUSTIFY_CENTER = 0, JUSTIFY_RIGHT = 1 }
 Alignment for mutt_simple_format() More...
 

Functions

int mutt_addwch (wchar_t wc)
 addwch would be provided by an up-to-date curses library 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...
 
void mutt_edit_file (const char *editor, const char *file)
 Let the user edit a file. More...
 
void mutt_endwin (void)
 Shutdown curses/slang. 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_flushinp (void)
 Empty all the keyboard buffers. 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_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_format_s_x (char *buf, size_t buflen, const char *prec, const char *s, bool arboreal)
 Format a string like snprintf() More...
 
void mutt_getch_timeout (int delay)
 Set the getch() timeout. More...
 
struct KeyEvent mutt_getch (void)
 Read a character from the input buffer. More...
 
int mutt_get_field_full (const char *field, char *buf, size_t buflen, CompletionFlags complete, bool multiple, char ***files, int *numfiles)
 Ask the user for a string. More...
 
int mutt_get_field_unbuffered (const char *msg, char *buf, size_t buflen, CompletionFlags flags)
 Ask the user for a string (ignoring macro buffer) More...
 
int mutt_multi_choice (const char *prompt, const char *letters)
 Offer the user a multiple choice question. More...
 
void mutt_need_hard_redraw (void)
 Force a hard refresh. More...
 
void mutt_paddstr (int n, const char *s)
 Display a string on screen, padded if necessary. More...
 
void mutt_perror_debug (const char *s)
 Show the user an 'errno' message. More...
 
void mutt_push_macro_event (int ch, int op)
 Add the character/operation to the macro buffer. More...
 
void mutt_query_exit (void)
 Ask the user if they want to leave NeoMutt. More...
 
void mutt_refresh (void)
 Force a refresh of the screen. More...
 
void mutt_show_error (void)
 Show the user an error message. More...
 
void mutt_simple_format (char *buf, size_t buflen, int min_width, int max_width, enum FormatJustify justify, char pad_char, const char *s, size_t n, bool arboreal)
 Format a string, like snprintf() More...
 
int mutt_strwidth (const char *s)
 Measure a string's width in screen cells. 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...
 
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...
 
enum QuadOption mutt_yesorno (const char *msg, enum QuadOption def)
 Ask the user a Yes/No question. More...
 
int mutt_buffer_enter_fname_full (const char *prompt, struct Buffer *fname, bool mailbox, bool multiple, char ***files, int *numfiles, SelectFileFlags flags)
 Ask the user to select a file. More...
 

Variables

bool C_MetaKey
 interpret ALT-x as ESC-x More...
 
int MuttGetchTimeout
 Timeout in ms for mutt_getch() More...
 

Detailed Description

GUI miscellaneous curses (window drawing) routines.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file curs_lib.h.

Macro Definition Documentation

◆ mutt_buffer_enter_fname

#define mutt_buffer_enter_fname (   prompt,
  fname,
  mailbox 
)    mutt_buffer_enter_fname_full(prompt, fname, mailbox, false, NULL, NULL, MUTT_SEL_NO_FLAGS)

Definition at line 82 of file curs_lib.h.

◆ mutt_enter_fname

#define mutt_enter_fname (   prompt,
  buf,
  buflen,
  mailbox 
)    mutt_enter_fname_full(prompt, buf, buflen, mailbox, false, NULL, NULL, 0)

Definition at line 85 of file curs_lib.h.

◆ mutt_get_field

#define mutt_get_field (   field,
  buf,
  buflen,
  complete 
)    mutt_get_field_full(field, buf, buflen, complete, false, NULL, NULL)

Definition at line 86 of file curs_lib.h.

◆ mutt_get_password

#define mutt_get_password (   msg,
  buf,
  buflen 
)    mutt_get_field_unbuffered(msg, buf, buflen, MUTT_PASS)

Definition at line 87 of file curs_lib.h.

Enumeration Type Documentation

◆ FormatJustify

Alignment for mutt_simple_format()

Enumerator
JUSTIFY_LEFT 

Left justify the text.

JUSTIFY_CENTER 

Centre the text.

JUSTIFY_RIGHT 

Right justify the text.

Definition at line 44 of file curs_lib.h.

45 {
46  JUSTIFY_LEFT = -1,
47  JUSTIFY_CENTER = 0,
48  JUSTIFY_RIGHT = 1,
49 };
Left justify the text.
Definition: curs_lib.h:46
Right justify the text.
Definition: curs_lib.h:48
Centre the text.
Definition: curs_lib.h:47

Function Documentation

◆ mutt_addwch()

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

967 {
968  char buf[MB_LEN_MAX * 2];
969  mbstate_t mbstate;
970  size_t n1, n2;
971 
972  memset(&mbstate, 0, sizeof(mbstate));
973  if (((n1 = wcrtomb(buf, wc, &mbstate)) == (size_t)(-1)) ||
974  ((n2 = wcrtomb(buf + n1, 0, &mbstate)) == (size_t)(-1)))
975  {
976  return -1; /* ERR */
977  }
978  else
979  {
980  return addstr(buf);
981  }
982 }
+ Here is the caller graph for this function:

◆ mutt_any_key_to_continue()

int mutt_any_key_to_continue ( const char *  s)

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

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

Definition at line 532 of file curs_lib.c.

533 {
534  struct termios term;
535  struct termios old;
536 
537  int fd = open("/dev/tty", O_RDONLY);
538  if (fd < 0)
539  return EOF;
540 
541  tcgetattr(fd, &old); // Save the current tty settings
542 
543  term = old;
544  term.c_lflag &= ~(ICANON | ECHO); // Canonical (not line-buffered), don't echo the characters
545  term.c_cc[VMIN] = 1; // Wait for at least one character
546  term.c_cc[VTIME] = 255; // Wait for 25.5s
547  tcsetattr(fd, TCSANOW, &term);
548 
549  if (s)
550  fputs(s, stdout);
551  else
552  fputs(_("Press any key to continue..."), stdout);
553  fflush(stdout);
554 
555  char ch = '\0';
556  // Wait for a character. This might timeout, so loop.
557  while (read(fd, &ch, 1) == 0)
558  ;
559 
560  // Change the tty settings to be non-blocking
561  term.c_cc[VMIN] = 0; // Returning with zero characters is acceptable
562  term.c_cc[VTIME] = 0; // Don't wait
563  tcsetattr(fd, TCSANOW, &term);
564 
565  char buf[64];
566  while (read(fd, buf, sizeof(buf)) > 0) // Mop up any remaining chars
567  ;
568 
569  tcsetattr(fd, TCSANOW, &old); // Restore the previous tty settings
570  close(fd);
571 
572  fputs("\r\n", stdout);
574  return (ch >= 0) ? ch : EOF;
575 }
#define _(a)
Definition: message.h:28
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:109
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_do_pager()

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

588 {
589  int rc;
590 
591  if (!C_Pager || (mutt_str_strcmp(C_Pager, "builtin") == 0))
592  rc = mutt_pager(banner, tempfile, do_color, info);
593  else
594  {
595  struct Buffer *cmd = mutt_buffer_pool_get();
596 
597  mutt_endwin();
599  if (mutt_system(mutt_b2s(cmd)) == -1)
600  {
601  mutt_error(_("Error running \"%s\""), mutt_b2s(cmd));
602  rc = -1;
603  }
604  else
605  rc = 0;
606  mutt_file_unlink(tempfile);
608  }
609 
610  return rc;
611 }
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:100
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:111
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:192
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
#define mutt_b2s(buf)
Definition: buffer.h:41
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:499
#define mutt_error(...)
Definition: logging.h:84
void mutt_buffer_file_expand_fmt_quote(struct Buffer *dest, const char *fmt, const char *src)
Replace s in a string with a filename.
Definition: file.c:1417
WHERE char * C_Pager
Config: External command for viewing messages, or &#39;builtin&#39; to use NeoMutt&#39;s.
Definition: globals.h:137
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:2241
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
int mutt_system(const char *cmd)
Run an external command.
Definition: system.c:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_edit_file()

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

Let the user edit a file.

Parameters
editorUser's editor config
fileFile to edit

Definition at line 308 of file curs_lib.c.

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

◆ mutt_endwin()

void mutt_endwin ( void  )

Shutdown curses/slang.

Definition at line 499 of file curs_lib.c.

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

◆ mutt_enter_fname_full()

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

628 {
629  struct Buffer *fname = mutt_buffer_pool_get();
630 
631  mutt_buffer_addstr(fname, NONULL(buf));
632  int rc = mutt_buffer_enter_fname_full(prompt, fname, mailbox, multiple, files,
633  numfiles, flags);
634  mutt_str_strfcpy(buf, mutt_b2s(fname), buflen);
635 
636  mutt_buffer_pool_release(&fname);
637  return rc;
638 }
#define NONULL(x)
Definition: string2.h:37
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:100
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:111
String manipulation buffer.
Definition: buffer.h:33
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
int mutt_buffer_enter_fname_full(const char *prompt, struct Buffer *fname, bool mailbox, bool multiple, char ***files, int *numfiles, SelectFileFlags flags)
Ask the user to select a file.
Definition: curs_lib.c:652
#define mutt_b2s(buf)
Definition: buffer.h:41
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:750
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_flushinp()

void mutt_flushinp ( void  )

Empty all the keyboard buffers.

Definition at line 804 of file curs_lib.c.

805 {
806  UngetCount = 0;
807  MacroBufferCount = 0;
808  flushinp();
809 }
static size_t MacroBufferCount
Definition: curs_lib.c:78
static size_t UngetCount
Definition: curs_lib.c:85
+ Here is the caller graph for this function:

◆ mutt_flush_macro_to_endcond()

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

776 {
777  UngetCount = 0;
778  while (MacroBufferCount > 0)
779  {
780  if (MacroEvents[--MacroBufferCount].op == OP_END_COND)
781  return;
782  }
783 }
static struct KeyEvent * MacroEvents
Definition: curs_lib.c:80
static size_t MacroBufferCount
Definition: curs_lib.c:78
static size_t UngetCount
Definition: curs_lib.c:85
+ Here is the caller graph for this function:

◆ mutt_flush_unget_to_endcond()

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

793 {
794  while (UngetCount > 0)
795  {
796  if (UngetKeyEvents[--UngetCount].op == OP_END_COND)
797  return;
798  }
799 }
static size_t UngetCount
Definition: curs_lib.c:85
static struct KeyEvent * UngetKeyEvents
Definition: curs_lib.c:87
+ Here is the caller graph for this function:

◆ mutt_format_s()

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

1152 {
1153  mutt_format_s_x(buf, buflen, prec, s, false);
1154 }
void mutt_format_s_x(char *buf, size_t buflen, const char *prec, const char *s, bool arboreal)
Format a string like snprintf()
Definition: curs_lib.c:1114
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_format_s_tree()

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

1164 {
1165  mutt_format_s_x(buf, buflen, prec, s, true);
1166 }
void mutt_format_s_x(char *buf, size_t buflen, const char *prec, const char *s, bool arboreal)
Format a string like snprintf()
Definition: curs_lib.c:1114
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_format_s_x()

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

Format a string like snprintf()

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

This formats a string rather like:

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

Definition at line 1114 of file curs_lib.c.

1115 {
1116  enum FormatJustify justify = JUSTIFY_RIGHT;
1117  char *p = NULL;
1118  int min_width;
1119  int max_width = INT_MAX;
1120 
1121  if (*prec == '-')
1122  {
1123  prec++;
1124  justify = JUSTIFY_LEFT;
1125  }
1126  else if (*prec == '=')
1127  {
1128  prec++;
1129  justify = JUSTIFY_CENTER;
1130  }
1131  min_width = strtol(prec, &p, 10);
1132  if (*p == '.')
1133  {
1134  prec = p + 1;
1135  max_width = strtol(prec, &p, 10);
1136  if (p <= prec)
1137  max_width = INT_MAX;
1138  }
1139 
1140  mutt_simple_format(buf, buflen, min_width, max_width, justify, ' ', s,
1141  mutt_str_strlen(s), arboreal);
1142 }
Left justify the text.
Definition: curs_lib.h:46
FormatJustify
Alignment for mutt_simple_format()
Definition: curs_lib.h:44
Right justify the text.
Definition: curs_lib.h:48
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
Centre the text.
Definition: curs_lib.h:47
void mutt_simple_format(char *buf, size_t buflen, int min_width, int max_width, enum FormatJustify justify, char pad_char, const char *s, size_t n, bool arboreal)
Format a string, like snprintf()
Definition: curs_lib.c:1000
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_getch_timeout()

void mutt_getch_timeout ( int  delay)

Set the getch() timeout.

Parameters
delayTimeout delay in ms

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

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

Definition at line 132 of file curs_lib.c.

133 {
134  MuttGetchTimeout = delay;
135  timeout(delay);
136 }
int MuttGetchTimeout
Timeout in ms for mutt_getch()
Definition: curs_lib.c:89
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_getch()

struct KeyEvent mutt_getch ( void  )

Read a character from the input buffer.

Return values
objKeyEvent to process

The priority for reading events is:

  1. UngetKeyEvents buffer
  2. MacroEvents buffer
  3. Keyboard

This function can return:

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

Definition at line 175 of file curs_lib.c.

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

◆ mutt_get_field_full()

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

Ask the user for a string.

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

Definition at line 246 of file curs_lib.c.

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

◆ mutt_get_field_unbuffered()

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

Ask the user for a string (ignoring macro buffer)

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

Definition at line 287 of file curs_lib.c.

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

◆ mutt_multi_choice()

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

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

◆ mutt_need_hard_redraw()

void mutt_need_hard_redraw ( void  )

Force a hard refresh.

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

Definition at line 116 of file curs_lib.c.

117 {
118  keypad(stdscr, true);
119  clearok(stdscr, true);
121 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_paddstr()

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

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

◆ mutt_perror_debug()

void mutt_perror_debug ( const char *  s)

Show the user an 'errno' message.

Parameters
sAdditional text to show

Definition at line 518 of file curs_lib.c.

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

◆ mutt_push_macro_event()

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

757 {
758  struct KeyEvent tmp;
759 
760  tmp.ch = ch;
761  tmp.op = op;
762 
764  mutt_mem_realloc(&MacroEvents, (MacroBufferLen += 128) * sizeof(struct KeyEvent));
765 
766  MacroEvents[MacroBufferCount++] = tmp;
767 }
static struct KeyEvent * MacroEvents
Definition: curs_lib.c:80
static size_t MacroBufferCount
Definition: curs_lib.c:78
int op
function op
Definition: mutt_curses.h:111
int ch
raw key pressed
Definition: mutt_curses.h:110
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
An event such as a keypress.
Definition: mutt_curses.h:108
static size_t MacroBufferLen
Definition: curs_lib.c:79
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_query_exit()

void mutt_query_exit ( void  )

Ask the user if they want to leave NeoMutt.

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

Definition at line 467 of file curs_lib.c.

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

◆ mutt_refresh()

void mutt_refresh ( void  )

Force a refresh of the screen.

Definition at line 94 of file curs_lib.c.

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

◆ mutt_show_error()

void mutt_show_error ( void  )

Show the user an error message.

Definition at line 485 of file curs_lib.c.

486 {
488  return;
489 
492  NORMAL_COLOR;
494 }
#define NORMAL_COLOR
Definition: mutt_curses.h:239
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:107
Informational message.
Definition: mutt_curses.h:137
WHERE char ErrorBuf[256]
Copy of the last error message.
Definition: globals.h:45
WHERE bool ErrorBufMessage
true if the last message was an error
Definition: globals.h:44
#define SET_COLOR(X)
Definition: mutt_curses.h:224
int mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:202
Error message.
Definition: mutt_curses.h:132
WHERE bool OptMsgErr
(pseudo) used by mutt_error/mutt_message
Definition: options.h:39
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42
WHERE bool OptKeepQuiet
(pseudo) shut up the message and refresh functions while we are executing an external program...
Definition: options.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_simple_format()

void mutt_simple_format ( char *  buf,
size_t  buflen,
int  min_width,
int  max_width,
enum FormatJustify  justify,
char  pad_char,
const char *  s,
size_t  n,
bool  arboreal 
)

Format a string, like snprintf()

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

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

Definition at line 1000 of file curs_lib.c.

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

◆ mutt_strwidth()

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

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

◆ mutt_unget_event()

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

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

◆ mutt_unget_string()

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

739 {
740  const char *p = s + mutt_str_strlen(s) - 1;
741 
742  while (p >= s)
743  {
744  mutt_unget_event((unsigned char) *p--, 0);
745  }
746 }
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:719
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_wstr_trunc()

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

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

◆ mutt_yesorno()

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

Ask the user a Yes/No question.

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

Definition at line 332 of file curs_lib.c.

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

◆ mutt_buffer_enter_fname_full()

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

Ask the user to select a file.

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

Definition at line 652 of file curs_lib.c.

655 {
656  struct KeyEvent ch;
657 
660  addstr(_(" ('?' for list): "));
661  NORMAL_COLOR;
662  if (!mutt_buffer_is_empty(fname))
663  addstr(mutt_b2s(fname));
665  mutt_refresh();
666 
667  do
668  {
669  ch = mutt_getch();
670  } while (ch.ch == -2);
671  if (ch.ch < 0)
672  {
674  return -1;
675  }
676  else if (ch.ch == '?')
677  {
678  mutt_refresh();
679  mutt_buffer_reset(fname);
680 
681  if (flags == MUTT_SEL_NO_FLAGS)
682  flags = MUTT_SEL_FOLDER;
683  if (multiple)
684  flags |= MUTT_SEL_MULTI;
685  if (mailbox)
686  flags |= MUTT_SEL_MAILBOX;
687  mutt_buffer_select_file(fname, flags, files, numfiles);
688  }
689  else
690  {
691  char *pc = mutt_mem_malloc(mutt_str_strlen(prompt) + 3);
692 
693  sprintf(pc, "%s: ", prompt);
694  if (ch.op == OP_NULL)
695  mutt_unget_event(ch.ch, 0);
696  else
697  mutt_unget_event(0, ch.op);
698 
699  mutt_buffer_alloc(fname, 1024);
700  if (mutt_get_field_full(pc, fname->data, fname->dsize,
701  (mailbox ? MUTT_EFILE : MUTT_FILE) | MUTT_CLEAR,
702  multiple, files, numfiles) != 0)
703  mutt_buffer_reset(fname);
704  else
705  mutt_buffer_fix_dptr(fname);
706  FREE(&pc);
707  }
708 
709  return 0;
710 }
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
#define MUTT_CLEAR
Clear input if printable character is pressed.
Definition: mutt.h:70
void mutt_buffer_select_file(struct Buffer *file, SelectFileFlags flags, char ***files, int *numfiles)
Let the user select a file.
Definition: browser.c:1148
#define NORMAL_COLOR
Definition: mutt_curses.h:239
void mutt_window_clrtoeol(struct MuttWindow *win)
Clear to the end of the line.
Definition: mutt_window.c:107
void mutt_unget_event(int ch, int op)
Return a keystroke to the input buffer.
Definition: curs_lib.c:719
#define _(a)
Definition: message.h:28
Question/user input.
Definition: mutt_curses.h:143
int ch
raw key pressed
Definition: mutt_curses.h:110
#define MUTT_SEL_NO_FLAGS
No flags are set.
Definition: browser.h:44
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:666
#define MUTT_SEL_FOLDER
Select a local directory.
Definition: browser.h:47
size_t dsize
Length of data.
Definition: buffer.h:37
void mutt_window_clearline(struct MuttWindow *win, int row)
Clear a row of a Window.
Definition: mutt_window.c:95
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:181
#define mutt_b2s(buf)
Definition: buffer.h:41
void mutt_refresh(void)
Force a refresh of the screen.
Definition: curs_lib.c:94
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
char * data
Pointer to data.
Definition: buffer.h:35
An event such as a keypress.
Definition: mutt_curses.h:108
struct KeyEvent mutt_getch(void)
Read a character from the input buffer.
Definition: curs_lib.c:175
#define SET_COLOR(X)
Definition: mutt_curses.h:224
#define MUTT_SEL_MULTI
Multi-selection is enabled.
Definition: browser.h:46
int mutt_window_mvaddstr(struct MuttWindow *win, int row, int col, const char *str)
Move the cursor and write a fixed string to a Window.
Definition: mutt_window.c:202
#define MUTT_FILE
Do file completion.
Definition: mutt.h:66
#define MUTT_SEL_MAILBOX
Select a mailbox.
Definition: browser.h:45
#define MUTT_EFILE
Do file completion, plus incoming folders.
Definition: mutt.h:67
#define FREE(x)
Definition: memory.h:40
struct MuttWindow * MuttMessageWindow
Message Window.
Definition: mutt_window.c:42
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
void mutt_buffer_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:265
int mutt_get_field_full(const char *field, char *buf, size_t buflen, CompletionFlags complete, bool multiple, char ***files, int *numfiles)
Ask the user for a string.
Definition: curs_lib.c:246
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ C_MetaKey

bool C_MetaKey

interpret ALT-x as ESC-x

interpret ALT-x as ESC-x

Definition at line 68 of file curs_lib.c.

◆ MuttGetchTimeout

int MuttGetchTimeout

Timeout in ms for mutt_getch()

Definition at line 89 of file curs_lib.c.