Factorize boolean user prompting.

Introduce a new `status_ask_bool()` function, and use it where
applicable.

This greatly reduces code duplication, and will allow handling special
events (resize, user escape) much more uniformely.

Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org>
Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Baptiste Jonglez 2012-05-13 14:09:21 +02:00 committed by Lukas Fleischer
parent 7d4ef08345
commit 13d6f8703b
6 changed files with 19 additions and 35 deletions

View File

@ -276,8 +276,7 @@ apoint_delete (unsigned *nb_events, unsigned *nb_apoints)
if (conf.confirm_delete) if (conf.confirm_delete)
{ {
status_mesg_yesno (del_app_str); if (status_ask_bool (del_app_str) != 1)
if (wgetch (win[STA].p) != 'y')
{ {
wins_erase_status_bar (); wins_erase_status_bar ();
return; return;

View File

@ -546,9 +546,7 @@ main (int argc, char **argv)
if (conf.confirm_quit) if (conf.confirm_quit)
{ {
status_mesg_yesno (_("Do you really want to quit ?")); if (status_ask_bool (_("Do you really want to quit ?")) == 1)
key = wgetch (win[STA].p);
if (key == 'y')
exit_calcurse (EXIT_SUCCESS); exit_calcurse (EXIT_SUCCESS);
else else
{ {

View File

@ -895,8 +895,8 @@ void free_user_data (void);
void fatalbox (const char *); void fatalbox (const char *);
void warnbox (const char *); void warnbox (const char *);
void status_mesg (const char *, const char *); void status_mesg (const char *, const char *);
void status_mesg_yesno (const char *);
int status_ask_choice (const char *, const char[], int); int status_ask_choice (const char *, const char[], int);
int status_ask_bool (const char *);
int status_ask_simplechoice (const char *, const char *[], int); int status_ask_simplechoice (const char *, const char *[], int);
void erase_window_part (WINDOW *, int, int, int, int); void erase_window_part (WINDOW *, int, int, int, int);
WINDOW *popup (int, int, int, int, const char *, const char *, int); WINDOW *popup (int, int, int, int, const char *, const char *, int);

View File

@ -1253,16 +1253,8 @@ io_log_display (struct io_file *log, const char *msg, const char *pager)
} }
else else
{ {
status_mesg_yesno (msg); if (status_ask_bool (msg) == 1)
do
{
ans = wgetch (win[STA].p);
if (ans == 'y')
{
wins_launch_external (log->name, pager); wins_launch_external (log->name, pager);
}
}
while (ans != 'y' && ans != 'n');
wins_erase_status_bar (); wins_erase_status_bar ();
} }
} }

View File

@ -250,17 +250,8 @@ todo_delete (void)
const int nb_erase_choice = 2; const int nb_erase_choice = 2;
int answer; int answer;
if (conf.confirm_delete) if ((todos <= 0) ||
{ (conf.confirm_delete && (status_ask_bool (del_todo_str) != 1)))
status_mesg_yesno (del_todo_str);
answer = wgetch (win[STA].p);
if ((answer != 'y') || (todos <= 0))
{
wins_erase_status_bar ();
return;
}
}
else if (todos <= 0)
{ {
wins_erase_status_bar (); wins_erase_status_bar ();
return; return;

View File

@ -184,13 +184,6 @@ status_mesg (const char *msg1, const char *msg2)
custom_remove_attr (win[STA].p, ATTR_HIGHEST); custom_remove_attr (win[STA].p, ATTR_HIGHEST);
} }
/* Print a status message, followed by a "[y/n]" prompt. */
void
status_mesg_yesno (const char *msg)
{
status_mesg (msg, "[y/n] ");
}
/* /*
* Prompts the user to make a choice between named alternatives. * Prompts the user to make a choice between named alternatives.
* *
@ -233,6 +226,17 @@ status_ask_choice(const char *message, const char choice[], int nb_choice)
} }
} }
/*
* Prompts the user with a boolean question.
*
* Returns 1 if yes, 2 if no, and -1 otherwise
*/
int
status_ask_bool (const char *msg)
{
return (status_ask_choice (msg, _("[yn]"), 2));
}
/* /*
* Prompts the user to make a choice between a number of alternatives. * Prompts the user to make a choice between a number of alternatives.
* *