Mercurial > vim
comparison src/terminal.c @ 13823:d0d8125ba692 v8.0.1783
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
commit https://github.com/vim/vim/commit/c5cd88554f1e0b2e9ff08d9a0748238dd8340ce1
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 1 15:47:38 2018 +0200
patch 8.0.1783: cannot use 256 colors in a MS-Windows console
Problem: Cannot use 256 colors in a MS-Windows console.
Solution: Add 256 color support. (Nobuhiro Takasaki, closes https://github.com/vim/vim/issues/2821)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 01 May 2018 16:00:07 +0200 |
parents | 3ab6198c1f9a |
children | 044337cbf854 |
comparison
equal
deleted
inserted
replaced
13822:46912abff012 | 13823:d0d8125ba692 |
---|---|
41 * - Win32: Make terminal used for :!cmd in the GUI work better. Allow for | 41 * - Win32: Make terminal used for :!cmd in the GUI work better. Allow for |
42 * redirection. Probably in call to channel_set_pipes(). | 42 * redirection. Probably in call to channel_set_pipes(). |
43 * - Win32: Redirecting output does not work, Test_terminal_redir_file() | 43 * - Win32: Redirecting output does not work, Test_terminal_redir_file() |
44 * is disabled. | 44 * is disabled. |
45 * - Add test for 'termwinkey'. | 45 * - Add test for 'termwinkey'. |
46 * - libvterm: bringg back using // comments and trailing comma in enum | |
47 * - When starting terminal window with shell in terminal, then using :gui to | 46 * - When starting terminal window with shell in terminal, then using :gui to |
48 * switch to GUI, shell stops working. Scrollback seems wrong, command | 47 * switch to GUI, shell stops working. Scrollback seems wrong, command |
49 * running in shell is still running. | 48 * running in shell is still running. |
50 * - GUI: when using tabs, focus in terminal, click on tab does not work. | 49 * - GUI: when using tabs, focus in terminal, click on tab does not work. |
51 * - handle_moverect() scrolls one line at a time. Postpone scrolling, count | 50 * - handle_moverect() scrolls one line at a time. Postpone scrolling, count |
3014 cellattr = line->sb_cells + col; | 3013 cellattr = line->sb_cells + col; |
3015 } | 3014 } |
3016 return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg); | 3015 return cell2attr(cellattr->attrs, cellattr->fg, cellattr->bg); |
3017 } | 3016 } |
3018 | 3017 |
3019 static VTermColor ansi_table[16] = { | |
3020 { 0, 0, 0, 1}, /* black */ | |
3021 {224, 0, 0, 2}, /* dark red */ | |
3022 { 0, 224, 0, 3}, /* dark green */ | |
3023 {224, 224, 0, 4}, /* dark yellow / brown */ | |
3024 { 0, 0, 224, 5}, /* dark blue */ | |
3025 {224, 0, 224, 6}, /* dark magenta */ | |
3026 { 0, 224, 224, 7}, /* dark cyan */ | |
3027 {224, 224, 224, 8}, /* light grey */ | |
3028 | |
3029 {128, 128, 128, 9}, /* dark grey */ | |
3030 {255, 64, 64, 10}, /* light red */ | |
3031 { 64, 255, 64, 11}, /* light green */ | |
3032 {255, 255, 64, 12}, /* yellow */ | |
3033 { 64, 64, 255, 13}, /* light blue */ | |
3034 {255, 64, 255, 14}, /* light magenta */ | |
3035 { 64, 255, 255, 15}, /* light cyan */ | |
3036 {255, 255, 255, 16}, /* white */ | |
3037 }; | |
3038 | |
3039 static int cube_value[] = { | |
3040 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF | |
3041 }; | |
3042 | |
3043 static int grey_ramp[] = { | |
3044 0x08, 0x12, 0x1C, 0x26, 0x30, 0x3A, 0x44, 0x4E, 0x58, 0x62, 0x6C, 0x76, | |
3045 0x80, 0x8A, 0x94, 0x9E, 0xA8, 0xB2, 0xBC, 0xC6, 0xD0, 0xDA, 0xE4, 0xEE | |
3046 }; | |
3047 | |
3048 /* | 3018 /* |
3049 * Convert a cterm color number 0 - 255 to RGB. | 3019 * Convert a cterm color number 0 - 255 to RGB. |
3050 * This is compatible with xterm. | 3020 * This is compatible with xterm. |
3051 */ | 3021 */ |
3052 static void | 3022 static void |
3053 cterm_color2rgb(int nr, VTermColor *rgb) | 3023 cterm_color2vterm(int nr, VTermColor *rgb) |
3054 { | 3024 { |
3055 int idx; | 3025 cterm_color2rgb(nr, &rgb->red, &rgb->green, &rgb->blue, &rgb->ansi_index); |
3056 | |
3057 if (nr < 16) | |
3058 { | |
3059 *rgb = ansi_table[nr]; | |
3060 } | |
3061 else if (nr < 232) | |
3062 { | |
3063 /* 216 color cube */ | |
3064 idx = nr - 16; | |
3065 rgb->blue = cube_value[idx % 6]; | |
3066 rgb->green = cube_value[idx / 6 % 6]; | |
3067 rgb->red = cube_value[idx / 36 % 6]; | |
3068 rgb->ansi_index = VTERM_ANSI_INDEX_NONE; | |
3069 } | |
3070 else if (nr < 256) | |
3071 { | |
3072 /* 24 grey scale ramp */ | |
3073 idx = nr - 232; | |
3074 rgb->blue = grey_ramp[idx]; | |
3075 rgb->green = grey_ramp[idx]; | |
3076 rgb->red = grey_ramp[idx]; | |
3077 rgb->ansi_index = VTERM_ANSI_INDEX_NONE; | |
3078 } | |
3079 } | 3026 } |
3080 | 3027 |
3081 /* | 3028 /* |
3082 * Initialize term->tl_default_color from the environment. | 3029 * Initialize term->tl_default_color from the environment. |
3083 */ | 3030 */ |
3118 # ifdef FEAT_GUI | 3065 # ifdef FEAT_GUI |
3119 || gui.in_use | 3066 || gui.in_use |
3120 # endif | 3067 # endif |
3121 # ifdef FEAT_TERMGUICOLORS | 3068 # ifdef FEAT_TERMGUICOLORS |
3122 || p_tgc | 3069 || p_tgc |
3070 # ifdef FEAT_VTP | |
3071 /* Finally get INVALCOLOR on this execution path */ | |
3072 || (!p_tgc && t_colors >= 256) | |
3073 # endif | |
3123 # endif | 3074 # endif |
3124 ) | 3075 ) |
3125 { | 3076 { |
3126 guicolor_T fg_rgb = INVALCOLOR; | 3077 guicolor_T fg_rgb = INVALCOLOR; |
3127 guicolor_T bg_rgb = INVALCOLOR; | 3078 guicolor_T bg_rgb = INVALCOLOR; |
3169 else | 3120 else |
3170 #endif | 3121 #endif |
3171 if (id != 0 && t_colors >= 16) | 3122 if (id != 0 && t_colors >= 16) |
3172 { | 3123 { |
3173 if (term_default_cterm_fg >= 0) | 3124 if (term_default_cterm_fg >= 0) |
3174 cterm_color2rgb(term_default_cterm_fg, fg); | 3125 cterm_color2vterm(term_default_cterm_fg, fg); |
3175 if (term_default_cterm_bg >= 0) | 3126 if (term_default_cterm_bg >= 0) |
3176 cterm_color2rgb(term_default_cterm_bg, bg); | 3127 cterm_color2vterm(term_default_cterm_bg, bg); |
3177 } | 3128 } |
3178 else | 3129 else |
3179 { | 3130 { |
3180 #if defined(WIN3264) && !defined(FEAT_GUI_W32) | 3131 #if defined(WIN3264) && !defined(FEAT_GUI_W32) |
3181 int tmp; | 3132 int tmp; |
3182 #endif | 3133 #endif |
3183 | 3134 |
3184 /* In an MS-Windows console we know the normal colors. */ | 3135 /* In an MS-Windows console we know the normal colors. */ |
3185 if (cterm_normal_fg_color > 0) | 3136 if (cterm_normal_fg_color > 0) |
3186 { | 3137 { |
3187 cterm_color2rgb(cterm_normal_fg_color - 1, fg); | 3138 cterm_color2vterm(cterm_normal_fg_color - 1, fg); |
3188 # if defined(WIN3264) && !defined(FEAT_GUI_W32) | 3139 # if defined(WIN3264) && !defined(FEAT_GUI_W32) |
3189 tmp = fg->red; | 3140 tmp = fg->red; |
3190 fg->red = fg->blue; | 3141 fg->red = fg->blue; |
3191 fg->blue = tmp; | 3142 fg->blue = tmp; |
3192 # endif | 3143 # endif |
3196 term_get_fg_color(&fg->red, &fg->green, &fg->blue); | 3147 term_get_fg_color(&fg->red, &fg->green, &fg->blue); |
3197 # endif | 3148 # endif |
3198 | 3149 |
3199 if (cterm_normal_bg_color > 0) | 3150 if (cterm_normal_bg_color > 0) |
3200 { | 3151 { |
3201 cterm_color2rgb(cterm_normal_bg_color - 1, bg); | 3152 cterm_color2vterm(cterm_normal_bg_color - 1, bg); |
3202 # if defined(WIN3264) && !defined(FEAT_GUI_W32) | 3153 # if defined(WIN3264) && !defined(FEAT_GUI_W32) |
3203 tmp = bg->red; | 3154 tmp = bg->red; |
3204 bg->red = bg->blue; | 3155 bg->red = bg->blue; |
3205 bg->blue = tmp; | 3156 bg->blue = tmp; |
3206 # endif | 3157 # endif |