summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2021-07-06 13:12:50 -0700
committerKevin McCarthy <kevin@8t8.us>2021-07-07 15:37:06 -0700
commitd0b9bec88a5b0c11b2a13303ceb5e8c5e5b09e05 (patch)
tree5baad9a64b3f788866aa24ab0a59b70527680884
parentab6bbb5b15b747a72d202e150dd0621d2d9155cb (diff)
Add a help choice '?' to the yes or no prompt for quadoptions.
The prompt currently just prints "See $%s for more information." where %s is the variable name. This will at least give a pointer to what variable can be adjusted to change the prompt behavior. A handful of boolean variables also control prompt display. Add a help choice for those too using the function mutt_query_boolean().
-rw-r--r--crypt-gpgme.c2
-rw-r--r--curs_lib.c92
-rw-r--r--curs_main.c10
-rw-r--r--imap/imap.c6
-rw-r--r--imap/message.c3
-rw-r--r--init.c37
-rw-r--r--muttlib.c6
-rw-r--r--pgp.c2
-rw-r--r--protos.h2
9 files changed, 134 insertions, 26 deletions
diff --git a/crypt-gpgme.c b/crypt-gpgme.c
index 4a388392..74b027bd 100644
--- a/crypt-gpgme.c
+++ b/crypt-gpgme.c
@@ -4994,7 +4994,7 @@ static char *find_keys (ADDRESS *adrlist, unsigned int app, int oppenc_mode)
{
snprintf (buf, sizeof (buf), _("Use keyID = \"%s\" for %s?"),
crypt_hook_val, p->mailbox);
- r = mutt_yesorno (buf, MUTT_YES);
+ r = mutt_query_boolean (OPTCRYPTCONFIRMHOOK, buf, MUTT_YES);
}
if (r == MUTT_YES)
{
diff --git a/curs_lib.c b/curs_lib.c
index 7a5a3f54..b43438a3 100644
--- a/curs_lib.c
+++ b/curs_lib.c
@@ -315,15 +315,20 @@ void mutt_edit_file (const char *editor, const char *data)
mutt_buffer_pool_release (&cmd);
}
-int mutt_yesorno (const char *msg, int def)
+/* Prompts for a yes or no response.
+ * If var is non-null, it will print a help message referencing the variable
+ * when '?' is pressed.
+ */
+int mutt_yesorno_with_help (const char *msg, int def, const char *var)
{
event_t ch;
char *yes = _("yes");
char *no = _("no");
- char *answer_string;
+ BUFFER *answer_buffer = NULL, *help_buffer = NULL;
int answer_string_wid, msg_wid;
- size_t trunc_msg_len;
+ size_t trunc_msg_len, trunc_help_len;
int redraw = 1, prompt_lines = 1;
+ int show_help_prompt = 0, show_help = 0;
#ifdef HAVE_LANGINFO_YESEXPR
char *expr;
@@ -341,14 +346,23 @@ int mutt_yesorno (const char *msg, int def)
!REGCOMP (&reno, expr, REG_NOSUB);
#endif
+ if (var)
+ show_help_prompt = 1;
+
/*
* In order to prevent the default answer to the question to wrapped
* around the screen in the even the question is wider than the screen,
* ensure there is enough room for the answer and truncate the question
* to fit.
*/
- safe_asprintf (&answer_string, " ([%s]/%s): ", def == MUTT_YES ? yes : no, def == MUTT_YES ? no : yes);
- answer_string_wid = mutt_strwidth (answer_string);
+ answer_buffer = mutt_buffer_pool_get ();
+ mutt_buffer_printf (answer_buffer,
+ " ([%s]/%s%s): ",
+ def == MUTT_YES ? yes : no,
+ def == MUTT_YES ? no : yes,
+ show_help_prompt ? "/?" : "");
+ answer_string_wid = mutt_strwidth (mutt_b2s (answer_buffer));
+
msg_wid = mutt_strwidth (msg);
FOREVER
@@ -371,21 +385,36 @@ int mutt_yesorno (const char *msg, int def)
MuttMessageWindow->cols;
prompt_lines = MAX (1, MIN (3, prompt_lines));
}
- if (prompt_lines != MuttMessageWindow->rows)
- {
- reflow_message_window_rows (prompt_lines);
- mutt_current_menu_redraw ();
- }
+ else
+ prompt_lines = 1;
/* maxlen here is sort of arbitrary, so pick a reasonable upper bound */
trunc_msg_len = mutt_wstr_trunc (msg, 4 * prompt_lines * MuttMessageWindow->cols,
prompt_lines * MuttMessageWindow->cols - answer_string_wid,
NULL);
+ if (show_help)
+ prompt_lines += 1;
+
+ if (prompt_lines != MuttMessageWindow->rows)
+ {
+ reflow_message_window_rows (prompt_lines);
+ mutt_current_menu_redraw ();
+ }
+
mutt_window_move (MuttMessageWindow, 0, 0);
SETCOLOR (MT_COLOR_PROMPT);
+ if (show_help)
+ {
+ trunc_help_len = mutt_wstr_trunc (mutt_b2s (help_buffer),
+ help_buffer->dsize,
+ MuttMessageWindow->cols, NULL);
+ addnstr (mutt_b2s (help_buffer), trunc_help_len);
+ mutt_window_clrtoeol (MuttMessageWindow);
+ mutt_window_move (MuttMessageWindow, 1, 0);
+ }
addnstr (msg, trunc_msg_len);
- addstr (answer_string);
+ addstr (mutt_b2s (answer_buffer));
NORMAL_COLOR;
mutt_window_clrtoeol (MuttMessageWindow);
}
@@ -427,13 +456,41 @@ int mutt_yesorno (const char *msg, int def)
def = MUTT_NO;
break;
}
+ else if (show_help_prompt && ch.ch == '?')
+ {
+ show_help_prompt = 0;
+ show_help = 1;
+ redraw = 1;
+
+ mutt_buffer_printf (answer_buffer,
+ " ([%s]/%s): ",
+ def == MUTT_YES ? yes : no,
+ def == MUTT_YES ? no : yes);
+ answer_string_wid = mutt_strwidth (mutt_b2s (answer_buffer));
+
+ help_buffer = mutt_buffer_pool_get ();
+ /* L10N:
+ In the mutt_yesorno() prompt, some variables and all
+ quadoptions provide a '?' choice to provide the name of the
+ configuration variable this prompt is dependent on.
+
+ For example, the prompt "Quit Mutt?" is dependent on the
+ quadoption $quit.
+
+ Typing '?' at those prompts will print this message above
+ the prompt, where %s is the name of the configuration
+ variable.
+ */
+ mutt_buffer_printf (help_buffer, _("See $%s for more information."), var);
+ }
else
{
BEEP();
}
}
- FREE (&answer_string);
+ mutt_buffer_pool_release (&answer_buffer);
+ mutt_buffer_pool_release (&help_buffer);
#ifdef HAVE_LANGINFO_YESEXPR
if (reyes_ok)
@@ -464,6 +521,12 @@ int mutt_yesorno (const char *msg, int def)
return (def);
}
+int mutt_yesorno (const char *msg, int def)
+{
+ return mutt_yesorno_with_help (msg, def, NULL);
+}
+
+
/* this function is called when the user presses the abort key */
void mutt_query_exit (void)
{
@@ -475,8 +538,9 @@ void mutt_query_exit (void)
{
if (!(mutt_background_has_backgrounded () &&
option (OPTBACKGROUNDCONFIRMQUIT) &&
- mutt_yesorno (_("There are $background_edit sessions. Really quit Mutt?"),
- MUTT_NO) != MUTT_YES))
+ mutt_query_boolean (OPTBACKGROUNDCONFIRMQUIT,
+ _("There are $background_edit sessions. Really quit Mutt?"),
+ MUTT_NO) != MUTT_YES))
{
endwin ();
exit (1);
diff --git a/curs_main.c b/curs_main.c
index edc3eac5..de6bc25b 100644
--- a/curs_main.c
+++ b/curs_main.c
@@ -1071,8 +1071,9 @@ int mutt_index_menu (void)
Prompt when trying to quit Mutt while there are backgrounded
compose sessions in process.
*/
- mutt_yesorno (_("There are $background_edit sessions. Really quit Mutt?"),
- MUTT_NO) != MUTT_YES)
+ mutt_query_boolean (OPTBACKGROUNDCONFIRMQUIT,
+ _("There are $background_edit sessions. Really quit Mutt?"),
+ MUTT_NO) != MUTT_YES)
{
break;
}
@@ -1499,8 +1500,9 @@ int mutt_index_menu (void)
{
if (mutt_background_has_backgrounded () &&
option (OPTBACKGROUNDCONFIRMQUIT) &&
- mutt_yesorno (_("There are $background_edit sessions. Really quit Mutt?"),
- MUTT_NO) != MUTT_YES)
+ mutt_query_boolean (OPTBACKGROUNDCONFIRMQUIT,
+ _("There are $background_edit sessions. Really quit Mutt?"),
+ MUTT_NO) != MUTT_YES)
{
break;
}
diff --git a/imap/imap.c b/imap/imap.c
index 9147f1ee..a4ad6917 100644
--- a/imap/imap.c
+++ b/imap/imap.c
@@ -1049,7 +1049,8 @@ static int imap_open_mailbox_append (CONTEXT *ctx, int flags)
return -1;
snprintf (buf, sizeof (buf), _("Create %s?"), mailbox);
- if (option (OPTCONFIRMCREATE) && mutt_yesorno (buf, 1) < 1)
+ if (option (OPTCONFIRMCREATE) &&
+ mutt_query_boolean (OPTCONFIRMCREATE, buf, 1) < 1)
return -1;
if (imap_create_mailbox (idata, mailbox) < 0)
@@ -2557,7 +2558,8 @@ int imap_fast_trash (CONTEXT* ctx, char* dest)
break;
dprint (3, (debugfile, "imap_fast_trash: server suggests TRYCREATE\n"));
snprintf (prompt, sizeof (prompt), _("Create %s?"), mbox);
- if (option (OPTCONFIRMCREATE) && mutt_yesorno (prompt, 1) < 1)
+ if (option (OPTCONFIRMCREATE) &&
+ mutt_query_boolean (OPTCONFIRMCREATE, prompt, 1) < 1)
{
mutt_clear_error ();
goto out;
diff --git a/imap/message.c b/imap/message.c
index 4c859921..fa26531d 100644
--- a/imap/message.c
+++ b/imap/message.c
@@ -1547,7 +1547,8 @@ int imap_copy_messages (CONTEXT* ctx, HEADER* h, const char* dest, int delete)
break;
dprint (3, (debugfile, "imap_copy_messages: server suggests TRYCREATE\n"));
snprintf (prompt, sizeof (prompt), _("Create %s?"), mbox);
- if (option (OPTCONFIRMCREATE) && mutt_yesorno (prompt, 1) < 1)
+ if (option (OPTCONFIRMCREATE) &&
+ mutt_query_boolean (OPTCONFIRMCREATE, prompt, 1) < 1)
{
mutt_clear_error ();
goto out;
diff --git a/init.c b/init.c
index e75e51e9..01abe50d 100644
--- a/init.c
+++ b/init.c
@@ -104,6 +104,27 @@ int quadoption (int opt)
return (QuadOptions[n] >> b) & 0x3;
}
+static const char *option_type_name (int opt, int type)
+{
+ int i;
+
+ for (i = 0; MuttVars[i].option; i++)
+ if (MuttVars[i].type == type &&
+ MuttVars[i].data.l == opt)
+ return MuttVars[i].option;
+ return NULL;
+}
+
+static const char *quadoption_name (int opt)
+{
+ return option_type_name (opt, DT_QUAD);
+}
+
+static const char *boolean_name (int opt)
+{
+ return option_type_name (opt, DT_BOOL);
+}
+
int query_quadoption (int opt, const char *prompt)
{
int v = quadoption (opt);
@@ -115,7 +136,8 @@ int query_quadoption (int opt, const char *prompt)
return (v);
default:
- v = mutt_yesorno (prompt, (v == MUTT_ASKYES));
+ v = mutt_yesorno_with_help (prompt, (v == MUTT_ASKYES),
+ quadoption_name (opt));
mutt_window_clearline (MuttMessageWindow, 0);
return (v);
}
@@ -123,6 +145,19 @@ int query_quadoption (int opt, const char *prompt)
/* not reached */
}
+/* This is slightly different from query_quadoption(), which only
+ * prompts when the quadoption is of type "ask-*".
+ *
+ * This function always prompts, but provides a help string listing
+ * the boolean name as a reference. It should be used when displaying
+ * the mutt_yesorno() prompt depends on the setting of the boolean.
+ */
+int mutt_query_boolean (int opt, const char *prompt, int def)
+{
+ return mutt_yesorno_with_help (prompt, def,
+ boolean_name (opt));
+}
+
/* given the variable ``s'', return the index into the rc_vars array which
matches, or -1 if the variable is not found. */
static int mutt_option_index (char *s)
diff --git a/muttlib.c b/muttlib.c
index e9578270..faf1b2b8 100644
--- a/muttlib.c
+++ b/muttlib.c
@@ -1988,7 +1988,8 @@ int mutt_save_confirm (const char *s, struct stat *st)
{
tmp = mutt_buffer_pool_get ();
mutt_buffer_printf (tmp, _("Append message(s) to %s?"), s);
- if ((rc = mutt_yesorno (mutt_b2s (tmp), MUTT_YES)) == MUTT_NO)
+ if ((rc = mutt_query_boolean (OPTCONFIRMAPPEND,
+ mutt_b2s (tmp), MUTT_YES)) == MUTT_NO)
ret = 1;
else if (rc == -1)
ret = -1;
@@ -2015,7 +2016,8 @@ int mutt_save_confirm (const char *s, struct stat *st)
{
tmp = mutt_buffer_pool_get ();
mutt_buffer_printf (tmp, _("Create %s?"), s);
- if ((rc = mutt_yesorno (mutt_b2s (tmp), MUTT_YES)) == MUTT_NO)
+ if ((rc = mutt_query_boolean (OPTCONFIRMCREATE,
+ mutt_b2s (tmp), MUTT_YES)) == MUTT_NO)
ret = 1;
else if (rc == -1)
ret = -1;
diff --git a/pgp.c b/pgp.c
index 245617f0..8fc51c83 100644
--- a/pgp.c
+++ b/pgp.c
@@ -1406,7 +1406,7 @@ char *pgp_findKeys (ADDRESS *adrlist, int oppenc_mode)
if (! oppenc_mode && option(OPTCRYPTCONFIRMHOOK))
{
snprintf (buf, sizeof (buf), _("Use keyID = \"%s\" for %s?"), keyID, p->mailbox);
- r = mutt_yesorno (buf, MUTT_YES);
+ r = mutt_query_boolean (OPTCRYPTCONFIRMHOOK, buf, MUTT_YES);
}
if (r == MUTT_YES)
{
diff --git a/protos.h b/protos.h
index db0af193..b6d09d5f 100644
--- a/protos.h
+++ b/protos.h
@@ -79,6 +79,7 @@ FILE *mutt_open_read (const char *, pid_t *);
void set_quadoption (int, int);
int query_quadoption (int, const char *);
int quadoption (int);
+int mutt_query_boolean (int opt, const char *prompt, int def);
char* mutt_extract_message_id (const char *, const char **, int);
@@ -405,6 +406,7 @@ int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const c
int mutt_write_rfc822_header (FILE *, ENVELOPE *, BODY *, char *, mutt_write_header_mode, int, int);
void mutt_write_references (LIST *, FILE *, int);
int mutt_yesorno (const char *, int);
+int mutt_yesorno_with_help (const char *, int, const char *);
void mutt_set_header_color(CONTEXT *, HEADER *);
void mutt_sleep (short);
int mutt_save_confirm (const char *, struct stat *);