summaryrefslogtreecommitdiffstats
path: root/ui/ncurses/nc-boot-editor.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-boot-editor.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-boot-editor.c')
-rw-r--r--ui/ncurses/nc-boot-editor.c127
1 files changed, 59 insertions, 68 deletions
diff --git a/ui/ncurses/nc-boot-editor.c b/ui/ncurses/nc-boot-editor.c
index 38d29f8..fb0bee8 100644
--- a/ui/ncurses/nc-boot-editor.c
+++ b/ui/ncurses/nc-boot-editor.c
@@ -196,81 +196,72 @@ static struct pb_boot_data *boot_editor_prepare_data(
* Called from the cui via the scr:process_key method.
*/
-static void boot_editor_process_key(struct nc_scr *scr)
+static void boot_editor_process_key(struct nc_scr *scr, int key)
{
struct boot_editor *boot_editor = boot_editor_from_scr(scr);
struct pb_boot_data *bd;
- while (1) {
- int c = getch();
-
- if (c == ERR)
- return;
-
- /* DBGS("%d (%o)\n", c, c); */
-
- switch (c) {
- default:
- boot_editor_move_cursor(boot_editor, c);
- break;
+ switch (key) {
+ default:
+ boot_editor_move_cursor(boot_editor, key);
+ break;
- /* hot keys */
- case 27: /* ESC */
- boot_editor->on_exit(boot_editor,
- boot_editor_cancel, NULL);
- nc_flush_keys();
- return;
- case '\n':
- case '\r':
- form_driver(boot_editor->ncf, REQ_VALIDATION);
- bd = boot_editor_prepare_data(boot_editor);
- boot_editor->on_exit(boot_editor,
- boot_editor_update, bd);
- nc_flush_keys();
- return;
-
- /* insert mode */
- case KEY_IC:
- boot_editor_insert_mode_tog(boot_editor);
- break;
+ /* hot keys */
+ case 27: /* ESC */
+ boot_editor->on_exit(boot_editor,
+ boot_editor_cancel, NULL);
+ nc_flush_keys();
+ return;
+ case '\n':
+ case '\r':
+ form_driver(boot_editor->ncf, REQ_VALIDATION);
+ bd = boot_editor_prepare_data(boot_editor);
+ boot_editor->on_exit(boot_editor,
+ boot_editor_update, bd);
+ nc_flush_keys();
+ return;
+
+ /* insert mode */
+ case KEY_IC:
+ boot_editor_insert_mode_tog(boot_editor);
+ break;
- /* form nav */
- case KEY_PPAGE:
- boot_editor_move_field(boot_editor, REQ_FIRST_FIELD);
- break;
- case KEY_NPAGE:
- boot_editor_move_field(boot_editor, REQ_LAST_FIELD);
- break;
- case KEY_DOWN:
- boot_editor_move_field(boot_editor, REQ_NEXT_FIELD);
- break;
- case KEY_UP:
- boot_editor_move_field(boot_editor, REQ_PREV_FIELD);
- break;
+ /* form nav */
+ case KEY_PPAGE:
+ boot_editor_move_field(boot_editor, REQ_FIRST_FIELD);
+ break;
+ case KEY_NPAGE:
+ boot_editor_move_field(boot_editor, REQ_LAST_FIELD);
+ break;
+ case KEY_DOWN:
+ boot_editor_move_field(boot_editor, REQ_NEXT_FIELD);
+ break;
+ case KEY_UP:
+ boot_editor_move_field(boot_editor, REQ_PREV_FIELD);
+ break;
- /* field nav */
- case KEY_HOME:
- boot_editor_move_cursor(boot_editor, REQ_BEG_FIELD);
- break;
- case KEY_END:
- boot_editor_move_cursor(boot_editor, REQ_END_FIELD);
- break;
- case KEY_LEFT:
- boot_editor_move_cursor(boot_editor, REQ_LEFT_CHAR);
- break;
- case KEY_RIGHT:
- boot_editor_move_cursor(boot_editor, REQ_RIGHT_CHAR);
- break;
- case KEY_BACKSPACE:
- if (boot_editor_move_cursor(boot_editor, REQ_LEFT_CHAR)
- == E_OK)
- boot_editor_move_cursor(boot_editor,
- REQ_DEL_CHAR);
- break;
- case KEY_DC:
- boot_editor_move_cursor(boot_editor, REQ_DEL_CHAR);
- break;
- }
+ /* field nav */
+ case KEY_HOME:
+ boot_editor_move_cursor(boot_editor, REQ_BEG_FIELD);
+ break;
+ case KEY_END:
+ boot_editor_move_cursor(boot_editor, REQ_END_FIELD);
+ break;
+ case KEY_LEFT:
+ boot_editor_move_cursor(boot_editor, REQ_LEFT_CHAR);
+ break;
+ case KEY_RIGHT:
+ boot_editor_move_cursor(boot_editor, REQ_RIGHT_CHAR);
+ break;
+ case KEY_BACKSPACE:
+ if (boot_editor_move_cursor(boot_editor, REQ_LEFT_CHAR)
+ == E_OK)
+ boot_editor_move_cursor(boot_editor,
+ REQ_DEL_CHAR);
+ break;
+ case KEY_DC:
+ boot_editor_move_cursor(boot_editor, REQ_DEL_CHAR);
+ break;
}
}
OpenPOWER on IntegriCloud