summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-11-22 14:12:59 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-11-22 14:15:43 +0800
commite3319e99833a30a63e3a7ed3b6b22a127bcd0d50 (patch)
tree2cebd3ca87c0c5ef939e5dc47b56af87fe7ea7b1
parent04b0f95866d735313d7aeb4bcb07552e1799ab6d (diff)
downloadtalos-petitboot-e3319e99833a30a63e3a7ed3b6b22a127bcd0d50.tar.gz
talos-petitboot-e3319e99833a30a63e3a7ed3b6b22a127bcd0d50.zip
ui/ncurses/nc-widgets: Unify select key
We have a few instances where we check for a 'select' action (enter or space key event), and some are inconsistent. Unify these with a key_is_select() function. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r--ui/ncurses/nc-widgets.c26
1 files changed, 11 insertions, 15 deletions
diff --git a/ui/ncurses/nc-widgets.c b/ui/ncurses/nc-widgets.c
index 8632aff..a6773cd 100644
--- a/ui/ncurses/nc-widgets.c
+++ b/ui/ncurses/nc-widgets.c
@@ -132,6 +132,11 @@ struct nc_widget_button {
static void widgetset_add_field(struct nc_widgetset *set, FIELD *field);
static void widgetset_remove_field(struct nc_widgetset *set, FIELD *field);
+static bool key_is_select(int key)
+{
+ return key == ' ' || key == '\r' || key == '\n' || key == KEY_ENTER;
+}
+
static bool process_key_nop(struct nc_widget *widget __attribute__((unused)),
FORM *form __attribute((unused)),
int key __attribute__((unused)))
@@ -206,7 +211,7 @@ static bool checkbox_process_key(struct nc_widget *widget,
{
struct nc_widget_checkbox *checkbox = to_checkbox(widget);
- if (key != ' ')
+ if (!key_is_select(key))
return false;
checkbox->checked = !checkbox->checked;
@@ -361,13 +366,8 @@ static bool select_process_key(struct nc_widget *w, FORM *form, int key)
int i, new_idx;
FIELD *field;
- switch (key) {
- case ' ':
- case KEY_ENTER:
- break;
- default:
+ if (!key_is_select(key))
return false;
- }
field = current_field(form);
new_opt = NULL;
@@ -556,15 +556,11 @@ static bool button_process_key(struct nc_widget *widget,
if (!button->click)
return false;
- switch (key) {
- case ' ':
- case '\r':
- case '\n':
- button->click(button->arg);
- return true;
- }
+ if (!key_is_select(key))
+ return false;
- return false;
+ button->click(button->arg);
+ return true;
}
static int button_destructor(void *ptr)
OpenPOWER on IntegriCloud