sys/shell: cancel current line on CTRL-C.
CTRL-C cancels the current line, similar to how getty works. This is useful if one is using a dumb terminal to communicate with a node, as it saves having to repeatedly type backspace to discard the current line. It also helps when connecting to an already running node, as one does not know what is on the line buffer, the safest thing to do is to begin by sending a ctrl-C. This is a suggestion of @benemorius.
This commit is contained in:
parent
cdfece682f
commit
fa9337d73c
@ -32,6 +32,7 @@
|
||||
#include "shell.h"
|
||||
#include "shell_commands.h"
|
||||
|
||||
#define ETX '\x03' /** ASCII "End-of-Text", or ctrl-C */
|
||||
#if !defined(SHELL_NO_ECHO) || !defined(SHELL_NO_PROMPT)
|
||||
#ifdef MODULE_NEWLIB
|
||||
/* use local copy of putchar, as it seems to be inlined,
|
||||
@ -243,7 +244,8 @@ static int readline(char *buf, size_t size)
|
||||
/* We allow Unix linebreaks (\n), DOS linebreaks (\r\n), and Mac linebreaks (\r). */
|
||||
/* QEMU transmits only a single '\r' == 13 on hitting enter ("-serial stdio"). */
|
||||
/* DOS newlines are handled like hitting enter twice, but empty lines are ignored. */
|
||||
if (c == '\r' || c == '\n') {
|
||||
/* Ctrl-C cancels the current line. */
|
||||
if (c == '\r' || c == '\n' || c == ETX) {
|
||||
*line_buf_ptr = '\0';
|
||||
#ifndef SHELL_NO_ECHO
|
||||
_putchar('\r');
|
||||
@ -251,7 +253,7 @@ static int readline(char *buf, size_t size)
|
||||
#endif
|
||||
|
||||
/* return 1 if line is empty, 0 otherwise */
|
||||
return line_buf_ptr == buf;
|
||||
return c == ETX || line_buf_ptr == buf;
|
||||
}
|
||||
/* QEMU uses 0x7f (DEL) as backspace, while 0x08 (BS) is for most terminals */
|
||||
else if (c == 0x08 || c == 0x7f) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user