summaryrefslogtreecommitdiff
path: root/src/user/app/shell.c
diff options
context:
space:
mode:
authordzwdz2022-07-14 17:10:40 +0200
committerdzwdz2022-07-14 17:10:40 +0200
commit22a3e004cdf41cb3a48d9087f8bf87e56cc4cbe9 (patch)
tree833f5f561ad2499bacbb9ee8f9129eb906d7e486 /src/user/app/shell.c
parent81ac903ce39ae1c96d28da3d7af29f364296b4cf (diff)
user: basic terminal driver with line editing
Diffstat (limited to 'src/user/app/shell.c')
-rw-r--r--src/user/app/shell.c31
1 files changed, 6 insertions, 25 deletions
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) {