8000 Merge pull request #6639 from jepler/repl-ctrl-l · tannewt/circuitpython@2e39610 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2e39610

Browse files
authored
Merge pull request micropython#6639 from jepler/repl-ctrl-l
readline: make ctrl-l clear screen & redraw line
2 parents 96e870d + 975e3e2 commit 2e39610

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

shared/readline/readline.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ 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+
#endif
181+
} else if (c == CHAR_CTRL_L) {
182+
// CTRL-L is clear screen / redraw. This specific sequence is used
183+
// (instead of a slightly more minimal sequence) for compatibility
184+
// with the built-in Terminal class
185+
mp_hal_stdout_tx_str("\x1b[;H\x1b[2J");
186+
mp_hal_stdout_tx_str(rl.prompt);
187+
mp_hal_stdout_tx_strn(rl.line->buf + rl.orig_line_len, rl.cursor_pos - rl.orig_line_len);
188+
// set redraw parameters
189+
redraw_from_cursor = true;
190+
#if MICROPY_REPL_EMACS_KEYS
180191
} else if (c == CHAR_CTRL_N) {
181192
// CTRL-N is go to next line in history
182193
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)
0