@@ -222,32 +222,26 @@ int readline_process_char(int c) {
222
222
redraw_step_forward = compl_len ;
223
223
}
224
224
#endif
225
- } else if (32 <= c && c <= 126 ) {
225
+ } else if (32 <= c ) {
226
226
// printable character
227
- vstr_ins_char (rl .line , rl .cursor_pos , c );
228
- // set redraw parameters
229
- redraw_from_cursor = true;
230
- redraw_step_forward = 1 ;
231
- }else if (c >= 128 ) {
232
- // utf-8 character
233
- if (c >= 0xc0 && c < 0xf8 ) {
234
- // Lead code point
235
- vstr_ins_char (rl .line , rl .cursor_pos , c );
227
+ char lcp = rl .line -> buf [rl .cursor_pos ];
228
+ uint8_t cont_need = 0 ;
229
+ if (!UTF8_IS_CONT (c )) {
230
+ // ASCII or Lead code point
236
231
rl .utf8_cont_chars = 0 ;
237
- }else if (UTF8_IS_CONT (c )) {
238
- char lcp = rl .line -> buf [rl .cursor_pos ];
239
- // Check for valid lead code point
240
- if (lcp >= 0xc0 && lcp < 0xf8 ) {
241
- rl .utf8_cont_chars += 1 ;
242
- vstr_ins_char (rl .line , rl .cursor_pos + rl .utf8_cont_chars , c );
243
- // set redraw parameters if we have the entire character
244
- uint8_t need = (0xe5 >> ((lcp >> 3 ) & 0x6 )) & 3 ; // From unicode.c L195
245
- if (rl .utf8_cont_chars == need ) {
246
- redraw_from_cursor = true;
247
- redraw_step_forward = rl .utf8_cont_chars + 1 ;
248
- cont_chars = rl .utf8_cont_chars ;
249
- }
250
- }
232
+ lcp = c ;
233
+ }else {
234
+ rl .utf8_cont_chars += 1 ;
235
+ }
236
+ if (lcp >= 0xc0 && lcp < 0xf8 ) {
237
+ cont_need = (0xe5 >> ((lcp >> 3 ) & 0x6 )) & 3 ; // From unicode.c L195
238
+ }
239
+ vstr_ins_char (rl .line , rl .cursor_pos + rl .utf8_cont_chars , c );
240
+ // set redraw parameters if we have the entire character
241
+ if (rl .utf8_cont_chars == cont_need ) {
242
+ redraw_from_cursor = true;
243
+ redraw_step_forward = rl .utf8_cont_chars + 1 ;
244
+ cont_chars = rl .utf8_cont_chars ;
251
245
}
252
246
}
253
247
} else if (rl .escape_seq == ESEQ_ESC ) {
@@ -274,7 +268,7 @@ int readline_process_char(int c) {
274
268
#endif
275
269
// up arrow
276
270
if (rl .hist_cur + 1 < (int )READLINE_HIST_SIZE && MP_STATE_PORT (readline_hist )[rl .hist_cur + 1 ] != NULL ) {
277
- // Check for continuation characters through the cursor_pos
271
+ // Check for continuation characters
278
272
cont_chars = count_cont_bytes (rl .line -> buf + rl .orig_line_len , rl .line -> buf + rl .cursor_pos );
279
273
// increase hist num
280
274
rl .hist_cur += 1 ;
@@ -292,7 +286,7 @@ int readline_process_char(int c) {
292
286
#endif
293
287
// down arrow
294
288
if (rl .hist_cur >= 0 ) {
295
- // Check for continuation characters through the cursor_pos
289
+ // Check for continuation characters
296
290
cont_chars = count_cont_bytes (rl .line -> buf + rl .orig_line_len , rl .line -> buf + rl .cursor_pos );
297
291
// decrease hist num
298
292
rl .hist_cur -= 1 ;
@@ -390,7 +384,7 @@ int readline_process_char(int c) {
390
384
// erase old chars
391
385
mp_hal_erase_line_from_cursor (last_line_len - rl .cursor_pos );
392
386
}
393
- // Check for continuation characters from the new cursor_pos to the EOL
387
+ // Check for continuation characters
394
388
cont_chars = count_cont_bytes (rl .line -> buf + rl .cursor_pos + redraw_step_forward , rl .line -> buf + rl .line -> len );
395
389
// draw new chars
396
390
mp_hal_stdout_tx_strn (rl .line -> buf + rl .cursor_pos , rl .line -> len - rl .cursor_pos );
0 commit comments