comparison src/terminal.c @ 25965:1266292376c7 v8.2.3516

patch 8.2.3516: terminal window does not have transparent background Commit: https://github.com/vim/vim/commit/7b5f45be2197403d631b5a3d633f6a20afdf806e Author: Milly <milly.ca@gmail.com> Date: Fri Oct 15 22:25:43 2021 +0100 patch 8.2.3516: terminal window does not have transparent background Problem: Terminal window does not have transparent background when 'termguicolors' is used. Solution: Fix the background color. (closes #2361, closes #9002)
author Bram Moolenaar <Bram@vim.org>
date Fri, 15 Oct 2021 23:30:04 +0200
parents ea0820d05257
children e8873138ffbb
comparison
equal deleted inserted replaced
25964:0cc536850b7e 25965:1266292376c7
201 static void handle_postponed_scrollback(term_T *term); 201 static void handle_postponed_scrollback(term_T *term);
202 202
203 // The character that we know (or assume) that the terminal expects for the 203 // The character that we know (or assume) that the terminal expects for the
204 // backspace key. 204 // backspace key.
205 static int term_backspace_char = BS; 205 static int term_backspace_char = BS;
206
207 // "Terminal" highlight group colors.
208 static int term_default_cterm_fg = -1;
209 static int term_default_cterm_bg = -1;
210 206
211 // Store the last set and the desired cursor properties, so that we only update 207 // Store the last set and the desired cursor properties, so that we only update
212 // them when needed. Doing it unnecessary may result in flicker. 208 // them when needed. Doing it unnecessary may result in flicker.
213 static char_u *last_set_cursor_color = NULL; 209 static char_u *last_set_cursor_color = NULL;
214 static char_u *desired_cursor_color = NULL; 210 static char_u *desired_cursor_color = NULL;
2720 cursor_off(); 2716 cursor_off();
2721 } 2717 }
2722 } 2718 }
2723 2719
2724 /* 2720 /*
2725 * Cache "Terminal" highlight group colors.
2726 */
2727 void
2728 set_terminal_default_colors(int cterm_fg, int cterm_bg)
2729 {
2730 term_default_cterm_fg = cterm_fg - 1;
2731 term_default_cterm_bg = cterm_bg - 1;
2732 }
2733
2734 static int
2735 get_default_cterm_fg(term_T *term)
2736 {
2737 if (term->tl_highlight_name != NULL)
2738 {
2739 int id = syn_name2id(term->tl_highlight_name);
2740 int fg = -1;
2741 int bg = -1;
2742
2743 if (id > 0)
2744 syn_id2cterm_bg(id, &fg, &bg);
2745 return fg;
2746 }
2747 return term_default_cterm_fg;
2748 }
2749
2750 static int
2751 get_default_cterm_bg(term_T *term)
2752 {
2753 if (term->tl_highlight_name != NULL)
2754 {
2755 int id = syn_name2id(term->tl_highlight_name);
2756 int fg = -1;
2757 int bg = -1;
2758
2759 if (id > 0)
2760 syn_id2cterm_bg(id, &fg, &bg);
2761 return bg;
2762 }
2763 return term_default_cterm_bg;
2764 }
2765
2766 /*
2767 * Reverse engineer the RGB value into a cterm color index. 2721 * Reverse engineer the RGB value into a cterm color index.
2768 * First color is 1. Return 0 if no match found (default color). 2722 * First color is 1. Return 0 if no match found (default color).
2769 */ 2723 */
2770 static int 2724 static int
2771 color2index(VTermColor *color, int fg, int *boldp) 2725 color2index(VTermColor *color, int fg, int *boldp)
2907 else 2861 else
2908 #endif 2862 #endif
2909 #ifdef FEAT_TERMGUICOLORS 2863 #ifdef FEAT_TERMGUICOLORS
2910 if (p_tgc) 2864 if (p_tgc)
2911 { 2865 {
2912 guicolor_T fg, bg; 2866 guicolor_T fg = INVALCOLOR;
2913 2867 guicolor_T bg = INVALCOLOR;
2914 fg = gui_get_rgb_color_cmn(cellfg.red, cellfg.green, cellfg.blue); 2868
2915 bg = gui_get_rgb_color_cmn(cellbg.red, cellbg.green, cellbg.blue); 2869 // Use the 'wincolor' or "Terminal" highlighting for the default
2870 // colors.
2871 if (VTERM_COLOR_IS_DEFAULT_FG(&cellfg)
2872 || VTERM_COLOR_IS_DEFAULT_BG(&cellbg))
2873 {
2874 int id = 0;
2875
2876 if (wp != NULL && *wp->w_p_wcr != NUL)
2877 id = syn_name2id(wp->w_p_wcr);
2878 if (id == 0)
2879 id = syn_name2id(term_get_highlight_name(term));
2880 if (id > 0)
2881 syn_id2colors(id, &fg, &bg);
2882 if (!VTERM_COLOR_IS_DEFAULT_FG(&cellfg))
2883 fg = gui_get_rgb_color_cmn(cellfg.red, cellfg.green,
2884 cellfg.blue);
2885 if (!VTERM_COLOR_IS_DEFAULT_BG(&cellbg))
2886 bg = gui_get_rgb_color_cmn(cellbg.red, cellbg.green,
2887 cellbg.blue);
2888 }
2889 else
2890 {
2891 fg = gui_get_rgb_color_cmn(cellfg.red, cellfg.green, cellfg.blue);
2892 bg = gui_get_rgb_color_cmn(cellbg.red, cellbg.green, cellbg.blue);
2893 }
2916 2894
2917 return get_tgc_attr_idx(attr, fg, bg); 2895 return get_tgc_attr_idx(attr, fg, bg);
2918 } 2896 }
2919 else 2897 else
2920 #endif 2898 #endif
2925 2903
2926 // Use the 'wincolor' or "Terminal" highlighting for the default 2904 // Use the 'wincolor' or "Terminal" highlighting for the default
2927 // colors. 2905 // colors.
2928 if ((fg == 0 || bg == 0) && t_colors >= 16) 2906 if ((fg == 0 || bg == 0) && t_colors >= 16)
2929 { 2907 {
2930 int wincolor_fg = -1; 2908 int cterm_fg = -1;
2931 int wincolor_bg = -1; 2909 int cterm_bg = -1;
2910 int id = 0;
2932 2911
2933 if (wp != NULL && *wp->w_p_wcr != NUL) 2912 if (wp != NULL && *wp->w_p_wcr != NUL)
2934 { 2913 id = syn_name2id(wp->w_p_wcr);
2935 int id = syn_name2id(curwin->w_p_wcr); 2914 if (id == 0)
2936 2915 id = syn_name2id(term_get_highlight_name(term));
2937 // Get the 'wincolor' group colors. 2916 if (id > 0)
2938 if (id > 0) 2917 syn_id2cterm_bg(id, &cterm_fg, &cterm_bg);
2939 syn_id2cterm_bg(id, &wincolor_fg, &wincolor_bg); 2918 if (fg == 0 && cterm_fg >= 0)
2940 } 2919 fg = cterm_fg + 1;
2941 if (fg == 0) 2920 if (bg == 0 && cterm_bg >= 0)
2942 { 2921 bg = cterm_bg + 1;
2943 if (wincolor_fg >= 0)
2944 fg = wincolor_fg + 1;
2945 else
2946 {
2947 int cterm_fg = get_default_cterm_fg(term);
2948
2949 if (cterm_fg >= 0)
2950 fg = cterm_fg + 1;
2951 }
2952 }
2953 if (bg == 0)
2954 {
2955 if (wincolor_bg >= 0)
2956 bg = wincolor_bg + 1;
2957 else
2958 {
2959 int cterm_bg = get_default_cterm_bg(term);
2960
2961 if (cterm_bg >= 0)
2962 bg = cterm_bg + 1;
2963 }
2964 }
2965 } 2922 }
2966 2923
2967 // with 8 colors set the bold attribute to get a bright foreground 2924 // with 8 colors set the bold attribute to get a bright foreground
2968 if (bold == TRUE) 2925 if (bold == TRUE)
2969 attr |= HL_BOLD; 2926 attr |= HL_BOLD;
4039 } 3996 }
4040 else 3997 else
4041 #endif 3998 #endif
4042 if (id != 0 && t_colors >= 16) 3999 if (id != 0 && t_colors >= 16)
4043 { 4000 {
4044 int cterm_fg = get_default_cterm_fg(term); 4001 int cterm_fg = -1;
4045 int cterm_bg = get_default_cterm_bg(term); 4002 int cterm_bg = -1;
4003 syn_id2cterm_bg(id, &cterm_fg, &cterm_bg);
4046 4004
4047 if (cterm_fg >= 0) 4005 if (cterm_fg >= 0)
4048 cterm_color2vterm(cterm_fg, fg); 4006 cterm_color2vterm(cterm_fg, fg);
4049 if (cterm_bg >= 0) 4007 if (cterm_bg >= 0)
4050 cterm_color2vterm(cterm_bg, bg); 4008 cterm_color2vterm(cterm_bg, bg);