comparison src/libvterm/src/pen.c @ 12966:c5bccd50100e v8.0.1359

patch 8.0.1359: libvterm ANSI colors can not always be recognized commit https://github.com/vim/vim/commit/46359e198f6d6884dc3d3c4a3e46625f1b2a2ad2 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Nov 29 22:33:38 2017 +0100 patch 8.0.1359: libvterm ANSI colors can not always be recognized Problem: Libvterm ANSI colors can not always be recognized from the RGB values. The default color is wrong when t_RB is empty. Solution: Add the ANSI color index to VTermColor.
author Christian Brabandt <cb@256bit.org>
date Wed, 29 Nov 2017 22:45:05 +0100
parents fcb11cfca8b3
children 418941f0df08
comparison
equal deleted inserted replaced
12965:24c73ddf8b38 12966:c5bccd50100e
1 #include "vterm_internal.h" 1 #include "vterm_internal.h"
2 2
3 #include <stdio.h> 3 #include <stdio.h>
4 4
5 static const VTermColor ansi_colors[] = { 5 static const VTermColor ansi_colors[] = {
6 /* R G B */ 6 /* R G B index */
7 { 0, 0, 0 }, /* black */ 7 { 0, 0, 0, 1 }, /* black */
8 { 224, 0, 0 }, /* red */ 8 { 224, 0, 0, 2 }, /* red */
9 { 0, 224, 0 }, /* green */ 9 { 0, 224, 0, 3 }, /* green */
10 { 224, 224, 0 }, /* yellow */ 10 { 224, 224, 0, 4 }, /* yellow */
11 { 0, 0, 224 }, /* blue */ 11 { 0, 0, 224, 5 }, /* blue */
12 { 224, 0, 224 }, /* magenta */ 12 { 224, 0, 224, 6 }, /* magenta */
13 { 0, 224, 224 }, /* cyan */ 13 { 0, 224, 224, 7 }, /* cyan */
14 { 224, 224, 224 }, /* white == light grey */ 14 { 224, 224, 224, 8 }, /* white == light grey */
15 15
16 /* high intensity */ 16 /* high intensity */
17 { 128, 128, 128 }, /* black */ 17 { 128, 128, 128, 9 }, /* black */
18 { 255, 64, 64 }, /* red */ 18 { 255, 64, 64, 10 }, /* red */
19 { 64, 255, 64 }, /* green */ 19 { 64, 255, 64, 11 }, /* green */
20 { 255, 255, 64 }, /* yellow */ 20 { 255, 255, 64, 12 }, /* yellow */
21 { 64, 64, 255 }, /* blue */ 21 { 64, 64, 255, 13 }, /* blue */
22 { 255, 64, 255 }, /* magenta */ 22 { 255, 64, 255, 14 }, /* magenta */
23 { 64, 255, 255 }, /* cyan */ 23 { 64, 255, 255, 15 }, /* cyan */
24 { 255, 255, 255 }, /* white for real */ 24 { 255, 255, 255, 16 }, /* white for real */
25 }; 25 };
26 26
27 static int ramp6[] = { 27 static int ramp6[] = {
28 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF, 28 0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF,
29 }; 29 };
55 index -= 16; 55 index -= 16;
56 56
57 col->blue = ramp6[index % 6]; 57 col->blue = ramp6[index % 6];
58 col->green = ramp6[index/6 % 6]; 58 col->green = ramp6[index/6 % 6];
59 col->red = ramp6[index/6/6 % 6]; 59 col->red = ramp6[index/6/6 % 6];
60 col->ansi_index = VTERM_ANSI_INDEX_NONE;
60 61
61 return TRUE; 62 return TRUE;
62 } 63 }
63 else if(index >= 232 && index < 256) { 64 else if(index >= 232 && index < 256) {
64 /* 24 greyscales */ 65 /* 24 greyscales */
65 index -= 232; 66 index -= 232;
66 67
67 col->blue = ramp24[index]; 68 col->blue = ramp24[index];
68 col->green = ramp24[index]; 69 col->green = ramp24[index];
69 col->red = ramp24[index]; 70 col->red = ramp24[index];
71 col->ansi_index = VTERM_ANSI_INDEX_NONE;
70 72
71 return TRUE; 73 return TRUE;
72 } 74 }
73 75
74 return FALSE; 76 return FALSE;
82 return argcount; 84 return argcount;
83 85
84 col->red = (uint8_t)CSI_ARG(args[0]); 86 col->red = (uint8_t)CSI_ARG(args[0]);
85 col->green = (uint8_t)CSI_ARG(args[1]); 87 col->green = (uint8_t)CSI_ARG(args[1]);
86 col->blue = (uint8_t)CSI_ARG(args[2]); 88 col->blue = (uint8_t)CSI_ARG(args[2]);
89 col->ansi_index = VTERM_ANSI_INDEX_NONE;
87 90
88 return 3; 91 return 3;
89 92
90 case 5: /* XTerm 256-colour mode */ 93 case 5: /* XTerm 256-colour mode */
91 if(index) 94 if(index)
150 { 153 {
151 int col; 154 int col;
152 155
153 /* 90% grey so that pure white is brighter */ 156 /* 90% grey so that pure white is brighter */
154 state->default_fg.red = state->default_fg.green = state->default_fg.blue = 240; 157 state->default_fg.red = state->default_fg.green = state->default_fg.blue = 240;
158 state->default_fg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
155 state->default_bg.red = state->default_bg.green = state->default_bg.blue = 0; 159 state->default_bg.red = state->default_bg.green = state->default_bg.blue = 0;
160 state->default_bg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
156 161
157 for(col = 0; col < 16; col++) 162 for(col = 0; col < 16; col++)
158 state->colors[col] = ansi_colors[col]; 163 state->colors[col] = ansi_colors[col];
159 } 164 }
160 165
206 } 211 }
207 212
208 void vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg) 213 void vterm_state_set_default_colors(VTermState *state, const VTermColor *default_fg, const VTermColor *default_bg)
209 { 214 {
210 state->default_fg = *default_fg; 215 state->default_fg = *default_fg;
216 state->default_fg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
211 state->default_bg = *default_bg; 217 state->default_bg = *default_bg;
218 state->default_bg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
212 } 219 }
213 220
214 void vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col) 221 void vterm_state_set_palette_color(VTermState *state, int index, const VTermColor *col)
215 { 222 {
216 if(index >= 0 && index < 16) 223 if(index >= 0 && index < 16)
224 {
217 state->colors[index] = *col; 225 state->colors[index] = *col;
226 state->colors[index].ansi_index = index + VTERM_ANSI_INDEX_MIN;
227 }
218 } 228 }
219 229
220 void vterm_state_set_bold_highbright(VTermState *state, int bold_is_highbright) 230 void vterm_state_set_bold_highbright(VTermState *state, int bold_is_highbright)
221 { 231 {
222 state->bold_is_highbright = bold_is_highbright; 232 state->bold_is_highbright = bold_is_highbright;