aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2020-02-07 08:40:52 +0000
committerRon Yorston <rmy@pobox.com>2020-02-07 09:32:18 +0000
commit95f5e78e0b331996d786dc1ba099dab8f71ff63b (patch)
tree16836408d4f6d9d3c67e409175b06fe54575cbd6
parent87bc3fa0843f308a1b9175b8ae57c03f67a9116e (diff)
downloadbusybox-w32-95f5e78e0b331996d786dc1ba099dab8f71ff63b.tar.gz
busybox-w32-95f5e78e0b331996d786dc1ba099dab8f71ff63b.tar.bz2
busybox-w32-95f5e78e0b331996d786dc1ba099dab8f71ff63b.zip
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.
-rw-r--r--shell/shell_common.c10
1 files changed, 10 insertions, 0 deletions
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)
197 if ((bufpos & 0xff) == 0) 197 if ((bufpos & 0xff) == 0)
198 buffer = xrealloc(buffer, bufpos + 0x101); 198 buffer = xrealloc(buffer, bufpos + 0x101);
199 199
200 IF_PLATFORM_MINGW32(loop:)
200 timeout = -1; 201 timeout = -1;
201 if (params->opt_t) { 202 if (params->opt_t) {
202 timeout = end_ms - (unsigned)monotonic_ms(); 203 timeout = end_ms - (unsigned)monotonic_ms();
@@ -239,6 +240,15 @@ shell_builtin_read(struct builtin_read_params *params)
239 retval = (const char *)(uintptr_t)1; 240 retval = (const char *)(uintptr_t)1;
240 goto ret; 241 goto ret;
241 } 242 }
243 else if (key == '\b') {
244 if (bufpos > 0) {
245 --bufpos;
246 if (!(read_flags & BUILTIN_READ_SILENT)) {
247 printf("\b \b");
248 }
249 }
250 goto loop;
251 }
242 buffer[bufpos] = key == '\r' ? '\n' : key; 252 buffer[bufpos] = key == '\r' ? '\n' : key;
243 if (!(read_flags & BUILTIN_READ_SILENT)) { 253 if (!(read_flags & BUILTIN_READ_SILENT)) {
244 /* echo input if not in silent mode */ 254 /* echo input if not in silent mode */