diff --git a/sys/shell/shell.c b/sys/shell/shell.c index 543069fdc5..f791525394 100644 --- a/sys/shell/shell.c +++ b/sys/shell/shell.c @@ -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) {