comparison src/libvterm/src/state.c @ 20518:a4652d7ec99f v8.2.0813

patch 8.2.0813: libvterm code is slightly different from upstream Commit: https://github.com/vim/vim/commit/591cec8366e87a172495c362477cbf5de8d399f0 Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 22 22:06:06 2020 +0200 patch 8.2.0813: libvterm code is slightly different from upstream Problem: libvterm code is slightly different from upstream. Solution: Use upstream text to avoid future merge problems. Mainly comment style changes.
author Bram Moolenaar <Bram@vim.org>
date Fri, 22 May 2020 22:15:04 +0200
parents 03826c672315
children 88cec48503b8
comparison
equal deleted inserted replaced
20517:a7c6cd0d7ba0 20518:a4652d7ec99f
9 # define DEBUG_GLYPH_COMBINE 9 # define DEBUG_GLYPH_COMBINE
10 #endif 10 #endif
11 11
12 static int on_resize(int rows, int cols, void *user); 12 static int on_resize(int rows, int cols, void *user);
13 13
14 // Some convenient wrappers to make callback functions easier 14 /* Some convenient wrappers to make callback functions easier */
15 15
16 static void putglyph(VTermState *state, const uint32_t chars[], int width, VTermPos pos) 16 static void putglyph(VTermState *state, const uint32_t chars[], int width, VTermPos pos)
17 { 17 {
18 VTermGlyphInfo info; 18 VTermGlyphInfo info;
19 info.chars = chars; 19 info.chars = chars;
297 297
298 (*encoding->enc->decode)(encoding->enc, encoding->data, 298 (*encoding->enc->decode)(encoding->enc, encoding->data,
299 codepoints, &npoints, state->gsingle_set ? 1 : (int)len, 299 codepoints, &npoints, state->gsingle_set ? 1 : (int)len,
300 bytes, &eaten, len); 300 bytes, &eaten, len);
301 301
302 // There's a chance an encoding (e.g. UTF-8) hasn't found enough bytes yet 302 /* There's a chance an encoding (e.g. UTF-8) hasn't found enough bytes yet
303 // for even a single codepoint 303 * for even a single codepoint
304 */
304 if(!npoints) 305 if(!npoints)
305 { 306 {
306 vterm_allocator_free(state->vt, codepoints); 307 vterm_allocator_free(state->vt, codepoints);
307 return (int)eaten; 308 return (int)eaten;
308 } 309 }
309 310
310 if(state->gsingle_set && npoints) 311 if(state->gsingle_set && npoints)
311 state->gsingle_set = 0; 312 state->gsingle_set = 0;
312 313
313 // This is a combining char. that needs to be merged with the previous 314 /* This is a combining char. that needs to be merged with the previous
314 // glyph output 315 * glyph output */
315 if(vterm_unicode_is_combining(codepoints[i])) { 316 if(vterm_unicode_is_combining(codepoints[i])) {
316 // See if the cursor has moved since 317 /* See if the cursor has moved since */
317 if(state->pos.row == state->combine_pos.row && state->pos.col == state->combine_pos.col + state->combine_width) { 318 if(state->pos.row == state->combine_pos.row && state->pos.col == state->combine_pos.col + state->combine_width) {
318 #ifdef DEBUG_GLYPH_COMBINE 319 #ifdef DEBUG_GLYPH_COMBINE
319 int printpos; 320 int printpos;
320 printf("DEBUG: COMBINING SPLIT GLYPH of chars {"); 321 printf("DEBUG: COMBINING SPLIT GLYPH of chars {");
321 for(printpos = 0; state->combine_chars[printpos]; printpos++) 322 for(printpos = 0; state->combine_chars[printpos]; printpos++)
322 printf("U+%04x ", state->combine_chars[printpos]); 323 printf("U+%04x ", state->combine_chars[printpos]);
323 printf("} + {"); 324 printf("} + {");
324 #endif 325 #endif
325 326
326 // Find where we need to append these combining chars 327 /* Find where we need to append these combining chars */
327 int saved_i = 0; 328 int saved_i = 0;
328 while(state->combine_chars[saved_i]) 329 while(state->combine_chars[saved_i])
329 saved_i++; 330 saved_i++;
330 331
331 // Add extra ones 332 /* Add extra ones */
332 while(i < npoints && vterm_unicode_is_combining(codepoints[i])) { 333 while(i < npoints && vterm_unicode_is_combining(codepoints[i])) {
333 if(saved_i >= (int)state->combine_chars_size) 334 if(saved_i >= (int)state->combine_chars_size)
334 grow_combine_buffer(state); 335 grow_combine_buffer(state);
335 state->combine_chars[saved_i++] = codepoints[i++]; 336 state->combine_chars[saved_i++] = codepoints[i++];
336 } 337 }
342 for(; state->combine_chars[printpos]; printpos++) 343 for(; state->combine_chars[printpos]; printpos++)
343 printf("U+%04x ", state->combine_chars[printpos]); 344 printf("U+%04x ", state->combine_chars[printpos]);
344 printf("}\n"); 345 printf("}\n");
345 #endif 346 #endif
346 347
347 // Now render it 348 /* Now render it */
348 putglyph(state, state->combine_chars, state->combine_width, state->combine_pos); 349 putglyph(state, state->combine_chars, state->combine_width, state->combine_pos);
349 } 350 }
350 else { 351 else {
351 DEBUG_LOG("libvterm: TODO: Skip over split char+combining\n"); 352 DEBUG_LOG("libvterm: TODO: Skip over split char+combining\n");
352 } 353 }
416 } 417 }
417 418
418 putglyph(state, chars, width, state->pos); 419 putglyph(state, chars, width, state->pos);
419 420
420 if(i == npoints - 1) { 421 if(i == npoints - 1) {
421 // End of the buffer. Save the chars in case we have to combine with 422 /* End of the buffer. Save the chars in case we have to combine with
422 // more on the next call 423 * more on the next call */
423 int save_i; 424 int save_i;
424 for(save_i = 0; chars[save_i]; save_i++) { 425 for(save_i = 0; chars[save_i]; save_i++) {
425 if(save_i >= (int)state->combine_chars_size) 426 if(save_i >= (int)state->combine_chars_size)
426 grow_combine_buffer(state); 427 grow_combine_buffer(state);
427 state->combine_chars[save_i] = chars[save_i]; 428 state->combine_chars[save_i] = chars[save_i];
617 618
618 static int on_escape(const char *bytes, size_t len, void *user) 619 static int on_escape(const char *bytes, size_t len, void *user)
619 { 620 {
620 VTermState *state = user; 621 VTermState *state = user;
621 622
622 // Easier to decode this from the first byte, even though the final 623 /* Easier to decode this from the first byte, even though the final
623 // byte terminates it 624 * byte terminates it
625 */
624 switch(bytes[0]) { 626 switch(bytes[0]) {
625 case ' ': 627 case ' ':
626 if(len != 2) 628 if(len != 2)
627 return 0; 629 return 0;
628 630
1336 break; 1338 break;
1337 case 1: 1339 case 1:
1338 case 2: 1340 case 2:
1339 case 4: 1341 case 4:
1340 break; 1342 break;
1341 // TODO: 1, 2 and 4 aren't meaningful yet without line tab stops 1343 /* TODO: 1, 2 and 4 aren't meaningful yet without line tab stops */
1342 default: 1344 default:
1343 return 0; 1345 return 0;
1344 } 1346 }
1345 break; 1347 break;
1346 1348
1771 int col; 1773 int col;
1772 unsigned char *newtabstops = vterm_allocator_malloc(state->vt, (cols + 7) / 8); 1774 unsigned char *newtabstops = vterm_allocator_malloc(state->vt, (cols + 7) / 8);
1773 if (newtabstops == NULL) 1775 if (newtabstops == NULL)
1774 return 0; 1776 return 0;
1775 1777
1776 // TODO: This can all be done much more efficiently bytewise 1778 /* TODO: This can all be done much more efficiently bytewise */
1777 for(col = 0; col < state->cols && col < cols; col++) { 1779 for(col = 0; col < state->cols && col < cols; col++) {
1778 unsigned char mask = 1 << (col & 7); 1780 unsigned char mask = 1 << (col & 7);
1779 if(state->tabstops[col >> 3] & mask) 1781 if(state->tabstops[col >> 3] & mask)
1780 newtabstops[col >> 3] |= mask; 1782 newtabstops[col >> 3] |= mask;
1781 else 1783 else
2010 return state->fbdata; 2012 return state->fbdata;
2011 } 2013 }
2012 2014
2013 int vterm_state_set_termprop(VTermState *state, VTermProp prop, VTermValue *val) 2015 int vterm_state_set_termprop(VTermState *state, VTermProp prop, VTermValue *val)
2014 { 2016 {
2015 // Only store the new value of the property if usercode said it was happy. 2017 /* Only store the new value of the property if usercode said it was happy.
2016 // This is especially important for altscreen switching 2018 * This is especially important for altscreen switching */
2017 if(state->callbacks && state->callbacks->settermprop) 2019 if(state->callbacks && state->callbacks->settermprop)
2018 if(!(*state->callbacks->settermprop)(prop, val, state->cbdata)) 2020 if(!(*state->callbacks->settermprop)(prop, val, state->cbdata))
2019 return 0; 2021 return 0;
2020 2022
2021 switch(prop) { 2023 switch(prop) {