Mercurial > vim
comparison src/terminal.c @ 20500:03826c672315 v8.2.0804
patch 8.2.0804: libvterm code lags behind the upstream version
Commit: https://github.com/vim/vim/commit/e5886ccb5163873dd01fc67b09ab10e681351ee9
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu May 21 20:10:04 2020 +0200
patch 8.2.0804: libvterm code lags behind the upstream version
Problem: Libvterm code lags behind the upstream version.
Solution: Include revision 727, but add the index instead of switching
between RGB and indexed.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 21 May 2020 20:15:04 +0200 |
parents | 747a270eb1db |
children | 357dea6b9fde |
comparison
equal
deleted
inserted
replaced
20499:a7a490678633 | 20500:03826c672315 |
---|---|
1624 } | 1624 } |
1625 | 1625 |
1626 static int | 1626 static int |
1627 equal_celattr(cellattr_T *a, cellattr_T *b) | 1627 equal_celattr(cellattr_T *a, cellattr_T *b) |
1628 { | 1628 { |
1629 // Comparing the colors should be sufficient. | 1629 // We only compare the RGB colors, ignoring the ANSI index and type. |
1630 // Thus black set explicitly is equal the background black. | |
1630 return a->fg.red == b->fg.red | 1631 return a->fg.red == b->fg.red |
1631 && a->fg.green == b->fg.green | 1632 && a->fg.green == b->fg.green |
1632 && a->fg.blue == b->fg.blue | 1633 && a->fg.blue == b->fg.blue |
1633 && a->bg.red == b->bg.red | 1634 && a->bg.red == b->bg.red |
1634 && a->bg.green == b->bg.green | 1635 && a->bg.green == b->bg.green |
2690 { | 2691 { |
2691 int red = color->red; | 2692 int red = color->red; |
2692 int blue = color->blue; | 2693 int blue = color->blue; |
2693 int green = color->green; | 2694 int green = color->green; |
2694 | 2695 |
2695 if (color->ansi_index != VTERM_ANSI_INDEX_NONE) | 2696 if (VTERM_COLOR_IS_DEFAULT_FG(color) |
2697 || VTERM_COLOR_IS_DEFAULT_BG(color)) | |
2698 return 0; | |
2699 if (VTERM_COLOR_IS_INDEXED(color)) | |
2696 { | 2700 { |
2697 // The first 16 colors and default: use the ANSI index. | 2701 // The first 16 colors and default: use the ANSI index. |
2698 switch (color->ansi_index) | 2702 switch (color->index + 1) |
2699 { | 2703 { |
2700 case 0: return 0; | 2704 case 0: return 0; |
2701 case 1: return lookup_color( 0, fg, boldp) + 1; // black | 2705 case 1: return lookup_color( 0, fg, boldp) + 1; // black |
2702 case 2: return lookup_color( 4, fg, boldp) + 1; // dark red | 2706 case 2: return lookup_color( 4, fg, boldp) + 1; // dark red |
2703 case 3: return lookup_color( 2, fg, boldp) + 1; // dark green | 2707 case 3: return lookup_color( 2, fg, boldp) + 1; // dark green |
3830 * This is compatible with xterm. | 3834 * This is compatible with xterm. |
3831 */ | 3835 */ |
3832 static void | 3836 static void |
3833 cterm_color2vterm(int nr, VTermColor *rgb) | 3837 cterm_color2vterm(int nr, VTermColor *rgb) |
3834 { | 3838 { |
3835 cterm_color2rgb(nr, &rgb->red, &rgb->green, &rgb->blue, &rgb->ansi_index); | 3839 cterm_color2rgb(nr, &rgb->red, &rgb->green, &rgb->blue, &rgb->index); |
3840 if (rgb->index == 0) | |
3841 rgb->type = VTERM_COLOR_RGB; | |
3842 else | |
3843 { | |
3844 rgb->type = VTERM_COLOR_INDEXED; | |
3845 --rgb->index; | |
3846 } | |
3836 } | 3847 } |
3837 | 3848 |
3838 /* | 3849 /* |
3839 * Initialize term->tl_default_color from the environment. | 3850 * Initialize term->tl_default_color from the environment. |
3840 */ | 3851 */ |
3862 fgval = 255; | 3873 fgval = 255; |
3863 bgval = 0; | 3874 bgval = 0; |
3864 } | 3875 } |
3865 fg->red = fg->green = fg->blue = fgval; | 3876 fg->red = fg->green = fg->blue = fgval; |
3866 bg->red = bg->green = bg->blue = bgval; | 3877 bg->red = bg->green = bg->blue = bgval; |
3867 fg->ansi_index = bg->ansi_index = VTERM_ANSI_INDEX_DEFAULT; | 3878 fg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_FG; |
3879 bg->type = VTERM_COLOR_RGB | VTERM_COLOR_DEFAULT_BG; | |
3868 | 3880 |
3869 // The 'wincolor' or the highlight group overrules the defaults. | 3881 // The 'wincolor' or the highlight group overrules the defaults. |
3870 if (wp != NULL && *wp->w_p_wcr != NUL) | 3882 if (wp != NULL && *wp->w_p_wcr != NUL) |
3871 id = syn_name2id(wp->w_p_wcr); | 3883 id = syn_name2id(wp->w_p_wcr); |
3872 else | 3884 else |
4507 return NULL; | 4519 return NULL; |
4508 } | 4520 } |
4509 return buf; | 4521 return buf; |
4510 } | 4522 } |
4511 | 4523 |
4512 static int | 4524 static void |
4513 same_color(VTermColor *a, VTermColor *b) | 4525 clear_cell(VTermScreenCell *cell) |
4514 { | 4526 { |
4515 return a->red == b->red | 4527 CLEAR_FIELD(*cell); |
4516 && a->green == b->green | 4528 cell->fg.type = VTERM_COLOR_DEFAULT_FG; |
4517 && a->blue == b->blue | 4529 cell->bg.type = VTERM_COLOR_DEFAULT_BG; |
4518 && a->ansi_index == b->ansi_index; | |
4519 } | 4530 } |
4520 | 4531 |
4521 static void | 4532 static void |
4522 dump_term_color(FILE *fd, VTermColor *color) | 4533 dump_term_color(FILE *fd, VTermColor *color) |
4523 { | 4534 { |
4535 int index; | |
4536 | |
4537 if (VTERM_COLOR_IS_INDEXED(color)) | |
4538 index = color->index + 1; | |
4539 else if (color->type == 0) | |
4540 // use RGB values | |
4541 index = 255; | |
4542 else | |
4543 // default color | |
4544 index = 0; | |
4524 fprintf(fd, "%02x%02x%02x%d", | 4545 fprintf(fd, "%02x%02x%02x%d", |
4525 (int)color->red, (int)color->green, (int)color->blue, | 4546 (int)color->red, (int)color->green, (int)color->blue, |
4526 (int)color->ansi_index); | 4547 index); |
4527 } | 4548 } |
4528 | 4549 |
4529 /* | 4550 /* |
4530 * "term_dumpwrite(buf, filename, options)" function | 4551 * "term_dumpwrite(buf, filename, options)" function |
4531 * | 4552 * |
4605 { | 4626 { |
4606 semsg(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname); | 4627 semsg(_(e_notcreate), *fname == NUL ? (char_u *)_("<empty>") : fname); |
4607 return; | 4628 return; |
4608 } | 4629 } |
4609 | 4630 |
4610 CLEAR_FIELD(prev_cell); | 4631 clear_cell(&prev_cell); |
4611 | 4632 |
4612 screen = vterm_obtain_screen(term->tl_vterm); | 4633 screen = vterm_obtain_screen(term->tl_vterm); |
4613 state = vterm_obtain_state(term->tl_vterm); | 4634 state = vterm_obtain_state(term->tl_vterm); |
4614 vterm_state_get_cursorpos(state, &cursor_pos); | 4635 vterm_state_get_cursorpos(state, &cursor_pos); |
4615 | 4636 |
4627 int i; | 4648 int i; |
4628 int is_cursor_pos = (pos.col == cursor_pos.col | 4649 int is_cursor_pos = (pos.col == cursor_pos.col |
4629 && pos.row == cursor_pos.row); | 4650 && pos.row == cursor_pos.row); |
4630 | 4651 |
4631 if (vterm_screen_get_cell(screen, pos, &cell) == 0) | 4652 if (vterm_screen_get_cell(screen, pos, &cell) == 0) |
4632 CLEAR_FIELD(cell); | 4653 clear_cell(&cell); |
4633 | 4654 |
4634 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i) | 4655 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i) |
4635 { | 4656 { |
4636 int c = cell.chars[i]; | 4657 int c = cell.chars[i]; |
4637 int pc = prev_cell.chars[i]; | 4658 int pc = prev_cell.chars[i]; |
4647 if (c == NUL || pc == NUL) | 4668 if (c == NUL || pc == NUL) |
4648 break; | 4669 break; |
4649 } | 4670 } |
4650 same_attr = vtermAttr2hl(cell.attrs) | 4671 same_attr = vtermAttr2hl(cell.attrs) |
4651 == vtermAttr2hl(prev_cell.attrs) | 4672 == vtermAttr2hl(prev_cell.attrs) |
4652 && same_color(&cell.fg, &prev_cell.fg) | 4673 && vterm_color_is_equal(&cell.fg, &prev_cell.fg) |
4653 && same_color(&cell.bg, &prev_cell.bg); | 4674 && vterm_color_is_equal(&cell.bg, &prev_cell.bg); |
4654 if (same_chars && cell.width == prev_cell.width && same_attr | 4675 if (same_chars && cell.width == prev_cell.width && same_attr |
4655 && !is_cursor_pos) | 4676 && !is_cursor_pos) |
4656 { | 4677 { |
4657 ++repeat; | 4678 ++repeat; |
4658 } | 4679 } |
4695 fputs("&", fd); | 4716 fputs("&", fd); |
4696 } | 4717 } |
4697 else | 4718 else |
4698 { | 4719 { |
4699 fprintf(fd, "%d", vtermAttr2hl(cell.attrs)); | 4720 fprintf(fd, "%d", vtermAttr2hl(cell.attrs)); |
4700 if (same_color(&cell.fg, &prev_cell.fg)) | 4721 if (vterm_color_is_equal(&cell.fg, &prev_cell.fg)) |
4701 fputs("&", fd); | 4722 fputs("&", fd); |
4702 else | 4723 else |
4703 { | 4724 { |
4704 fputs("#", fd); | 4725 fputs("#", fd); |
4705 dump_term_color(fd, &cell.fg); | 4726 dump_term_color(fd, &cell.fg); |
4706 } | 4727 } |
4707 if (same_color(&cell.bg, &prev_cell.bg)) | 4728 if (vterm_color_is_equal(&cell.bg, &prev_cell.bg)) |
4708 fputs("&", fd); | 4729 fputs("&", fd); |
4709 else | 4730 else |
4710 { | 4731 { |
4711 fputs("#", fd); | 4732 fputs("#", fd); |
4712 dump_term_color(fd, &cell.bg); | 4733 dump_term_color(fd, &cell.bg); |
4743 if (ga_grow(gap, 1) == OK) | 4764 if (ga_grow(gap, 1) == OK) |
4744 { | 4765 { |
4745 *(((cellattr_T *)gap->ga_data) + gap->ga_len) = *cell; | 4766 *(((cellattr_T *)gap->ga_data) + gap->ga_len) = *cell; |
4746 ++gap->ga_len; | 4767 ++gap->ga_len; |
4747 } | 4768 } |
4769 } | |
4770 | |
4771 static void | |
4772 clear_cellattr(cellattr_T *cell) | |
4773 { | |
4774 CLEAR_FIELD(*cell); | |
4775 cell->fg.type = VTERM_COLOR_DEFAULT_FG; | |
4776 cell->bg.type = VTERM_COLOR_DEFAULT_BG; | |
4748 } | 4777 } |
4749 | 4778 |
4750 /* | 4779 /* |
4751 * Read the dump file from "fd" and append lines to the current buffer. | 4780 * Read the dump file from "fd" and append lines to the current buffer. |
4752 * Return the cell width of the longest line. | 4781 * Return the cell width of the longest line. |
4765 int max_cells = 0; | 4794 int max_cells = 0; |
4766 int start_row = term->tl_scrollback.ga_len; | 4795 int start_row = term->tl_scrollback.ga_len; |
4767 | 4796 |
4768 ga_init2(&ga_text, 1, 90); | 4797 ga_init2(&ga_text, 1, 90); |
4769 ga_init2(&ga_cell, sizeof(cellattr_T), 90); | 4798 ga_init2(&ga_cell, sizeof(cellattr_T), 90); |
4770 CLEAR_FIELD(cell); | 4799 clear_cellattr(&cell); |
4771 CLEAR_FIELD(empty_cell); | 4800 clear_cellattr(&empty_cell); |
4772 cursor_pos->row = -1; | 4801 cursor_pos->row = -1; |
4773 cursor_pos->col = -1; | 4802 cursor_pos->col = -1; |
4774 | 4803 |
4775 c = fgetc(fd); | 4804 c = fgetc(fd); |
4776 for (;;) | 4805 for (;;) |
4876 // use same color as previous cell | 4905 // use same color as previous cell |
4877 c = fgetc(fd); | 4906 c = fgetc(fd); |
4878 } | 4907 } |
4879 else if (c == '#') | 4908 else if (c == '#') |
4880 { | 4909 { |
4881 int red, green, blue, index = 0; | 4910 int red, green, blue, index = 0, type; |
4882 | 4911 |
4883 c = fgetc(fd); | 4912 c = fgetc(fd); |
4884 red = hex2nr(c); | 4913 red = hex2nr(c); |
4885 c = fgetc(fd); | 4914 c = fgetc(fd); |
4886 red = (red << 4) + hex2nr(c); | 4915 red = (red << 4) + hex2nr(c); |
4898 while (isdigit(c)) | 4927 while (isdigit(c)) |
4899 { | 4928 { |
4900 index = index * 10 + (c - '0'); | 4929 index = index * 10 + (c - '0'); |
4901 c = fgetc(fd); | 4930 c = fgetc(fd); |
4902 } | 4931 } |
4903 | 4932 if (index == 0 || index == 255) |
4933 { | |
4934 type = VTERM_COLOR_RGB; | |
4935 if (index == 0) | |
4936 { | |
4937 if (is_bg) | |
4938 type |= VTERM_COLOR_DEFAULT_BG; | |
4939 else | |
4940 type |= VTERM_COLOR_DEFAULT_FG; | |
4941 } | |
4942 } | |
4943 else | |
4944 { | |
4945 type = VTERM_COLOR_INDEXED; | |
4946 index -= 1; | |
4947 } | |
4904 if (is_bg) | 4948 if (is_bg) |
4905 { | 4949 { |
4950 cell.bg.type = type; | |
4906 cell.bg.red = red; | 4951 cell.bg.red = red; |
4907 cell.bg.green = green; | 4952 cell.bg.green = green; |
4908 cell.bg.blue = blue; | 4953 cell.bg.blue = blue; |
4909 cell.bg.ansi_index = index; | 4954 cell.bg.index = index; |
4910 } | 4955 } |
4911 else | 4956 else |
4912 { | 4957 { |
4958 cell.fg.type = type; | |
4913 cell.fg.red = red; | 4959 cell.fg.red = red; |
4914 cell.fg.green = green; | 4960 cell.fg.green = green; |
4915 cell.fg.blue = blue; | 4961 cell.fg.blue = blue; |
4916 cell.fg.ansi_index = index; | 4962 cell.fg.index = index; |
4917 } | 4963 } |
4918 } | 4964 } |
4919 else | 4965 else |
4920 dump_is_corrupt(&ga_text); | 4966 dump_is_corrupt(&ga_text); |
4921 } | 4967 } |
5224 else if (cellattr1 != NULL && cellattr2 != NULL) | 5270 else if (cellattr1 != NULL && cellattr2 != NULL) |
5225 { | 5271 { |
5226 if ((cellattr1 + col)->width | 5272 if ((cellattr1 + col)->width |
5227 != (cellattr2 + col)->width) | 5273 != (cellattr2 + col)->width) |
5228 textline[col] = 'w'; | 5274 textline[col] = 'w'; |
5229 else if (!same_color(&(cellattr1 + col)->fg, | 5275 else if (!vterm_color_is_equal(&(cellattr1 + col)->fg, |
5230 &(cellattr2 + col)->fg)) | 5276 &(cellattr2 + col)->fg)) |
5231 textline[col] = 'f'; | 5277 textline[col] = 'f'; |
5232 else if (!same_color(&(cellattr1 + col)->bg, | 5278 else if (!vterm_color_is_equal(&(cellattr1 + col)->bg, |
5233 &(cellattr2 + col)->bg)) | 5279 &(cellattr2 + col)->bg)) |
5234 textline[col] = 'b'; | 5280 textline[col] = 'b'; |
5235 else if (vtermAttr2hl((cellattr1 + col)->attrs) | 5281 else if (vtermAttr2hl((cellattr1 + col)->attrs) |
5236 != vtermAttr2hl(((cellattr2 + col)->attrs))) | 5282 != vtermAttr2hl(((cellattr2 + col)->attrs))) |
5237 textline[col] = 'a'; | 5283 textline[col] = 'a'; |
5806 p += len; | 5852 p += len; |
5807 } | 5853 } |
5808 else | 5854 else |
5809 { | 5855 { |
5810 VTermScreenCell cell; | 5856 VTermScreenCell cell; |
5857 | |
5811 if (vterm_screen_get_cell(screen, pos, &cell) == 0) | 5858 if (vterm_screen_get_cell(screen, pos, &cell) == 0) |
5812 break; | 5859 break; |
5813 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i) | 5860 for (i = 0; i < VTERM_MAX_CHARS_PER_CELL; ++i) |
5814 { | 5861 { |
5815 if (cell.chars[i] == 0) | 5862 if (cell.chars[i] == 0) |