Skip to content

Commit

Permalink
shared/readline: Implement CTRL-L (clear screen, redraw prompt).
Browse files Browse the repository at this point in the history
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: micropython#11354
Signed-off-by: J. Neuschäfer <j.ne@posteo.net>
  • Loading branch information
neuschaefer committed Apr 19, 2024
1 parent d11ca09 commit 5364a1c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions shared/readline/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions shared/readline/readline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5364a1c

Please sign in to comment.