Skip to content

Commit 8d3f59e

Browse files
committed
readline: make ctrl-l clear screen & redraw line
.. similar to how standard Python does it. Closes: #6635
1 parent 492b208 commit 8d3f59e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

shared/readline/readline.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ int readline_process_char(int c) {
177177
vstr_cut_tail_bytes(rl.line, rl.line->len - rl.cursor_pos);
178178
// set redraw parameters
179179
redraw_from_cursor = true;
180+
} else if (c == CHAR_CTRL_L) {
181+
// CTRL-L is clear screen / redraw
182+
mp_hal_stdout_tx_str("\x1b[H\x1b[J");
183+
mp_hal_stdout_tx_str(rl.prompt);
184+
mp_hal_stdout_tx_strn(rl.line->buf + rl.orig_line_len, rl.cursor_pos - rl.orig_line_len);
185+
// set redraw parameters
186+
redraw_from_cursor = true;
180187
} else if (c == CHAR_CTRL_N) {
181188
// CTRL-N is go to next line in history
182189
goto down_arrow_key;

shared/readline/readline.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#define CHAR_CTRL_E (5)
3636
#define CHAR_CTRL_F (6)
3737
#define CHAR_CTRL_K (11)
38+
#define CHAR_CTRL_L (12)
3839
#define CHAR_CTRL_N (14)
3940
#define CHAR_CTRL_P (16)
4041
#define CHAR_CTRL_U (21)

0 commit comments

Comments
 (0)