From c5d994b0878ba509a0dff8d4b37dea7c69717fb2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jonathan=20Neusch=C3=A4fer?= Date: Sat, 17 Dec 2011 22:24:42 +0100 Subject: [PATCH] screen_utils: add function screen_get_yesno --- src/screen_utils.c | 16 ++++++++++++++++ src/screen_utils.h | 9 +++++++++ 2 files changed, 25 insertions(+) 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); -- 2.30.2