From 32db19a03c5a74c0bae40a0e83a730ec05c147be Mon Sep 17 00:00:00 2001 From: KAAAsS Date: Wed, 20 Apr 2022 23:22:24 +0800 Subject: [PATCH] =?UTF-8?q?shell=20=E6=94=AF=E6=8C=81=E9=80=80=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lab5/user/lab5/apps/init.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lab5/user/lab5/apps/init.c b/lab5/user/lab5/apps/init.c index 947afd2..bcda0f5 100644 --- a/lab5/user/lab5/apps/init.c +++ b/lab5/user/lab5/apps/init.c @@ -54,15 +54,25 @@ char *readline(const char *prompt) c = getch(); if (c < 0) return NULL; - buf[complement_time++] = c; - printf("%c", c); if (c == '\r') { + // 回车 usys_putc('\n'); break; + } else if (c == '\b' || c == 127) { + // 退格 + if (i > 0) { + i--; + usys_putc('\b'); + usys_putc(' '); + usys_putc('\b'); + } + continue; + } else { + usys_putc(c); } + buf[i++] = c; } - - buf[complement_time - 1] = '\0'; + buf[i] = '\0'; return buf; }