@@ -58,6 +58,14 @@ STATIC char *str_dup_maybe(const char *str) {
58
58
return s2 ;
59
59
}
60
60
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
+
61
69
// By default assume terminal which implements VT100 commands...
62
70
#ifndef MICROPY_HAL_HAS_VT100
63
71
#define MICROPY_HAL_HAS_VT100 (1)
@@ -99,14 +107,6 @@ typedef struct _readline_t {
99
107
100
108
STATIC readline_t rl ;
101
109
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
-
110
110
int readline_process_char (int c ) {
111
111
size_t last_line_len = rl .line -> len ;
112
112
int cont_chars = 0 ;
@@ -275,7 +275,7 @@ int readline_process_char(int c) {
275
275
// up arrow
276
276
if (rl .hist_cur + 1 < (int )READLINE_HIST_SIZE && MP_STATE_PORT (readline_hist )[rl .hist_cur + 1 ] != NULL ) {
277
277
// 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 );
279
279
// increase hist num
280
280
rl .hist_cur += 1 ;
281
281
// set line to history
@@ -293,7 +293,7 @@ int readline_process_char(int c) {
293
293
// down arrow
294
294
if (rl .hist_cur >= 0 ) {
295
295
// 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 );
297
297
// decrease hist num
298
298
rl .hist_cur -= 1 ;
299
299
// set line to history
@@ -391,7 +391,7 @@ int readline_process_char(int c) {
391
391
mp_hal_erase_line_from_cursor (last_line_len - rl .cursor_pos );
392
392
}
393
393
// 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 );
395
395
// draw new chars
396
396
mp_hal_stdout_tx_strn (rl .line -> buf + rl .cursor_pos , rl .line -> len - rl .cursor_pos );
397
397
// move cursor forward if needed (already moved forward by length of line, so move it back)
0 commit comments