@@ -58,6 +58,14 @@ STATIC char *str_dup_maybe(const char *str) {
5858 return s2 ;
5959}
6060
61+ STATIC int count_cont_bytes (char * start , char * end ) {
62+ int count = 0 ;
63+ for (char * pos = start ; pos < end ; pos ++ ) {
64+ count += UTF8_IS_CONT (* pos );
65+ }
66+ return count ;
67+ }
68+
6169// By default assume terminal which implements VT100 commands...
6270#ifndef MICROPY_HAL_HAS_VT100
6371#define MICROPY_HAL_HAS_VT100 (1)
@@ -99,14 +107,6 @@ typedef struct _readline_t {
99107
100108STATIC readline_t rl ;
101109
102- int readline_count_cont_byte (char * start , char * end ) {
103- int count = 0 ;
104- for (char * pos = start ; pos < end ; pos ++ ) {
105- count += UTF8_IS_CONT (* pos );
106- }
107- return count ;
108- }
109-
110110int readline_process_char (int c ) {
111111 size_t last_line_len = rl .line -> len ;
112112 int cont_chars = 0 ;
@@ -275,7 +275,7 @@ int readline_process_char(int c) {
275275 // up arrow
276276 if (rl .hist_cur + 1 < (int )READLINE_HIST_SIZE && MP_STATE_PORT (readline_hist )[rl .hist_cur + 1 ] != NULL ) {
277277 // Check for continuation characters through the cursor_pos
278- cont_chars = readline_count_cont_byte (rl .line -> buf + rl .orig_line_len , rl .line -> buf + rl .cursor_pos );
278+ cont_chars = count_cont_bytes (rl .line -> buf + rl .orig_line_len , rl .line -> buf + rl .cursor_pos );
279279 // increase hist num
280280 rl .hist_cur += 1 ;
281281 // set line to history
@@ -293,7 +293,7 @@ int readline_process_char(int c) {
293293 // down arrow
294294 if (rl .hist_cur >= 0 ) {
295295 // Check for continuation characters through the cursor_pos
296- cont_chars = readline_count_cont_byte (rl .line -> buf + rl .orig_line_len , rl .line -> buf + rl .cursor_pos );
296+ cont_chars = count_cont_bytes (rl .line -> buf + rl .orig_line_len , rl .line -> buf + rl .cursor_pos );
297297 // decrease hist num
298298 rl .hist_cur -= 1 ;
299299 // set line to history
@@ -391,7 +391,7 @@ int readline_process_char(int c) {
391391 mp_hal_erase_line_from_cursor (last_line_len - rl .cursor_pos );
392392 }
393393 // Check for continuation characters from the new cursor_pos to the EOL
394- cont_chars = readline_count_cont_byte (rl .line -> buf + rl .cursor_pos + redraw_step_forward , rl .line -> buf + rl .line -> len );
394+ cont_chars = count_cont_bytes (rl .line -> buf + rl .cursor_pos + redraw_step_forward , rl .line -> buf + rl .line -> len );
395395 // draw new chars
396396 mp_hal_stdout_tx_strn (rl .line -> buf + rl .cursor_pos , rl .line -> len - rl .cursor_pos );
397397 // move cursor forward if needed (already moved forward by length of line, so move it back)
0 commit comments