From 208f889a4a4092d9fbfc943d8a23e0afc0a2a2f4 Mon Sep 17 00:00:00 2001 From: Yao Wei Date: Thu, 11 Sep 2014 21:24:51 +0800 Subject: [PATCH] add backspace functionality in shell --- sys/shell/shell.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 49e42818f3..6cc07e9630 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -236,6 +236,18 @@ static int readline(shell_t *shell, char *buf, size_t size) shell->put_char('\n'); 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 { *line_buf_ptr++ = c; shell->put_char(c);