summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-10-01 19:13:09 -0600
committerTom Rini <trini@konsulko.com>2023-10-11 15:43:54 -0400
commitdcc18ce0dbaf93d82ef7f0c6fe625c42313eca32 (patch)
treef5607bb80ba4cfa024fe058321c69a0b25aa79ec /common
parent6321391ac3e310081768b6170554d4f49416b5c2 (diff)
downloadu-boot-dcc18ce0dbaf93d82ef7f0c6fe625c42313eca32.tar.gz
u-boot-dcc18ce0dbaf93d82ef7f0c6fe625c42313eca32.tar.bz2
u-boot-dcc18ce0dbaf93d82ef7f0c6fe625c42313eca32.zip
cli: Implement delete-word in cread_line()
The Ctrl-W option is implemented in the cread_line_simple() but not in the full version. This seems odd, so add an implementation. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/cli_readline.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/common/cli_readline.c b/common/cli_readline.c
index 458e927e49..687e239bfa 100644
--- a/common/cli_readline.c
+++ b/common/cli_readline.c
@@ -89,6 +89,14 @@ static char hist_lines[HIST_MAX][HIST_SIZE + 1]; /* Save room for NULL */
#define add_idx_minus_one() ((hist_add_idx == 0) ? hist_max : hist_add_idx-1)
+static void getcmd_putchars(int count, int ch)
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ getcmd_putch(ch);
+}
+
static void hist_init(void)
{
int i;
@@ -337,6 +345,29 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len,
case CTL_CH('o'):
insert = !insert;
break;
+ case CTL_CH('w'):
+ if (num) {
+ uint base;
+
+ for (base = num - 1;
+ base >= 0 && buf[base] == ' ';)
+ base--;
+ for (; base > 0 && buf[base - 1] != ' ';)
+ base--;
+
+ /* now delete chars from base to num */
+ wlen = num - base;
+ eol_num -= wlen;
+ memmove(&buf[base], &buf[num],
+ eol_num - base + 1);
+ num = base;
+ getcmd_putchars(wlen, CTL_BACKSPACE);
+ puts(buf + base);
+ getcmd_putchars(wlen, ' ');
+ getcmd_putchars(wlen + eol_num - num,
+ CTL_BACKSPACE);
+ }
+ break;
case CTL_CH('x'):
case CTL_CH('u'):
BEGINNING_OF_LINE();