diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2013-11-22 14:12:59 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2013-11-22 14:15:43 +0800 |
commit | e3319e99833a30a63e3a7ed3b6b22a127bcd0d50 (patch) | |
tree | 2cebd3ca87c0c5ef939e5dc47b56af87fe7ea7b1 | |
parent | 04b0f95866d735313d7aeb4bcb07552e1799ab6d (diff) | |
download | talos-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.c | 26 |
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) |