Mercurial > vim
comparison src/libvterm/src/termscreen.c @ 17777:811a12a78164 v8.1.1885
patch 8.1.1885: comments in libvterm are inconsistent
commit https://github.com/vim/vim/commit/db1085a5630ffdaa2e9f342c06cc739ebdf1a99a
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 18 20:41:38 2019 +0200
patch 8.1.1885: comments in libvterm are inconsistent
Problem: Comments in libvterm are inconsistent.
Solution: Use // comments. Als update the table of combining characters.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 18 Aug 2019 20:45:04 +0200 |
parents | a1229400434a |
children | 8b4f9be5db73 |
comparison
equal
deleted
inserted
replaced
17776:5c9a1d9d02ad | 17777:811a12a78164 |
---|---|
1 #include "vterm_internal.h" | 1 #include "vterm_internal.h" |
2 | 2 |
3 /* vim: set sw=2 : */ | 3 // vim: set sw=2 : |
4 #include <stdio.h> | 4 #include <stdio.h> |
5 #include <string.h> | 5 #include <string.h> |
6 | 6 |
7 #include "rect.h" | 7 #include "rect.h" |
8 #include "utf8.h" | 8 #include "utf8.h" |
9 | 9 |
10 #define UNICODE_SPACE 0x20 | 10 #define UNICODE_SPACE 0x20 |
11 #define UNICODE_LINEFEED 0x0a | 11 #define UNICODE_LINEFEED 0x0a |
12 | 12 |
13 /* State of the pen at some moment in time, also used in a cell */ | 13 // State of the pen at some moment in time, also used in a cell |
14 typedef struct | 14 typedef struct |
15 { | 15 { |
16 /* After the bitfield */ | 16 // After the bitfield |
17 VTermColor fg, bg; | 17 VTermColor fg, bg; |
18 | 18 |
19 unsigned int bold : 1; | 19 unsigned int bold : 1; |
20 unsigned int underline : 2; | 20 unsigned int underline : 2; |
21 unsigned int italic : 1; | 21 unsigned int italic : 1; |
22 unsigned int blink : 1; | 22 unsigned int blink : 1; |
23 unsigned int reverse : 1; | 23 unsigned int reverse : 1; |
24 unsigned int strike : 1; | 24 unsigned int strike : 1; |
25 unsigned int font : 4; /* 0 to 9 */ | 25 unsigned int font : 4; // 0 to 9 |
26 | 26 |
27 /* Extra state storage that isn't strictly pen-related */ | 27 // Extra state storage that isn't strictly pen-related |
28 unsigned int protected_cell : 1; | 28 unsigned int protected_cell : 1; |
29 unsigned int dwl : 1; /* on a DECDWL or DECDHL line */ | 29 unsigned int dwl : 1; // on a DECDWL or DECDHL line |
30 unsigned int dhl : 2; /* on a DECDHL line (1=top 2=bottom) */ | 30 unsigned int dhl : 2; // on a DECDHL line (1=top 2=bottom) |
31 } ScreenPen; | 31 } ScreenPen; |
32 | 32 |
33 /* Internal representation of a screen cell */ | 33 // Internal representation of a screen cell |
34 typedef struct | 34 typedef struct |
35 { | 35 { |
36 uint32_t chars[VTERM_MAX_CHARS_PER_CELL]; | 36 uint32_t chars[VTERM_MAX_CHARS_PER_CELL]; |
37 ScreenPen pen; | 37 ScreenPen pen; |
38 } ScreenCell; | 38 } ScreenCell; |
46 | 46 |
47 const VTermScreenCallbacks *callbacks; | 47 const VTermScreenCallbacks *callbacks; |
48 void *cbdata; | 48 void *cbdata; |
49 | 49 |
50 VTermDamageSize damage_merge; | 50 VTermDamageSize damage_merge; |
51 /* start_row == -1 => no damage */ | 51 // start_row == -1 => no damage |
52 VTermRect damaged; | 52 VTermRect damaged; |
53 VTermRect pending_scrollrect; | 53 VTermRect pending_scrollrect; |
54 int pending_scroll_downward, pending_scroll_rightward; | 54 int pending_scroll_downward, pending_scroll_rightward; |
55 | 55 |
56 int rows; | 56 int rows; |
57 int cols; | 57 int cols; |
58 int global_reverse; | 58 int global_reverse; |
59 | 59 |
60 /* Primary and Altscreen. buffers[1] is lazily allocated as needed */ | 60 // Primary and Altscreen. buffers[1] is lazily allocated as needed |
61 ScreenCell *buffers[2]; | 61 ScreenCell *buffers[2]; |
62 | 62 |
63 /* buffer will == buffers[0] or buffers[1], depending on altscreen */ | 63 // buffer will == buffers[0] or buffers[1], depending on altscreen |
64 ScreenCell *buffer; | 64 ScreenCell *buffer; |
65 | 65 |
66 /* buffer for a single screen row used in scrollback storage callbacks */ | 66 // buffer for a single screen row used in scrollback storage callbacks |
67 VTermScreenCell *sb_buffer; | 67 VTermScreenCell *sb_buffer; |
68 | 68 |
69 ScreenPen pen; | 69 ScreenPen pen; |
70 }; | 70 }; |
71 | 71 |
107 { | 107 { |
108 VTermRect emit; | 108 VTermRect emit; |
109 | 109 |
110 switch(screen->damage_merge) { | 110 switch(screen->damage_merge) { |
111 case VTERM_DAMAGE_CELL: | 111 case VTERM_DAMAGE_CELL: |
112 /* Always emit damage event */ | 112 // Always emit damage event |
113 emit = rect; | 113 emit = rect; |
114 break; | 114 break; |
115 | 115 |
116 case VTERM_DAMAGE_ROW: | 116 case VTERM_DAMAGE_ROW: |
117 /* Emit damage longer than one row. Try to merge with existing damage in | 117 // Emit damage longer than one row. Try to merge with existing damage in |
118 * the same row */ | 118 // the same row |
119 if(rect.end_row > rect.start_row + 1) { | 119 if(rect.end_row > rect.start_row + 1) { |
120 // Bigger than 1 line - flush existing, emit this | 120 // Bigger than 1 line - flush existing, emit this |
121 vterm_screen_flush_damage(screen); | 121 vterm_screen_flush_damage(screen); |
122 emit = rect; | 122 emit = rect; |
123 } | 123 } |
141 } | 141 } |
142 break; | 142 break; |
143 | 143 |
144 case VTERM_DAMAGE_SCREEN: | 144 case VTERM_DAMAGE_SCREEN: |
145 case VTERM_DAMAGE_SCROLL: | 145 case VTERM_DAMAGE_SCROLL: |
146 /* Never emit damage event */ | 146 // Never emit damage event |
147 if(screen->damaged.start_row == -1) | 147 if(screen->damaged.start_row == -1) |
148 screen->damaged = rect; | 148 screen->damaged = rect; |
149 else { | 149 else { |
150 rect_expand(&screen->damaged, &rect); | 150 rect_expand(&screen->damaged, &rect); |
151 } | 151 } |
350 | 350 |
351 if(screen->damaged.start_row == -1) | 351 if(screen->damaged.start_row == -1) |
352 return 1; | 352 return 1; |
353 | 353 |
354 if(rect_contains(&rect, &screen->damaged)) { | 354 if(rect_contains(&rect, &screen->damaged)) { |
355 /* Scroll region entirely contains the damage; just move it */ | 355 // Scroll region entirely contains the damage; just move it |
356 vterm_rect_move(&screen->damaged, -downward, -rightward); | 356 vterm_rect_move(&screen->damaged, -downward, -rightward); |
357 rect_clip(&screen->damaged, &rect); | 357 rect_clip(&screen->damaged, &rect); |
358 } | 358 } |
359 /* There are a number of possible cases here, but lets restrict this to only | 359 // There are a number of possible cases here, but lets restrict this to only |
360 * the common case where we might actually gain some performance by | 360 // the common case where we might actually gain some performance by |
361 * optimising it. Namely, a vertical scroll that neatly cuts the damage | 361 // optimising it. Namely, a vertical scroll that neatly cuts the damage |
362 * region in half. | 362 // region in half. |
363 */ | |
364 else if(rect.start_col <= screen->damaged.start_col && | 363 else if(rect.start_col <= screen->damaged.start_col && |
365 rect.end_col >= screen->damaged.end_col && | 364 rect.end_col >= screen->damaged.end_col && |
366 rightward == 0) { | 365 rightward == 0) { |
367 if(screen->damaged.start_row >= rect.start_row && | 366 if(screen->damaged.start_row >= rect.start_row && |
368 screen->damaged.start_row < rect.end_row) { | 367 screen->damaged.start_row < rect.end_row) { |
447 case VTERM_PROP_ALTSCREEN: | 446 case VTERM_PROP_ALTSCREEN: |
448 if(val->boolean && !screen->buffers[1]) | 447 if(val->boolean && !screen->buffers[1]) |
449 return 0; | 448 return 0; |
450 | 449 |
451 screen->buffer = val->boolean ? screen->buffers[1] : screen->buffers[0]; | 450 screen->buffer = val->boolean ? screen->buffers[1] : screen->buffers[0]; |
452 /* only send a damage event on disable; because during enable there's an | 451 // only send a damage event on disable; because during enable there's an |
453 * erase that sends a damage anyway | 452 // erase that sends a damage anyway |
454 */ | |
455 if(!val->boolean) | 453 if(!val->boolean) |
456 damagescreen(screen); | 454 damagescreen(screen); |
457 break; | 455 break; |
458 case VTERM_PROP_REVERSE: | 456 case VTERM_PROP_REVERSE: |
459 screen->global_reverse = val->boolean; | 457 screen->global_reverse = val->boolean; |
460 damagescreen(screen); | 458 damagescreen(screen); |
461 break; | 459 break; |
462 default: | 460 default: |
463 ; /* ignore */ | 461 ; // ignore |
464 } | 462 } |
465 | 463 |
466 if(screen->callbacks && screen->callbacks->settermprop) | 464 if(screen->callbacks && screen->callbacks->settermprop) |
467 return (*screen->callbacks->settermprop)(prop, val, screen->cbdata); | 465 return (*screen->callbacks->settermprop)(prop, val, screen->cbdata); |
468 | 466 |
605 | 603 |
606 return 1; | 604 return 1; |
607 } | 605 } |
608 | 606 |
609 static VTermStateCallbacks state_cbs = { | 607 static VTermStateCallbacks state_cbs = { |
610 &putglyph, /* putglyph */ | 608 &putglyph, // putglyph |
611 &movecursor, /* movecursor */ | 609 &movecursor, // movecursor |
612 &scrollrect, /* scrollrect */ | 610 &scrollrect, // scrollrect |
613 NULL, /* moverect */ | 611 NULL, // moverect |
614 &erase, /* erase */ | 612 &erase, // erase |
615 NULL, /* initpen */ | 613 NULL, // initpen |
616 &setpenattr, /* setpenattr */ | 614 &setpenattr, // setpenattr |
617 &settermprop, /* settermprop */ | 615 &settermprop, // settermprop |
618 &bell, /* bell */ | 616 &bell, // bell |
619 &resize, /* resize */ | 617 &resize, // resize |
620 &setlineinfo /* setlineinfo */ | 618 &setlineinfo // setlineinfo |
621 }; | 619 }; |
622 | 620 |
623 /* | 621 /* |
624 * Allocate a new screen and return it. | 622 * Allocate a new screen and return it. |
625 * Return NULL when out of memory. | 623 * Return NULL when out of memory. |
741 size_t vterm_screen_get_text(const VTermScreen *screen, char *str, size_t len, const VTermRect rect) | 739 size_t vterm_screen_get_text(const VTermScreen *screen, char *str, size_t len, const VTermRect rect) |
742 { | 740 { |
743 return _get_chars(screen, 1, str, len, rect); | 741 return _get_chars(screen, 1, str, len, rect); |
744 } | 742 } |
745 | 743 |
746 /* Copy internal to external representation of a screen cell */ | 744 // Copy internal to external representation of a screen cell |
747 int vterm_screen_get_cell(const VTermScreen *screen, VTermPos pos, VTermScreenCell *cell) | 745 int vterm_screen_get_cell(const VTermScreen *screen, VTermPos pos, VTermScreenCell *cell) |
748 { | 746 { |
749 ScreenCell *intcell = getcell(screen, pos.row, pos.col); | 747 ScreenCell *intcell = getcell(screen, pos.row, pos.col); |
750 int i; | 748 int i; |
751 | 749 |
779 cell->width = 1; | 777 cell->width = 1; |
780 | 778 |
781 return 1; | 779 return 1; |
782 } | 780 } |
783 | 781 |
784 /* Copy external to internal representation of a screen cell */ | 782 // Copy external to internal representation of a screen cell |
785 /* static because it's only used internally for sb_popline during resize */ | 783 /* static because it's only used internally for sb_popline during resize */ |
786 static int vterm_screen_set_cell(VTermScreen *screen, VTermPos pos, const VTermScreenCell *cell) | 784 static int vterm_screen_set_cell(VTermScreen *screen, VTermPos pos, const VTermScreenCell *cell) |
787 { | 785 { |
788 ScreenCell *intcell = getcell(screen, pos.row, pos.col); | 786 ScreenCell *intcell = getcell(screen, pos.row, pos.col); |
789 int i; | 787 int i; |
814 return 1; | 812 return 1; |
815 } | 813 } |
816 | 814 |
817 int vterm_screen_is_eol(const VTermScreen *screen, VTermPos pos) | 815 int vterm_screen_is_eol(const VTermScreen *screen, VTermPos pos) |
818 { | 816 { |
819 /* This cell is EOL if this and every cell to the right is black */ | 817 // This cell is EOL if this and every cell to the right is black |
820 for(; pos.col < screen->cols; pos.col++) { | 818 for(; pos.col < screen->cols; pos.col++) { |
821 ScreenCell *cell = getcell(screen, pos.row, pos.col); | 819 ScreenCell *cell = getcell(screen, pos.row, pos.col); |
822 if(cell->chars[0] != 0) | 820 if(cell->chars[0] != 0) |
823 return 0; | 821 return 0; |
824 } | 822 } |