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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy