summaryrefslogtreecommitdiffstats
path: root/ui/ncurses/nc-menu.c
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2013-05-17 10:02:41 +0800
committerJeremy Kerr <jk@ozlabs.org>2013-05-21 15:29:43 +0800
commita610837ff38f5cc80bcbad465a80ab920e67927d (patch)
tree3e157da8508053daef1d400e8dfa3ec7c48e9f56 /ui/ncurses/nc-menu.c
parent3461b6ad5cb90f1448360d0eb04dd661ae477610 (diff)
downloadtalos-petitboot-a610837ff38f5cc80bcbad465a80ab920e67927d.tar.gz
talos-petitboot-a610837ff38f5cc80bcbad465a80ab920e67927d.zip
ui/ncurses: move getch() out of process_key callbacks
All process_key callbacks will want to query the key that was pressed, so do the getch() once in cui_process_key, and pass the result to the callback. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'ui/ncurses/nc-menu.c')
-rw-r--r--ui/ncurses/nc-menu.c101
1 files changed, 46 insertions, 55 deletions
diff --git a/ui/ncurses/nc-menu.c b/ui/ncurses/nc-menu.c
index 87b58e2..0612d8a 100644
--- a/ui/ncurses/nc-menu.c
+++ b/ui/ncurses/nc-menu.c
@@ -191,67 +191,58 @@ static void pmenu_move_cursor(struct pmenu *menu, int req)
* pmenu_process_key - Process a user keystroke.
*/
-static void pmenu_process_key(struct nc_scr *scr)
+static void pmenu_process_key(struct nc_scr *scr, int key)
{
struct pmenu *menu = pmenu_from_scr(scr);
struct pmenu_item *item = pmenu_find_selected(menu);
nc_scr_status_free(&menu->scr);
- while (1) {
- int c = getch();
-
- if (c == ERR)
- return;
-
- DBGS("%d (%o)\n", c, c);
-
- if (menu->hot_key)
- c = menu->hot_key(menu, item, c);
-
- switch (c) {
- case 27: /* ESC */
- if (menu->on_exit)
- menu->on_exit(menu);
- nc_flush_keys();
- return;
-
- case KEY_PPAGE:
- pmenu_move_cursor(menu, REQ_SCR_UPAGE);
- break;
- case KEY_NPAGE:
- pmenu_move_cursor(menu, REQ_SCR_DPAGE);
- break;
- case KEY_HOME:
- pmenu_move_cursor(menu, REQ_FIRST_ITEM);
- break;
- case KEY_END:
- pmenu_move_cursor(menu, REQ_LAST_ITEM);
- break;
- case KEY_UP:
- pmenu_move_cursor(menu, REQ_UP_ITEM);
- break;
- case KEY_DOWN:
- pmenu_move_cursor(menu, REQ_DOWN_ITEM);
- break;
- case 'e':
- if (item->on_edit)
- item->on_edit(item);
- break;
- case 'o':
- DBGS("on_open: %p\n", menu->on_open);
- if (menu->on_open)
- menu->on_open(menu);
- break;
- case '\n':
- case '\r':
- if (item->on_execute)
- item->on_execute(item);
- break;
- default:
- menu_driver(menu->ncm, c);
- break;
- }
+ if (menu->hot_key)
+ key = menu->hot_key(menu, item, key);
+
+ switch (key) {
+ case 27: /* ESC */
+ if (menu->on_exit)
+ menu->on_exit(menu);
+ nc_flush_keys();
+ return;
+
+ case KEY_PPAGE:
+ pmenu_move_cursor(menu, REQ_SCR_UPAGE);
+ break;
+ case KEY_NPAGE:
+ pmenu_move_cursor(menu, REQ_SCR_DPAGE);
+ break;
+ case KEY_HOME:
+ pmenu_move_cursor(menu, REQ_FIRST_ITEM);
+ break;
+ case KEY_END:
+ pmenu_move_cursor(menu, REQ_LAST_ITEM);
+ break;
+ case KEY_UP:
+ pmenu_move_cursor(menu, REQ_UP_ITEM);
+ break;
+ case KEY_DOWN:
+ pmenu_move_cursor(menu, REQ_DOWN_ITEM);
+ break;
+ case 'e':
+ if (item->on_edit)
+ item->on_edit(item);
+ break;
+ case 'o':
+ DBGS("on_open: %p\n", menu->on_open);
+ if (menu->on_open)
+ menu->on_open(menu);
+ break;
+ case '\n':
+ case '\r':
+ if (item->on_execute)
+ item->on_execute(item);
+ break;
+ default:
+ menu_driver(menu->ncm, key);
+ break;
}
}
OpenPOWER on IntegriCloud