add backspace functionality in shell

This commit is contained in:
Yao Wei 2014-09-11 21:24:51 +08:00
parent 85a5e6748a
commit 208f889a4a

View File

@ -236,6 +236,18 @@ static int readline(shell_t *shell, char *buf, size_t size)
shell->put_char('\n'); shell->put_char('\n');
return 0; return 0;
} }
else if (c == '\b') {
if (line_buf_ptr == buf) {
/* The line is empty. */
continue;
}
*--line_buf_ptr = '\0';
/* white-tape the character */
shell->put_char('\b');
shell->put_char(' ');
shell->put_char('\b');
}
else { else {
*line_buf_ptr++ = c; *line_buf_ptr++ = c;
shell->put_char(c); shell->put_char(c);