shared/readline: Implement CTRL-L (clear screen, redraw prompt).

This commit implements CTRL-L, a somewhat common key to clear the the
screen and move the prompt and command line to the top of the screen.
At least zsh, fish, ruby, and GNU readline support it.

Fixes: https://github.com/micropython/micropython/issues/11354
Signed-off-by: J. Neuschäfer <j.ne@posteo.net>
pull/14332/head
J. Neuschäfer 2024-04-19 17:37:28 +02:00
rodzic 49ce7a6075
commit d1b0814ea3
2 zmienionych plików z 6 dodań i 0 usunięć

Wyświetl plik

@ -188,6 +188,11 @@ int readline_process_char(int c) {
redraw_step_back = rl.cursor_pos - rl.orig_line_len;
redraw_from_cursor = true;
#endif
} else if (c == CHAR_CTRL_L) {
mp_hal_stdout_tx_str("\x1b[2J\x1b[H");
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);
redraw_from_cursor = true;
#if MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE
} else if (c == CHAR_CTRL_W) {
goto backward_kill_word;

Wyświetl plik

@ -33,6 +33,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)