From 32bab0eae51b55898d1e2804e6614d9143840581 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Fri, 6 Jan 2023 08:52:26 -0600 Subject: 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 --- common/cli_getch.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'common/cli_getch.c') diff --git a/common/cli_getch.c b/common/cli_getch.c index 9eeea7fef2..87c23edcf4 100644 --- a/common/cli_getch.c +++ b/common/cli_getch.c @@ -140,10 +140,11 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar) * sequence */ if (!ichar) { - if (cch->emit_upto) { + if (cch->emitting) { if (cch->emit_upto < cch->esc_len) return cch->esc_save[cch->emit_upto++]; cch->emit_upto = 0; + cch->emitting = false; } return 0; } else if (ichar == -ETIMEDOUT) { @@ -174,18 +175,21 @@ int cli_ch_process(struct cli_ch_state *cch, int ichar) case ESC_SAVE: /* save this character and return nothing */ cch->esc_save[cch->esc_len++] = ichar; - return 0; + ichar = 0; + break; case ESC_REJECT: /* * invalid escape sequence, start returning the * characters in it */ cch->esc_save[cch->esc_len++] = ichar; - return cch->esc_save[cch->emit_upto++]; + ichar = cch->esc_save[cch->emit_upto++]; + cch->emitting = true; + break; case ESC_CONVERTED: /* valid escape sequence, return the resulting char */ cch->esc_len = 0; - return ichar; + break; } } -- cgit v1.2.3