diff options
author | Simon Glass <sjg@chromium.org> | 2023-01-06 08:52:26 -0600 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-01-16 14:14:11 -0500 |
commit | 32bab0eae51b55898d1e2804e6614d9143840581 (patch) | |
tree | 67686cc8705aaf301695e8b66f50f613422b60b9 /common/menu.c | |
parent | 86cc3c5215fc6e3c2cb77ee162c22ad91dbfaff5 (diff) | |
download | u-boot-32bab0eae51b55898d1e2804e6614d9143840581.zip u-boot-32bab0eae51b55898d1e2804e6614d9143840581.tar.gz u-boot-32bab0eae51b55898d1e2804e6614d9143840581.tar.bz2 |
menu: Make use of CLI character processing
Avoid duplicating some of the escape-sequence processing here and use the
CLI function instead.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/menu.c')
-rw-r--r-- | common/menu.c | 92 |
1 files changed, 26 insertions, 66 deletions
diff --git a/common/menu.c b/common/menu.c index 7db9894..45f36ae 100644 --- a/common/menu.c +++ b/common/menu.c @@ -15,6 +15,8 @@ #include "menu.h" +#define ansi 0 + /* * Internally, each item in a menu is represented by a struct menu_item. * @@ -425,15 +427,19 @@ int menu_destroy(struct menu *m) return 1; } -enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) +enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, + struct cli_ch_state *cch) { enum bootmenu_key key = BKEY_NONE; int i, c; while (menu->delay > 0) { - printf(ANSI_CURSOR_POSITION, menu->count + 5, 3); + if (ansi) + printf(ANSI_CURSOR_POSITION, menu->count + 5, 3); printf("Hit any key to stop autoboot: %d ", menu->delay); for (i = 0; i < 100; ++i) { + int ichar; + if (!tstc()) { schedule(); mdelay(10); @@ -443,12 +449,13 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) menu->delay = -1; c = getchar(); - switch (c) { - case '\e': - *esc = 1; + ichar = cli_ch_process(cch, c); + + switch (ichar) { + case '\0': key = BKEY_NONE; break; - case '\r': + case '\n': key = BKEY_SELECT; break; case 0x3: /* ^C */ @@ -458,7 +465,6 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) key = BKEY_NONE; break; } - break; } @@ -468,7 +474,8 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) --menu->delay; } - printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, menu->count + 5, 1); + if (ansi) + printf(ANSI_CURSOR_POSITION ANSI_CLEAR_LINE, menu->count + 5, 1); if (menu->delay == 0) key = BKEY_SELECT; @@ -476,79 +483,32 @@ enum bootmenu_key bootmenu_autoboot_loop(struct bootmenu_data *menu, int *esc) return key; } -enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, int *esc) +enum bootmenu_key bootmenu_loop(struct bootmenu_data *menu, + struct cli_ch_state *cch) { enum bootmenu_key key = BKEY_NONE; int c; - if (*esc == 1) { - if (tstc()) { - c = getchar(); - } else { + c = cli_ch_process(cch, 0); + if (!c) { + while (!c && !tstc()) { schedule(); mdelay(10); - if (tstc()) - c = getchar(); - else - c = '\e'; + c = cli_ch_process(cch, -ETIMEDOUT); } - } else { - while (!tstc()) { - schedule(); - mdelay(10); - } - c = getchar(); - } - - switch (*esc) { - case 0: - /* First char of ANSI escape sequence '\e' */ - if (c == '\e') { - *esc = 1; - key = BKEY_NONE; - } - break; - case 1: - /* Second char of ANSI '[' */ - if (c == '[') { - *esc = 2; - key = BKEY_NONE; - } else { - /* Alone ESC key was pressed */ - key = BKEY_QUIT; - *esc = (c == '\e') ? 1 : 0; - } - break; - case 2: - case 3: - /* Third char of ANSI (number '1') - optional */ - if (*esc == 2 && c == '1') { - *esc = 3; - key = BKEY_NONE; - break; + if (!c) { + c = getchar(); + c = cli_ch_process(cch, c); } - - *esc = 0; - - /* ANSI 'A' - key up was pressed */ - if (c == 'A') - key = BKEY_UP; - /* ANSI 'B' - key down was pressed */ - else if (c == 'B') - key = BKEY_DOWN; - /* other key was pressed */ - else - key = BKEY_NONE; - - break; } switch (c) { - case '\r': + case '\n': /* enter key was pressed */ key = BKEY_SELECT; break; case CTL_CH('c'): + case '\e': /* ^C was pressed */ key = BKEY_QUIT; break; |