Merge pull request #6639 from jepler/repl-ctrl-l

readline: make ctrl-l clear screen & redraw line
This commit is contained in:
Jeff Epler 2022-07-29 11:42:58 -05:00 committed by GitHub
commit 2e3961019d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -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("\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;

View File

@ -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)