From 95f5e78e0b331996d786dc1ba099dab8f71ff63b Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Fri, 7 Feb 2020 08:40:52 +0000 Subject: ash: process backspace in read builtin Previously the 'read' builtin had no special treatment for backspace characters entered in interactive mode: they were simply added to the string being read. Change this so that backspace deletes the previous character from the buffer and updates the display to match. It still doesn't handle tabs in the input or lines that are larger than the console width. --- shell/shell_common.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/shell/shell_common.c b/shell/shell_common.c index be69ff249..af05625a4 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -197,6 +197,7 @@ shell_builtin_read(struct builtin_read_params *params) if ((bufpos & 0xff) == 0) buffer = xrealloc(buffer, bufpos + 0x101); + IF_PLATFORM_MINGW32(loop:) timeout = -1; if (params->opt_t) { timeout = end_ms - (unsigned)monotonic_ms(); @@ -239,6 +240,15 @@ shell_builtin_read(struct builtin_read_params *params) retval = (const char *)(uintptr_t)1; goto ret; } + else if (key == '\b') { + if (bufpos > 0) { + --bufpos; + if (!(read_flags & BUILTIN_READ_SILENT)) { + printf("\b \b"); + } + } + goto loop; + } buffer[bufpos] = key == '\r' ? '\n' : key; if (!(read_flags & BUILTIN_READ_SILENT)) { /* echo input if not in silent mode */ -- cgit v1.2.3-55-g6feb