This is an automated email from the ASF dual-hosted git repository. jerzy pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 47a6e50616f052c93f5af1ccc9b79f443b56bc0c Author: Jerzy Kasenberg <[email protected]> AuthorDate: Tue Oct 8 15:55:59 2019 +0200 sys/console: Add handling of CRTL-C Almost all non printable characters are treated somehow strange. If they are encounter on input they are appended to current input line then line is sent to the client as if enter was pressed. Users often hit CTRL-C just when they typed something wrong. To go along with this habit CTRL-C will now clear the input line. In the process three functions were moved up and modified so they write to console without filtering. --- sys/console/full/src/console.c | 82 ++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/sys/console/full/src/console.c b/sys/console/full/src/console.c index 4ba5fa1..c41be33 100644 --- a/sys/console/full/src/console.c +++ b/sys/console/full/src/console.c @@ -34,6 +34,10 @@ #define ESC 0x1b #define DEL 0x7f #define BS 0x08 +#define ETX 0x03 +#define EOT 0x04 +#define FF 0x0B +#define VT 0x0C /* ANSI escape sequences */ #define ANSI_ESC '[' @@ -164,6 +168,30 @@ console_filter_out(int c) return console_out_nolock(c); } +static inline void +cursor_save(void) +{ + console_out_nolock(ESC); + console_out_nolock('['); + console_out_nolock('s'); +} + +static inline void +cursor_restore(void) +{ + console_out_nolock(ESC); + console_out_nolock('['); + console_out_nolock('u'); +} + +static inline void +cursor_clear_line(void) +{ + console_out_nolock(ESC); + console_out_nolock('['); + console_out_nolock('K'); +} + void console_prompt_set(const char *prompt, const char *line) { @@ -318,32 +346,6 @@ cursor_backward(unsigned int count) console_printf("\x1b[%uD", count); } -#if MYNEWT_VAL(CONSOLE_HISTORY_SIZE) > 0 -static inline void -cursor_clear_line(void) -{ - console_out(ESC); - console_out('['); - console_out('K'); -} -#endif - -static inline void -cursor_save(void) -{ - console_out(ESC); - console_out('['); - console_out('s'); -} - -static inline void -cursor_restore(void) -{ - console_out(ESC); - console_out('['); - console_out('u'); -} - static void insert_char(char *pos, char c) { @@ -403,6 +405,18 @@ del_char(char *pos) } } +static void +console_clear_line(void) +{ + if (cur) { + cursor_backward(cur); + } + cur = 0; + trailing_chars = 0; + + cursor_clear_line(); +} + #if MYNEWT_VAL(CONSOLE_HISTORY_SIZE) > 0 static char console_hist_lines[ MYNEWT_VAL(CONSOLE_HISTORY_SIZE) ][ MYNEWT_VAL(CONSOLE_MAX_INPUT_LEN) ]; @@ -560,18 +574,6 @@ console_hist_add(char *line) } static void -console_clear_line(void) -{ - if (cur) { - cursor_backward(cur); - } - cur = 0; - trailing_chars = 0; - - cursor_clear_line(); -} - -static void console_hist_move(char *line, uint8_t direction) { struct console_hist *sh = &console_hist; @@ -894,6 +896,10 @@ console_handle_char(uint8_t byte) #endif } break; + /* CTRL-C */ + case ETX: + console_clear_line(); + break; } return 0;
