summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBaptiste Jonglez <baptiste--git@jonglez.org>2012-05-14 12:38:20 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2012-05-14 19:31:12 +0200
commitb2c92b2eb4ba8695923b72ff05493068b2be5934 (patch)
tree9e7618c080a8a74f27256b389af55e9a625a6ef8 /src
parentf5dd276edbeb65d787fcfd30a0d07bbc2660813c (diff)
downloadcalcurse-b2c92b2eb4ba8695923b72ff05493068b2be5934.zip
src/utils.c: Add a status_ask_simplechoice() function
We need a simpler version, based on the previously defined `status_ask_choice()` function, that asks to choose amongst a number of alternatives that can simply enumerated, without needing to bind keys on them. Signed-off-by: Baptiste Jonglez <baptiste--git@jonglez.org> Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src')
-rw-r--r--src/calcurse.h1
-rw-r--r--src/utils.c33
2 files changed, 34 insertions, 0 deletions
diff --git a/src/calcurse.h b/src/calcurse.h
index 4b54549..e26976a 100644
--- a/src/calcurse.h
+++ b/src/calcurse.h
@@ -897,6 +897,7 @@ void warnbox (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_simplechoice (const char *, const char *[], int);
void erase_window_part (WINDOW *, int, int, int, int);
WINDOW *popup (int, int, int, int, const char *, const char *, int);
void print_in_middle (WINDOW *, int, int, int, const char *);
diff --git a/src/utils.c b/src/utils.c
index 92c9d2b..37c1036 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -233,6 +233,39 @@ status_ask_choice(const char *message, const char choice[], int nb_choice)
}
}
+/*
+ * Prompts the user to make a choice between a number of alternatives.
+ *
+ * Returns the option chosen by the user (starting from 1), or -1 if
+ * the user doesn't want to answer.
+ */
+int
+status_ask_simplechoice (const char *prefix, const char *choice[],
+ int nb_choice)
+{
+ int i;
+ char tmp[BUFSIZ];
+ /* "(1) Choice1, (2) Choice2, (3) Choice3?" */
+ char choicestr[BUFSIZ];
+ /* Holds the characters to choose from ('1', '2', etc) */
+ char char_choice[nb_choice + 2];
+
+ /* No need to initialize first and last char. */
+ for (i = 1; i <= nb_choice; i++)
+ char_choice[i] = '0' + i;
+
+ strcpy (choicestr, prefix);
+
+ for (i = 0; i < nb_choice; i++)
+ {
+ sprintf (tmp, ((i + 1) == nb_choice) ? "(%d) %s?" : "(%d) %s, ",
+ (i + 1), _(choice[i]));
+ strcat (choicestr, tmp);
+ }
+
+ return (status_ask_choice (choicestr, char_choice, nb_choice));
+}
+
/* Erase part of a window. */
void
erase_window_part (WINDOW *win, int first_col, int first_row, int last_col,