summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cdd7b26)
raw | patch | inline | side by side (parent: cdd7b26)
author | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | |
Sat, 17 Dec 2011 21:24:42 +0000 (22:24 +0100) | ||
committer | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | |
Thu, 22 Dec 2011 12:01:17 +0000 (13:01 +0100) |
src/screen_utils.c | patch | blob | history | |
src/screen_utils.h | patch | blob | history |
diff --git a/src/screen_utils.c b/src/screen_utils.c
index 1203a938c8c4ca657c1f31b2a78bb7b316e470ce..8889ac13277b8b8cb0b2edf53609847bc469ae80 100644 (file)
--- a/src/screen_utils.c
+++ b/src/screen_utils.c
#include "wreadln.h"
#include <mpd/client.h>
+#include <ctype.h>
void
screen_bell(void)
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 1691e2b7edf83df8411b5fcf41df7198cf91f077..c418142a2d526e7dae96fd320e61ddb7eefadc38 100644 (file)
--- a/src/screen_utils.h
+++ b/src/screen_utils.h
/* 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);