comparison src/libvterm/src/pen.c @ 13770:2449b6ce1456 v8.0.1757

patch 8.0.1757: unnecessary changes in libvterm commit https://github.com/vim/vim/commit/b691de05f69905fe417f583083d7e3cc16eb865e Author: Bram Moolenaar <Bram@vim.org> Date: Tue Apr 24 18:39:14 2018 +0200 patch 8.0.1757: unnecessary changes in libvterm Problem: Unnecessary changes in libvterm. Solution: Bring back // comments and trailing comma in enums.
author Christian Brabandt <cb@256bit.org>
date Tue, 24 Apr 2018 18:45:07 +0200
parents 9f857e6310b6
children cd5c83115ec6
comparison
equal deleted inserted replaced
13769:804c3b21ce59 13770:2449b6ce1456
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 index */ 6 /* R G B index */
7 { 0, 0, 0, 1 }, /* black */ 7 { 0, 0, 0, 1 }, // black
8 { 224, 0, 0, 2 }, /* red */ 8 { 224, 0, 0, 2 }, // red
9 { 0, 224, 0, 3 }, /* green */ 9 { 0, 224, 0, 3 }, // green
10 { 224, 224, 0, 4 }, /* yellow */ 10 { 224, 224, 0, 4 }, // yellow
11 { 0, 0, 224, 5 }, /* blue */ 11 { 0, 0, 224, 5 }, // blue
12 { 224, 0, 224, 6 }, /* magenta */ 12 { 224, 0, 224, 6 }, // magenta
13 { 0, 224, 224, 7 }, /* cyan */ 13 { 0, 224, 224, 7 }, // cyan
14 { 224, 224, 224, 8 }, /* white == light grey */ 14 { 224, 224, 224, 8 }, // white == light grey
15 15
16 /* high intensity */ 16 // high intensity
17 { 128, 128, 128, 9 }, /* black */ 17 { 128, 128, 128, 9 }, // black
18 { 255, 64, 64, 10 }, /* red */ 18 { 255, 64, 64, 10 }, // red
19 { 64, 255, 64, 11 }, /* green */ 19 { 64, 255, 64, 11 }, // green
20 { 255, 255, 64, 12 }, /* yellow */ 20 { 255, 255, 64, 12 }, // yellow
21 { 64, 64, 255, 13 }, /* blue */ 21 { 64, 64, 255, 13 }, // blue
22 { 255, 64, 255, 14 }, /* magenta */ 22 { 255, 64, 255, 14 }, // magenta
23 { 64, 255, 255, 15 }, /* cyan */ 23 { 64, 255, 255, 15 }, // cyan
24 { 255, 255, 255, 16 }, /* 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 };
45 } 45 }
46 46
47 static int lookup_colour_palette(const VTermState *state, long index, VTermColor *col) 47 static int lookup_colour_palette(const VTermState *state, long index, VTermColor *col)
48 { 48 {
49 if(index >= 0 && index < 16) { 49 if(index >= 0 && index < 16) {
50 /* Normal 8 colours or high intensity - parse as palette 0 */ 50 // Normal 8 colours or high intensity - parse as palette 0
51 return lookup_colour_ansi(state, index, col); 51 return lookup_colour_ansi(state, index, col);
52 } 52 }
53 else if(index >= 16 && index < 232) { 53 else if(index >= 16 && index < 232) {
54 /* 216-colour cube */ 54 // 216-colour cube
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 col->ansi_index = VTERM_ANSI_INDEX_NONE;
61 61
62 return TRUE; 62 return TRUE;
63 } 63 }
64 else if(index >= 232 && index < 256) { 64 else if(index >= 232 && index < 256) {
65 /* 24 greyscales */ 65 // 24 greyscales
66 index -= 232; 66 index -= 232;
67 67
68 col->blue = ramp24[index]; 68 col->blue = ramp24[index];
69 col->green = ramp24[index]; 69 col->green = ramp24[index];
70 col->red = ramp24[index]; 70 col->red = ramp24[index];
77 } 77 }
78 78
79 static int lookup_colour(const VTermState *state, int palette, const long args[], int argcount, VTermColor *col, int *index) 79 static int lookup_colour(const VTermState *state, int palette, const long args[], int argcount, VTermColor *col, int *index)
80 { 80 {
81 switch(palette) { 81 switch(palette) {
82 case 2: /* RGB mode - 3 args contain colour values directly */ 82 case 2: // RGB mode - 3 args contain colour values directly
83 if(argcount < 3) 83 if(argcount < 3)
84 return argcount; 84 return argcount;
85 85
86 col->red = (uint8_t)CSI_ARG(args[0]); 86 col->red = (uint8_t)CSI_ARG(args[0]);
87 col->green = (uint8_t)CSI_ARG(args[1]); 87 col->green = (uint8_t)CSI_ARG(args[1]);
88 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; 89 col->ansi_index = VTERM_ANSI_INDEX_NONE;
90 90
91 return 3; 91 return 3;
92 92
93 case 5: /* XTerm 256-colour mode */ 93 case 5: // XTerm 256-colour mode
94 if(index) 94 if(index)
95 *index = CSI_ARG_OR(args[0], -1); 95 *index = CSI_ARG_OR(args[0], -1);
96 96
97 lookup_colour_palette(state, argcount ? CSI_ARG_OR(args[0], -1) : -1, col); 97 lookup_colour_palette(state, argcount ? CSI_ARG_OR(args[0], -1) : -1, col);
98 98
102 DEBUG_LOG1("Unrecognised colour palette %d\n", palette); 102 DEBUG_LOG1("Unrecognised colour palette %d\n", palette);
103 return 0; 103 return 0;
104 } 104 }
105 } 105 }
106 106
107 /* Some conveniences */ 107 // Some conveniences
108 108
109 static void setpenattr(VTermState *state, VTermAttr attr, VTermValueType type UNUSED, VTermValue *val) 109 static void setpenattr(VTermState *state, VTermAttr attr, VTermValueType type UNUSED, VTermValue *val)
110 { 110 {
111 #ifdef DEBUG 111 #ifdef DEBUG
112 if(type != vterm_get_attr_type(attr)) { 112 if(type != vterm_get_attr_type(attr)) {
151 151
152 INTERNAL void vterm_state_newpen(VTermState *state) 152 INTERNAL void vterm_state_newpen(VTermState *state)
153 { 153 {
154 int col; 154 int col;
155 155
156 /* 90% grey so that pure white is brighter */ 156 // 90% grey so that pure white is brighter
157 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; 158 state->default_fg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
159 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; 160 state->default_bg.ansi_index = VTERM_ANSI_INDEX_DEFAULT;
161 161
230 state->bold_is_highbright = bold_is_highbright; 230 state->bold_is_highbright = bold_is_highbright;
231 } 231 }
232 232
233 INTERNAL void vterm_state_setpen(VTermState *state, const long args[], int argcount) 233 INTERNAL void vterm_state_setpen(VTermState *state, const long args[], int argcount)
234 { 234 {
235 /* SGR - ECMA-48 8.3.117 */ 235 // SGR - ECMA-48 8.3.117
236 236
237 int argi = 0; 237 int argi = 0;
238 int value; 238 int value;
239 239
240 while(argi < argcount) { 240 while(argi < argcount) {
241 /* This logic is easier to do 'done' backwards; set it true, and make it 241 // This logic is easier to do 'done' backwards; set it true, and make it
242 false again in the 'default' case */ 242 // false again in the 'default' case
243 int done = 1; 243 int done = 1;
244 244
245 long arg; 245 long arg;
246 switch(arg = CSI_ARG(args[argi])) { 246 switch(arg = CSI_ARG(args[argi])) {
247 case CSI_ARG_MISSING: 247 case CSI_ARG_MISSING:
248 case 0: /* Reset */ 248 case 0: // Reset
249 vterm_state_resetpen(state); 249 vterm_state_resetpen(state);
250 break; 250 break;
251 251
252 case 1: /* Bold on */ 252 case 1: // Bold on
253 state->pen.bold = 1; 253 state->pen.bold = 1;
254 setpenattr_bool(state, VTERM_ATTR_BOLD, 1); 254 setpenattr_bool(state, VTERM_ATTR_BOLD, 1);
255 if(state->fg_index > -1 && state->fg_index < 8 && state->bold_is_highbright) 255 if(state->fg_index > -1 && state->fg_index < 8 && state->bold_is_highbright)
256 set_pen_col_ansi(state, VTERM_ATTR_FOREGROUND, state->fg_index + (state->pen.bold ? 8 : 0)); 256 set_pen_col_ansi(state, VTERM_ATTR_FOREGROUND, state->fg_index + (state->pen.bold ? 8 : 0));
257 break; 257 break;
258 258
259 case 3: /* Italic on */ 259 case 3: // Italic on
260 state->pen.italic = 1; 260 state->pen.italic = 1;
261 setpenattr_bool(state, VTERM_ATTR_ITALIC, 1); 261 setpenattr_bool(state, VTERM_ATTR_ITALIC, 1);
262 break; 262 break;
263 263
264 case 4: /* Underline single */ 264 case 4: // Underline single
265 state->pen.underline = 1; 265 state->pen.underline = 1;
266 setpenattr_int(state, VTERM_ATTR_UNDERLINE, 1); 266 setpenattr_int(state, VTERM_ATTR_UNDERLINE, 1);
267 break; 267 break;
268 268
269 case 5: /* Blink */ 269 case 5: // Blink
270 state->pen.blink = 1; 270 state->pen.blink = 1;
271 setpenattr_bool(state, VTERM_ATTR_BLINK, 1); 271 setpenattr_bool(state, VTERM_ATTR_BLINK, 1);
272 break; 272 break;
273 273
274 case 7: /* Reverse on */ 274 case 7: // Reverse on
275 state->pen.reverse = 1; 275 state->pen.reverse = 1;
276 setpenattr_bool(state, VTERM_ATTR_REVERSE, 1); 276 setpenattr_bool(state, VTERM_ATTR_REVERSE, 1);
277 break; 277 break;
278 278
279 case 9: /* Strikethrough on */ 279 case 9: // Strikethrough on
280 state->pen.strike = 1; 280 state->pen.strike = 1;
281 setpenattr_bool(state, VTERM_ATTR_STRIKE, 1); 281 setpenattr_bool(state, VTERM_ATTR_STRIKE, 1);
282 break; 282 break;
283 283
284 case 10: case 11: case 12: case 13: case 14: 284 case 10: case 11: case 12: case 13: case 14:
285 case 15: case 16: case 17: case 18: case 19: /* Select font */ 285 case 15: case 16: case 17: case 18: case 19: // Select font
286 state->pen.font = CSI_ARG(args[argi]) - 10; 286 state->pen.font = CSI_ARG(args[argi]) - 10;
287 setpenattr_int(state, VTERM_ATTR_FONT, state->pen.font); 287 setpenattr_int(state, VTERM_ATTR_FONT, state->pen.font);
288 break; 288 break;
289 289
290 case 21: /* Underline double */ 290 case 21: // Underline double
291 state->pen.underline = 2; 291 state->pen.underline = 2;
292 setpenattr_int(state, VTERM_ATTR_UNDERLINE, 2); 292 setpenattr_int(state, VTERM_ATTR_UNDERLINE, 2);
293 break; 293 break;
294 294
295 case 22: /* Bold off */ 295 case 22: // Bold off
296 state->pen.bold = 0; 296 state->pen.bold = 0;
297 setpenattr_bool(state, VTERM_ATTR_BOLD, 0); 297 setpenattr_bool(state, VTERM_ATTR_BOLD, 0);
298 break; 298 break;
299 299
300 case 23: /* Italic and Gothic (currently unsupported) off */ 300 case 23: // Italic and Gothic (currently unsupported) off
301 state->pen.italic = 0; 301 state->pen.italic = 0;
302 setpenattr_bool(state, VTERM_ATTR_ITALIC, 0); 302 setpenattr_bool(state, VTERM_ATTR_ITALIC, 0);
303 break; 303 break;
304 304
305 case 24: /* Underline off */ 305 case 24: // Underline off
306 state->pen.underline = 0; 306 state->pen.underline = 0;
307 setpenattr_int(state, VTERM_ATTR_UNDERLINE, 0); 307 setpenattr_int(state, VTERM_ATTR_UNDERLINE, 0);
308 break; 308 break;
309 309
310 case 25: /* Blink off */ 310 case 25: // Blink off
311 state->pen.blink = 0; 311 state->pen.blink = 0;
312 setpenattr_bool(state, VTERM_ATTR_BLINK, 0); 312 setpenattr_bool(state, VTERM_ATTR_BLINK, 0);
313 break; 313 break;
314 314
315 case 27: /* Reverse off */ 315 case 27: // Reverse off
316 state->pen.reverse = 0; 316 state->pen.reverse = 0;
317 setpenattr_bool(state, VTERM_ATTR_REVERSE, 0); 317 setpenattr_bool(state, VTERM_ATTR_REVERSE, 0);
318 break; 318 break;
319 319
320 case 29: /* Strikethrough off */ 320 case 29: // Strikethrough off
321 state->pen.strike = 0; 321 state->pen.strike = 0;
322 setpenattr_bool(state, VTERM_ATTR_STRIKE, 0); 322 setpenattr_bool(state, VTERM_ATTR_STRIKE, 0);
323 break; 323 break;
324 324
325 case 30: case 31: case 32: case 33: 325 case 30: case 31: case 32: case 33:
326 case 34: case 35: case 36: case 37: /* Foreground colour palette */ 326 case 34: case 35: case 36: case 37: // Foreground colour palette
327 value = CSI_ARG(args[argi]) - 30; 327 value = CSI_ARG(args[argi]) - 30;
328 state->fg_index = value; 328 state->fg_index = value;
329 if(state->pen.bold && state->bold_is_highbright) 329 if(state->pen.bold && state->bold_is_highbright)
330 value += 8; 330 value += 8;
331 set_pen_col_ansi(state, VTERM_ATTR_FOREGROUND, value); 331 set_pen_col_ansi(state, VTERM_ATTR_FOREGROUND, value);
332 break; 332 break;
333 333
334 case 38: /* Foreground colour alternative palette */ 334 case 38: // Foreground colour alternative palette
335 state->fg_index = -1; 335 state->fg_index = -1;
336 if(argcount - argi < 1) 336 if(argcount - argi < 1)
337 return; 337 return;
338 argi += 1 + lookup_colour(state, CSI_ARG(args[argi+1]), args+argi+2, argcount-argi-2, &state->pen.fg, &state->fg_index); 338 argi += 1 + lookup_colour(state, CSI_ARG(args[argi+1]), args+argi+2, argcount-argi-2, &state->pen.fg, &state->fg_index);
339 setpenattr_col(state, VTERM_ATTR_FOREGROUND, state->pen.fg); 339 setpenattr_col(state, VTERM_ATTR_FOREGROUND, state->pen.fg);
340 break; 340 break;
341 341
342 case 39: /* Foreground colour default */ 342 case 39: // Foreground colour default
343 state->fg_index = -1; 343 state->fg_index = -1;
344 state->pen.fg = state->default_fg; 344 state->pen.fg = state->default_fg;
345 setpenattr_col(state, VTERM_ATTR_FOREGROUND, state->pen.fg); 345 setpenattr_col(state, VTERM_ATTR_FOREGROUND, state->pen.fg);
346 break; 346 break;
347 347
348 case 40: case 41: case 42: case 43: 348 case 40: case 41: case 42: case 43:
349 case 44: case 45: case 46: case 47: /* Background colour palette */ 349 case 44: case 45: case 46: case 47: // Background colour palette
350 value = CSI_ARG(args[argi]) - 40; 350 value = CSI_ARG(args[argi]) - 40;
351 state->bg_index = value; 351 state->bg_index = value;
352 set_pen_col_ansi(state, VTERM_ATTR_BACKGROUND, value); 352 set_pen_col_ansi(state, VTERM_ATTR_BACKGROUND, value);
353 break; 353 break;
354 354
355 case 48: /* Background colour alternative palette */ 355 case 48: // Background colour alternative palette
356 state->bg_index = -1; 356 state->bg_index = -1;
357 if(argcount - argi < 1) 357 if(argcount - argi < 1)
358 return; 358 return;
359 argi += 1 + lookup_colour(state, CSI_ARG(args[argi+1]), args+argi+2, argcount-argi-2, &state->pen.bg, &state->bg_index); 359 argi += 1 + lookup_colour(state, CSI_ARG(args[argi+1]), args+argi+2, argcount-argi-2, &state->pen.bg, &state->bg_index);
360 setpenattr_col(state, VTERM_ATTR_BACKGROUND, state->pen.bg); 360 setpenattr_col(state, VTERM_ATTR_BACKGROUND, state->pen.bg);
361 break; 361 break;
362 362
363 case 49: /* Default background */ 363 case 49: // Default background
364 state->bg_index = -1; 364 state->bg_index = -1;
365 state->pen.bg = state->default_bg; 365 state->pen.bg = state->default_bg;
366 setpenattr_col(state, VTERM_ATTR_BACKGROUND, state->pen.bg); 366 setpenattr_col(state, VTERM_ATTR_BACKGROUND, state->pen.bg);
367 break; 367 break;
368 368
369 case 90: case 91: case 92: case 93: 369 case 90: case 91: case 92: case 93:
370 case 94: case 95: case 96: case 97: /* Foreground colour high-intensity palette */ 370 case 94: case 95: case 96: case 97: // Foreground colour high-intensity palette
371 value = CSI_ARG(args[argi]) - 90 + 8; 371 value = CSI_ARG(args[argi]) - 90 + 8;
372 state->fg_index = value; 372 state->fg_index = value;
373 set_pen_col_ansi(state, VTERM_ATTR_FOREGROUND, value); 373 set_pen_col_ansi(state, VTERM_ATTR_FOREGROUND, value);
374 break; 374 break;
375 375
376 case 100: case 101: case 102: case 103: 376 case 100: case 101: case 102: case 103:
377 case 104: case 105: case 106: case 107: /* Background colour high-intensity palette */ 377 case 104: case 105: case 106: case 107: // Background colour high-intensity palette
378 value = CSI_ARG(args[argi]) - 100 + 8; 378 value = CSI_ARG(args[argi]) - 100 + 8;
379 state->bg_index = value; 379 state->bg_index = value;
380 set_pen_col_ansi(state, VTERM_ATTR_BACKGROUND, value); 380 set_pen_col_ansi(state, VTERM_ATTR_BACKGROUND, value);
381 break; 381 break;
382 382
430 args[argi++] = CSI_ARG_FLAG_MORE|38; 430 args[argi++] = CSI_ARG_FLAG_MORE|38;
431 args[argi++] = CSI_ARG_FLAG_MORE|5; 431 args[argi++] = CSI_ARG_FLAG_MORE|5;
432 args[argi++] = state->fg_index; 432 args[argi++] = state->fg_index;
433 } 433 }
434 else if(state->fg_index == -1) { 434 else if(state->fg_index == -1) {
435 /* Send palette 2 if the actual FG colour is not default */ 435 // Send palette 2 if the actual FG colour is not default
436 if(state->pen.fg.red != state->default_fg.red || 436 if(state->pen.fg.red != state->default_fg.red ||
437 state->pen.fg.green != state->default_fg.green || 437 state->pen.fg.green != state->default_fg.green ||
438 state->pen.fg.blue != state->default_fg.blue ) { 438 state->pen.fg.blue != state->default_fg.blue ) {
439 args[argi++] = CSI_ARG_FLAG_MORE|38; 439 args[argi++] = CSI_ARG_FLAG_MORE|38;
440 args[argi++] = CSI_ARG_FLAG_MORE|2; 440 args[argi++] = CSI_ARG_FLAG_MORE|2;
452 args[argi++] = CSI_ARG_FLAG_MORE|48; 452 args[argi++] = CSI_ARG_FLAG_MORE|48;
453 args[argi++] = CSI_ARG_FLAG_MORE|5; 453 args[argi++] = CSI_ARG_FLAG_MORE|5;
454 args[argi++] = state->bg_index; 454 args[argi++] = state->bg_index;
455 } 455 }
456 else if(state->bg_index == -1) { 456 else if(state->bg_index == -1) {
457 /* Send palette 2 if the actual BG colour is not default */ 457 // Send palette 2 if the actual BG colour is not default
458 if(state->pen.bg.red != state->default_bg.red || 458 if(state->pen.bg.red != state->default_bg.red ||
459 state->pen.bg.green != state->default_bg.green || 459 state->pen.bg.green != state->default_bg.green ||
460 state->pen.bg.blue != state->default_bg.blue ) { 460 state->pen.bg.blue != state->default_bg.blue ) {
461 args[argi++] = CSI_ARG_FLAG_MORE|48; 461 args[argi++] = CSI_ARG_FLAG_MORE|48;
462 args[argi++] = CSI_ARG_FLAG_MORE|2; 462 args[argi++] = CSI_ARG_FLAG_MORE|2;