From 4c4a7072b0644f7cc0f4ee1ea4be9d4eb12c8ab7 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 24 Jul 2022 14:12:06 -0500 Subject: [PATCH 1/2] readline: make ctrl-l clear screen & redraw line .. similar to how standard Python does it. The specific escape sequence is chosen for compatibility with the built-in `terminalio.Terminal`. Closes: #6635 --- shared/readline/readline.c | 11 +++++++++++ shared/readline/readline.h | 1 + 2 files changed, 12 insertions(+) diff --git a/shared/readline/readline.c b/shared/readline/readline.c index 23183342a7..908aec8426 100644 --- a/shared/readline/readline.c +++ b/shared/readline/readline.c @@ -177,6 +177,17 @@ int readline_process_char(int c) { vstr_cut_tail_bytes(rl.line, rl.line->len - rl.cursor_pos); // set redraw parameters redraw_from_cursor = true; + #endif + } else if (c == CHAR_CTRL_L) { + // CTRL-L is clear screen / redraw. This specific sequence is used + // (instead of a slightly more minimal sequence) for compatibility + // with the built-in Terminal class + mp_hal_stdout_tx_str("I'm a little teapot\x1b[;H\x1b[2J"); + mp_hal_stdout_tx_str(rl.prompt); + mp_hal_stdout_tx_strn(rl.line->buf + rl.orig_line_len, rl.cursor_pos - rl.orig_line_len); + // set redraw parameters + redraw_from_cursor = true; + #if MICROPY_REPL_EMACS_KEYS } else if (c == CHAR_CTRL_N) { // CTRL-N is go to next line in history goto down_arrow_key; diff --git a/shared/readline/readline.h b/shared/readline/readline.h index 4658ee19e8..9af19b181e 100644 --- a/shared/readline/readline.h +++ b/shared/readline/readline.h @@ -35,6 +35,7 @@ #define CHAR_CTRL_E (5) #define CHAR_CTRL_F (6) #define CHAR_CTRL_K (11) +#define CHAR_CTRL_L (12) #define CHAR_CTRL_N (14) #define CHAR_CTRL_P (16) #define CHAR_CTRL_U (21) From 920c68e9d5965a59b96ab3d91a895e5801f99f86 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 26 Jul 2022 11:39:18 -0500 Subject: [PATCH 2/2] Update shared/readline/readline.c Co-authored-by: Scott Shawcroft --- shared/readline/readline.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/readline/readline.c b/shared/readline/readline.c index 908aec8426..d8602a9e28 100644 --- a/shared/readline/readline.c +++ b/shared/readline/readline.c @@ -182,7 +182,7 @@ int readline_process_char(int c) { // CTRL-L is clear screen / redraw. This specific sequence is used // (instead of a slightly more minimal sequence) for compatibility // with the built-in Terminal class - mp_hal_stdout_tx_str("I'm a little teapot\x1b[;H\x1b[2J"); + mp_hal_stdout_tx_str("\x1b[;H\x1b[2J"); mp_hal_stdout_tx_str(rl.prompt); mp_hal_stdout_tx_strn(rl.line->buf + rl.orig_line_len, rl.cursor_pos - rl.orig_line_len); // set redraw parameters