shell 支持退格

This commit is contained in:
KAAAsS 2022-04-20 23:22:24 +08:00
parent a41bd3ef2e
commit 32db19a03c
Signed by: KAAAsS
GPG Key ID: D22F53AF662411FE

View File

@ -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;
}