Skip to content

Commit f961456

Browse files
committed
lib/mp-readline: Add n_chars argument to mp_hal_erase_line_from_cursor.
If VT100 support is not available then a given implementation of mp_hal_erase_line_from_cursor might need to know the number of characters to erase. This patch does not change generated code when VT100 is supported, since compiler can optimise away the argument.
1 parent 22521ea commit f961456

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

lib/mp-readline/readline.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ STATIC void mp_hal_move_cursor_back(uint pos) {
8282
}
8383
}
8484

85-
STATIC void mp_hal_erase_line_from_cursor(void) {
85+
STATIC void mp_hal_erase_line_from_cursor(uint n_chars_to_erase) {
86+
(void)n_chars_to_erase;
8687
mp_hal_stdout_tx_strn("\x1b[K", 3);
8788
}
8889
#endif
@@ -338,8 +339,7 @@ int readline_process_char(int c) {
338339
if (redraw_from_cursor) {
339340
if (rl.line->len < last_line_len) {
340341
// erase old chars
341-
// (number of chars to erase: last_line_len - rl.cursor_pos)
342-
mp_hal_erase_line_from_cursor();
342+
mp_hal_erase_line_from_cursor(last_line_len - rl.cursor_pos);
343343
}
344344
// draw new chars
345345
mp_hal_stdout_tx_strn(rl.line->buf + rl.cursor_pos, rl.line->len - rl.cursor_pos);

windows/windows_mphal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void mp_hal_move_cursor_back(uint pos) {
9292
SetConsoleCursorPosition(con_out, info.dwCursorPosition);
9393
}
9494

95-
void mp_hal_erase_line_from_cursor() {
95+
void mp_hal_erase_line_from_cursor(uint n_chars_to_erase) {
9696
assure_conout_handle();
9797
CONSOLE_SCREEN_BUFFER_INFO info;
9898
GetConsoleScreenBufferInfo(con_out, &info);

windows/windows_mphal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
#define MICROPY_HAL_HAS_VT100 (0)
3030

3131
void mp_hal_move_cursor_back(unsigned int pos);
32-
void mp_hal_erase_line_from_cursor();
32+
void mp_hal_erase_line_from_cursor(unsigned int n_chars_to_erase);

0 commit comments

Comments
 (0)