From 22a3e004cdf41cb3a48d9087f8bf87e56cc4cbe9 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Thu, 14 Jul 2022 17:10:40 +0200 Subject: user: basic terminal driver with line editing --- src/user/app/shell.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) (limited to 'src/user/app/shell.c') diff --git a/src/user/app/shell.c b/src/user/app/shell.c index 4f062d9..3a08af4 100644 --- a/src/user/app/shell.c +++ b/src/user/app/shell.c @@ -31,33 +31,14 @@ static char *strtrim(char *s) { } +// TODO fgets static int readline(char *buf, size_t max) { - char c; + char c = '\0'; size_t pos = 0; - while (file_read(stdin, &c, 1)) { - switch (c) { - case '\b': - case 0x7f: - /* for some reason backspace outputs 0x7f (DEL) */ - if (pos != 0) { - printf("\b \b"); - pos--; - } - break; - case '\n': - case '\r': - printf("\n"); - buf[pos++] = '\0'; - return pos; - default: - if (pos < max) { - printf("%c", c); - buf[pos] = c; - pos++; - } - } - } - return -1; // error + while (pos < (max-1) && c != '\n' && file_read(stdin, &c, 1)) + buf[pos++] = c; + buf[pos++] = '\0'; + return pos; } static void cmd_cat_ls(const char *args, bool ls) { -- cgit v1.2.3