Skip to content

readline: make ctrl-l clear screen & redraw line #6639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions shared/readline/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions shared/readline/readline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down