From 6cc1a9d90a48533532fbbb3f490550038a33eae6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 25 Jan 2019 14:23:27 +0100 Subject: [PATCH] sh: Support basic backspacing on the command line. It's weird that I didn't do this sooner. I don't know how many tims I've had to retype a misspelled command. :^) --- Userland/sh.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Userland/sh.cpp b/Userland/sh.cpp index 38976a2751..2eb973455a 100644 --- a/Userland/sh.cpp +++ b/Userland/sh.cpp @@ -413,10 +413,19 @@ int main(int, char**) } } for (ssize_t i = 0; i < nread; ++i) { - putchar(keybuf[i]); + char ch = keybuf[i]; + if (ch == 8) { + if (linedx == 0) + continue; + linebuf[--linedx] = '\0'; + putchar(ch); + fflush(stdout); + continue; + } + putchar(ch); fflush(stdout); - if (keybuf[i] != '\n') { - linebuf[linedx++] = keybuf[i]; + if (ch != '\n') { + linebuf[linedx++] = ch; linebuf[linedx] = '\0'; } else { runcmd(linebuf);