Mercurial > vim
comparison src/libvterm/src/state.c @ 30876:2d2758ffd959 v9.0.0772
patch 9.0.0772: the libvterm code is outdated
Commit: https://github.com/vim/vim/commit/501e77766cd30d8f4bfeb04a67aff1865b5f5a41
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Oct 16 14:35:46 2022 +0100
patch 9.0.0772: the libvterm code is outdated
Problem: The libvterm code is outdated.
Solution: Include libvterm changes from revision 790 to 801.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 16 Oct 2022 15:45:04 +0200 |
parents | 58a7c651c313 |
children | 82336c3b679d |
comparison
equal
deleted
inserted
replaced
30875:3295247d97a5 | 30876:2d2758ffd959 |
---|---|
278 } | 278 } |
279 | 279 |
280 static int on_text(const char bytes[], size_t len, void *user) | 280 static int on_text(const char bytes[], size_t len, void *user) |
281 { | 281 { |
282 VTermState *state = user; | 282 VTermState *state = user; |
283 uint32_t *codepoints; | |
284 int npoints = 0; | 283 int npoints = 0; |
285 size_t eaten = 0; | 284 size_t eaten = 0; |
286 VTermEncodingInstance *encoding; | 285 VTermEncodingInstance *encoding; |
287 int i = 0; | 286 int i = 0; |
288 | 287 |
289 VTermPos oldpos = state->pos; | 288 VTermPos oldpos = state->pos; |
290 | 289 |
291 // We'll have at most len codepoints, plus one from a previous incomplete | 290 // We'll have at most len codepoints, plus one from a previous incomplete |
292 // sequence. | 291 // sequence. |
293 codepoints = vterm_allocator_malloc(state->vt, (len + 1) * sizeof(uint32_t)); | 292 uint32_t *codepoints = (uint32_t *)(state->vt->tmpbuffer); |
294 if (codepoints == NULL) | 293 size_t maxpoints = (state->vt->tmpbuffer_len) / sizeof(uint32_t); |
295 return 0; | |
296 | 294 |
297 encoding = | 295 encoding = |
298 state->gsingle_set ? &state->encoding[state->gsingle_set] : | 296 state->gsingle_set ? &state->encoding[state->gsingle_set] : |
299 !(bytes[eaten] & 0x80) ? &state->encoding[state->gl_set] : | 297 !(bytes[eaten] & 0x80) ? &state->encoding[state->gl_set] : |
300 state->vt->mode.utf8 ? &state->encoding_utf8 : | 298 state->vt->mode.utf8 ? &state->encoding_utf8 : |
301 &state->encoding[state->gr_set]; | 299 &state->encoding[state->gr_set]; |
302 | 300 |
303 (*encoding->enc->decode)(encoding->enc, encoding->data, | 301 (*encoding->enc->decode)(encoding->enc, encoding->data, |
304 codepoints, &npoints, state->gsingle_set ? 1 : (int)len, | 302 codepoints, &npoints, state->gsingle_set ? 1 : (int)maxpoints, |
305 bytes, &eaten, len); | 303 bytes, &eaten, len); |
306 | 304 |
307 /* There's a chance an encoding (e.g. UTF-8) hasn't found enough bytes yet | 305 /* There's a chance an encoding (e.g. UTF-8) hasn't found enough bytes yet |
308 * for even a single codepoint | 306 * for even a single codepoint |
309 */ | 307 */ |
310 if(!npoints) | 308 if(!npoints) |
311 { | 309 { |
312 vterm_allocator_free(state->vt, codepoints); | |
313 return (int)eaten; | 310 return (int)eaten; |
314 } | 311 } |
315 | 312 |
316 if(state->gsingle_set && npoints) | 313 if(state->gsingle_set && npoints) |
317 state->gsingle_set = 0; | 314 state->gsingle_set = 0; |
361 for(; i < npoints; i++) { | 358 for(; i < npoints; i++) { |
362 // Try to find combining characters following this | 359 // Try to find combining characters following this |
363 int glyph_starts = i; | 360 int glyph_starts = i; |
364 int glyph_ends; | 361 int glyph_ends; |
365 int width = 0; | 362 int width = 0; |
366 uint32_t *chars; | 363 |
367 | 364 for(glyph_ends = i + 1; |
368 for(glyph_ends = i + 1; glyph_ends < npoints; glyph_ends++) | 365 (glyph_ends < npoints) && (glyph_ends < glyph_starts + VTERM_MAX_CHARS_PER_CELL); |
366 glyph_ends++) | |
369 if(!vterm_unicode_is_combining(codepoints[glyph_ends])) | 367 if(!vterm_unicode_is_combining(codepoints[glyph_ends])) |
370 break; | 368 break; |
371 | 369 |
372 chars = vterm_allocator_malloc(state->vt, (glyph_ends - glyph_starts + 1) * sizeof(uint32_t)); | 370 uint32_t *chars = vterm_allocator_malloc(state->vt, (VTERM_MAX_CHARS_PER_CELL + 1) * sizeof(uint32_t)); |
373 if (chars == NULL) | 371 if (chars == NULL) |
374 break; | 372 break; |
375 | 373 |
376 for( ; i < glyph_ends; i++) { | 374 for( ; i < glyph_ends; i++) { |
377 int this_width; | 375 int this_width; |
459 state->pos.row, state->pos.col); | 457 state->pos.row, state->pos.col); |
460 abort(); | 458 abort(); |
461 } | 459 } |
462 #endif | 460 #endif |
463 | 461 |
464 vterm_allocator_free(state->vt, codepoints); | |
465 return (int)eaten; | 462 return (int)eaten; |
466 } | 463 } |
467 | 464 |
468 static int on_control(unsigned char control, void *user) | 465 static int on_control(unsigned char control, void *user) |
469 { | 466 { |
948 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "?%d;%d$y", num, 0); | 945 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "?%d;%d$y", num, 0); |
949 return; | 946 return; |
950 } | 947 } |
951 | 948 |
952 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "?%d;%d$y", num, reply ? 1 : 2); | 949 vterm_push_output_sprintf_ctrl(state->vt, C1_CSI, "?%d;%d$y", num, reply ? 1 : 2); |
950 } | |
951 | |
952 static void request_version_string(VTermState *state) | |
953 { | |
954 vterm_push_output_sprintf_str(state->vt, C1_DCS, TRUE, ">|libvterm(%d.%d)", | |
955 VTERM_VERSION_MAJOR, VTERM_VERSION_MINOR); | |
953 } | 956 } |
954 | 957 |
955 static int on_csi(const char *leader, const long args[], int argcount, const char *intermed, char command, void *user) | 958 static int on_csi(const char *leader, const long args[], int argcount, const char *intermed, char command, void *user) |
956 { | 959 { |
957 VTermState *state = user; | 960 VTermState *state = user; |
1419 vterm_state_reset(state, 0); | 1422 vterm_state_reset(state, 0); |
1420 break; | 1423 break; |
1421 | 1424 |
1422 case LEADER('?', INTERMED('$', 0x70)): | 1425 case LEADER('?', INTERMED('$', 0x70)): |
1423 request_dec_mode(state, CSI_ARG(args[0])); | 1426 request_dec_mode(state, CSI_ARG(args[0])); |
1427 break; | |
1428 | |
1429 case LEADER('>', 0x71): // XTVERSION - xterm query version string | |
1430 request_version_string(state); | |
1424 break; | 1431 break; |
1425 | 1432 |
1426 case INTERMED(' ', 0x71): // DECSCUSR - DEC set cursor shape | 1433 case INTERMED(' ', 0x71): // DECSCUSR - DEC set cursor shape |
1427 val = CSI_ARG_OR(args[0], 1); | 1434 val = CSI_ARG_OR(args[0], 1); |
1428 | 1435 |
2016 | 2023 |
2017 vterm_allocator_free(state->vt, state->tabstops); | 2024 vterm_allocator_free(state->vt, state->tabstops); |
2018 state->tabstops = newtabstops; | 2025 state->tabstops = newtabstops; |
2019 } | 2026 } |
2020 | 2027 |
2021 if(rows != state->rows) { | |
2022 int bufidx; | |
2023 for(bufidx = BUFIDX_PRIMARY; bufidx <= BUFIDX_ALTSCREEN; bufidx++) { | |
2024 int row; | |
2025 VTermLineInfo *oldlineinfo = state->lineinfos[bufidx]; | |
2026 VTermLineInfo *newlineinfo; | |
2027 if(!oldlineinfo) | |
2028 continue; | |
2029 | |
2030 newlineinfo = vterm_allocator_malloc(state->vt, rows * sizeof(VTermLineInfo)); | |
2031 | |
2032 for(row = 0; row < state->rows && row < rows; row++) { | |
2033 newlineinfo[row] = oldlineinfo[row]; | |
2034 } | |
2035 | |
2036 for( ; row < rows; row++) { | |
2037 VTermLineInfo lineInfo = {0x0}; | |
2038 newlineinfo[row] = lineInfo; | |
2039 } | |
2040 | |
2041 vterm_allocator_free(state->vt, state->lineinfos[bufidx]); | |
2042 state->lineinfos[bufidx] = newlineinfo; | |
2043 } | |
2044 | |
2045 state->lineinfo = state->lineinfos[state->mode.alt_screen ? BUFIDX_ALTSCREEN : BUFIDX_PRIMARY]; | |
2046 } | |
2047 | |
2048 state->rows = rows; | 2028 state->rows = rows; |
2049 state->cols = cols; | 2029 state->cols = cols; |
2050 | 2030 |
2051 if(state->scrollregion_bottom > -1) | 2031 if(state->scrollregion_bottom > -1) |
2052 UBOUND(state->scrollregion_bottom, state->rows); | 2032 UBOUND(state->scrollregion_bottom, state->rows); |
2053 if(state->scrollregion_right > -1) | 2033 if(state->scrollregion_right > -1) |
2054 UBOUND(state->scrollregion_right, state->cols); | 2034 UBOUND(state->scrollregion_right, state->cols); |
2055 | 2035 |
2056 fields.pos = state->pos; | 2036 fields.pos = state->pos; |
2057 | 2037 fields.lineinfos[0] = state->lineinfos[0]; |
2058 if(state->callbacks && state->callbacks->resize) | 2038 fields.lineinfos[1] = state->lineinfos[1]; |
2039 | |
2040 if(state->callbacks && state->callbacks->resize) { | |
2059 (*state->callbacks->resize)(rows, cols, &fields, state->cbdata); | 2041 (*state->callbacks->resize)(rows, cols, &fields, state->cbdata); |
2060 | 2042 |
2061 state->pos = fields.pos; | 2043 state->pos = fields.pos; |
2044 | |
2045 state->lineinfos[0] = fields.lineinfos[0]; | |
2046 state->lineinfos[1] = fields.lineinfos[1]; | |
2047 } | |
2048 else { | |
2049 if(rows != state->rows) { | |
2050 for(int bufidx = BUFIDX_PRIMARY; bufidx <= BUFIDX_ALTSCREEN; bufidx++) { | |
2051 VTermLineInfo *oldlineinfo = state->lineinfos[bufidx]; | |
2052 if(!oldlineinfo) | |
2053 continue; | |
2054 | |
2055 VTermLineInfo *newlineinfo = vterm_allocator_malloc(state->vt, rows * sizeof(VTermLineInfo)); | |
2056 | |
2057 int row; | |
2058 for(row = 0; row < state->rows && row < rows; row++) { | |
2059 newlineinfo[row] = oldlineinfo[row]; | |
2060 } | |
2061 | |
2062 for( ; row < rows; row++) { | |
2063 newlineinfo[row] = (VTermLineInfo){ | |
2064 .doublewidth = 0, | |
2065 }; | |
2066 } | |
2067 | |
2068 vterm_allocator_free(state->vt, state->lineinfos[bufidx]); | |
2069 state->lineinfos[bufidx] = newlineinfo; | |
2070 } | |
2071 } | |
2072 } | |
2073 | |
2074 state->lineinfo = state->lineinfos[state->mode.alt_screen ? BUFIDX_ALTSCREEN : BUFIDX_PRIMARY]; | |
2062 | 2075 |
2063 if(state->at_phantom && state->pos.col < cols-1) { | 2076 if(state->at_phantom && state->pos.col < cols-1) { |
2064 state->at_phantom = 0; | 2077 state->at_phantom = 0; |
2065 state->pos.col++; | 2078 state->pos.col++; |
2066 } | 2079 } |