Skip to content

Commit 12d853f

Browse files
committed
patch 8.0.0831: with 8 colors the bold attribute is not set properly
Problem: With 8 colors the bold attribute is not set properly. Solution: Move setting HL_TABLE() out of lookup_color. (closes #1901)
1 parent aaef1ba commit 12d853f

4 files changed

Lines changed: 51 additions & 28 deletions

File tree

src/proto/syntax.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void ex_syntime(exarg_T *eap);
2323
char_u *get_syntime_arg(expand_T *xp, int idx);
2424
void init_highlight(int both, int reset);
2525
int load_colors(char_u *name);
26-
int lookup_color(int idx, int foreground);
26+
int lookup_color(int idx, int foreground, int *boldp);
2727
void do_highlight(char_u *line, int forceit, int init);
2828
void free_highlight(void);
2929
void restore_cterm_colors(void);

src/syntax.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7276,9 +7276,11 @@ static int color_numbers_8[28] = {0, 4, 2, 6,
72767276
/*
72777277
* Lookup the "cterm" value to be used for color with index "idx" in
72787278
* color_names[].
7279+
* "boldp" will be set to TRUE or FALSE for a foreground color when using 8
7280+
* colors, otherwise it will be unchanged.
72797281
*/
72807282
int
7281-
lookup_color(int idx, int foreground)
7283+
lookup_color(int idx, int foreground, int *boldp)
72827284
{
72837285
int color = color_numbers_16[idx];
72847286
char_u *p;
@@ -7300,12 +7302,9 @@ lookup_color(int idx, int foreground)
73007302
/* set/reset bold attribute to get light foreground
73017303
* colors (on some terminals, e.g. "linux") */
73027304
if (color & 8)
7303-
{
7304-
HL_TABLE()[idx].sg_cterm |= HL_BOLD;
7305-
HL_TABLE()[idx].sg_cterm_bold = TRUE;
7306-
}
7305+
*boldp = TRUE;
73077306
else
7308-
HL_TABLE()[idx].sg_cterm &= ~HL_BOLD;
7307+
*boldp = FALSE;
73097308
}
73107309
color &= 7; /* truncate to 8 colors */
73117310
}
@@ -7837,6 +7836,8 @@ do_highlight(
78377836
}
78387837
else
78397838
{
7839+
int bold = MAYBE;
7840+
78407841
#if defined(__QNXNTO__)
78417842
static int *color_numbers_8_qansi = color_numbers_8;
78427843
/* On qnx, the 8 & 16 color arrays are the same */
@@ -7857,7 +7858,17 @@ do_highlight(
78577858
break;
78587859
}
78597860

7860-
color = lookup_color(i, key[5] == 'F');
7861+
color = lookup_color(i, key[5] == 'F', &bold);
7862+
7863+
/* set/reset bold attribute to get light foreground
7864+
* colors (on some terminals, e.g. "linux") */
7865+
if (bold == TRUE)
7866+
{
7867+
HL_TABLE()[idx].sg_cterm |= HL_BOLD;
7868+
HL_TABLE()[idx].sg_cterm_bold = TRUE;
7869+
}
7870+
else if (bold == FALSE)
7871+
HL_TABLE()[idx].sg_cterm &= ~HL_BOLD;
78617872
}
78627873

78637874
/* Add one to the argument, to avoid zero. Zero is used for

src/terminal.c

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
* that buffer, attributes come from the scrollback buffer tl_scrollback.
3737
*
3838
* TODO:
39-
* - Use "." for current line instead of optional.
39+
* - Use "." for current line instead of optional argument.
4040
* - make row and cols one-based instead of zero-based in term_ functions.
4141
* - Add StatusLineTerm highlighting
4242
* - in bash mouse clicks are inserting characters.
@@ -56,6 +56,8 @@
5656
* - do not store terminal window in viminfo. Or prefix term:// ?
5757
* - add a character in :ls output
5858
* - add 't' to mode()
59+
* - When making a change after the job has ended, make the buffer a normal
60+
* buffer; needs to be written.
5961
* - when closing window and job has not ended, make terminal hidden?
6062
* - when closing window and job has ended, make buffer hidden?
6163
* - don't allow exiting Vim when a terminal is still running a job
@@ -71,6 +73,8 @@
7173
* conversions.
7274
* - update ":help function-list" for terminal functions.
7375
* - In the GUI use a terminal emulator for :!cmd.
76+
* - Copy text in the vterm to the Vim buffer once in a while, so that
77+
* completion works.
7478
*/
7579

7680
#include "vim.h"
@@ -1253,7 +1257,7 @@ term_channel_closed(channel_T *ch)
12531257
* First color is 1. Return 0 if no match found.
12541258
*/
12551259
static int
1256-
color2index(VTermColor *color, int foreground)
1260+
color2index(VTermColor *color, int fg, int *boldp)
12571261
{
12581262
int red = color->red;
12591263
int blue = color->blue;
@@ -1265,70 +1269,70 @@ color2index(VTermColor *color, int foreground)
12651269
if (green == 0)
12661270
{
12671271
if (blue == 0)
1268-
return lookup_color(0, foreground) + 1; /* black */
1272+
return lookup_color(0, fg, boldp) + 1; /* black */
12691273
if (blue == 224)
1270-
return lookup_color(1, foreground) + 1; /* dark blue */
1274+
return lookup_color(1, fg, boldp) + 1; /* dark blue */
12711275
}
12721276
else if (green == 224)
12731277
{
12741278
if (blue == 0)
1275-
return lookup_color(2, foreground) + 1; /* dark green */
1279+
return lookup_color(2, fg, boldp) + 1; /* dark green */
12761280
if (blue == 224)
1277-
return lookup_color(3, foreground) + 1; /* dark cyan */
1281+
return lookup_color(3, fg, boldp) + 1; /* dark cyan */
12781282
}
12791283
}
12801284
else if (red == 224)
12811285
{
12821286
if (green == 0)
12831287
{
12841288
if (blue == 0)
1285-
return lookup_color(4, foreground) + 1; /* dark red */
1289+
return lookup_color(4, fg, boldp) + 1; /* dark red */
12861290
if (blue == 224)
1287-
return lookup_color(5, foreground) + 1; /* dark magenta */
1291+
return lookup_color(5, fg, boldp) + 1; /* dark magenta */
12881292
}
12891293
else if (green == 224)
12901294
{
12911295
if (blue == 0)
1292-
return lookup_color(6, foreground) + 1; /* dark yellow / brown */
1296+
return lookup_color(6, fg, boldp) + 1; /* dark yellow / brown */
12931297
if (blue == 224)
1294-
return lookup_color(8, foreground) + 1; /* white / light grey */
1298+
return lookup_color(8, fg, boldp) + 1; /* white / light grey */
12951299
}
12961300
}
12971301
else if (red == 128)
12981302
{
12991303
if (green == 128 && blue == 128)
1300-
return lookup_color(12, foreground) + 1; /* high intensity black / dark grey */
1304+
return lookup_color(12, fg, boldp) + 1; /* high intensity black / dark grey */
13011305
}
13021306
else if (red == 255)
13031307
{
13041308
if (green == 64)
13051309
{
13061310
if (blue == 64)
1307-
return lookup_color(20, foreground) + 1; /* light red */
1311+
return lookup_color(20, fg, boldp) + 1; /* light red */
13081312
if (blue == 255)
1309-
return lookup_color(22, foreground) + 1; /* light magenta */
1313+
return lookup_color(22, fg, boldp) + 1; /* light magenta */
13101314
}
13111315
else if (green == 255)
13121316
{
13131317
if (blue == 64)
1314-
return lookup_color(24, foreground) + 1; /* yellow */
1318+
return lookup_color(24, fg, boldp) + 1; /* yellow */
13151319
if (blue == 255)
1316-
return lookup_color(26, foreground) + 1; /* white */
1320+
return lookup_color(26, fg, boldp) + 1; /* white */
13171321
}
13181322
}
13191323
else if (red == 64)
13201324
{
13211325
if (green == 64)
13221326
{
13231327
if (blue == 255)
1324-
return lookup_color(14, foreground) + 1; /* light blue */
1328+
return lookup_color(14, fg, boldp) + 1; /* light blue */
13251329
}
13261330
else if (green == 255)
13271331
{
13281332
if (blue == 64)
1329-
return lookup_color(16, foreground) + 1; /* light green */
1333+
return lookup_color(16, fg, boldp) + 1; /* light green */
13301334
if (blue == 255)
1331-
return lookup_color(18, foreground) + 1; /* light cyan */
1335+
return lookup_color(18, fg, boldp) + 1; /* light cyan */
13321336
}
13331337
}
13341338
if (t_colors >= 256)
@@ -1399,8 +1403,14 @@ cell2attr(VTermScreenCell *cell)
13991403
else
14001404
#endif
14011405
{
1402-
return get_cterm_attr_idx(attr, color2index(&cell->fg, TRUE),
1403-
color2index(&cell->bg, FALSE));
1406+
int bold = MAYBE;
1407+
int fg = color2index(&cell->fg, TRUE, &bold);
1408+
int bg = color2index(&cell->bg, FALSE, &bold);
1409+
1410+
/* with 8 colors set the bold attribute to get a bright foreground */
1411+
if (bold == TRUE)
1412+
attr |= HL_BOLD;
1413+
return get_cterm_attr_idx(attr, fg, bg);
14041414
}
14051415
return 0;
14061416
}

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
831,
772774
/**/
773775
830,
774776
/**/

0 commit comments

Comments
 (0)