From: Jonathan Neuschäfer Date: Sat, 17 Dec 2011 21:24:42 +0000 (+0100) Subject: screen_utils: add function screen_get_yesno X-Git-Tag: release-0.20~31 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c5d994b0878ba509a0dff8d4b37dea7c69717fb2;p=ncmpc.git screen_utils: add function screen_get_yesno --- diff --git a/src/screen_utils.c b/src/screen_utils.c index 1203a93..8889ac1 100644 --- a/src/screen_utils.c +++ b/src/screen_utils.c @@ -27,6 +27,7 @@ #include "wreadln.h" #include +#include void screen_bell(void) @@ -66,6 +67,21 @@ screen_getch(const char *prompt) return key; } +bool +screen_get_yesno(const char *prompt, bool def) +{ + /* NOTE: if one day a translator decides to use a multi-byte character + for one of the yes/no keys, we'll have to parse it properly */ + + int key = tolower(screen_getch(prompt)); + if (key == YES[0]) + return true; + else if (key == NO[0]) + return false; + else + return def; +} + char * screen_readln(const char *prompt, const char *value, diff --git a/src/screen_utils.h b/src/screen_utils.h index 1691e2b..c418142 100644 --- a/src/screen_utils.h +++ b/src/screen_utils.h @@ -32,6 +32,15 @@ void screen_bell(void); /* read a character from the status window */ int screen_getch(const char *prompt); +/** + * display a prompt, wait for the user to press a key, and compare it with + * the default keys for "yes" and "no" (and their upper-case pendants). + * + * @returns true, if the user pressed the key for "yes"; false, if the user + * pressed the key for "no"; def otherwise + */ +bool screen_get_yesno(const char *prompt, bool def); + char * screen_read_password(const char *prompt);