Skip to content

Commit a8fc0d3

Browse files
committed
patch 8.0.1149: libvterm colors differ from xterm
Problem: libvterm colors differ from xterm. Solution: Use the xterm colors for libvterm.
1 parent 22ab547 commit a8fc0d3

File tree

5 files changed

+77
-15
lines changed

5 files changed

+77
-15
lines changed

Filelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ SRC_ALL = \
136136
src/testdir/bench*.vim \
137137
src/testdir/samples/*.txt \
138138
src/testdir/if_ver*.vim \
139+
src/testdir/xterm_ramp.vim \
139140
src/proto.h \
140141
src/proto/arabic.pro \
141142
src/proto/blowfish.pro \

src/libvterm/src/pen.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ static const VTermColor ansi_colors[] = {
2525
};
2626

2727
static int ramp6[] = {
28-
0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF,
28+
0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF,
2929
};
3030

31+
/* Use 0x81 instead of 0x80 to be able to distinguish from ansi black */
3132
static int ramp24[] = {
32-
0x00, 0x0B, 0x16, 0x21, 0x2C, 0x37, 0x42, 0x4D, 0x58, 0x63, 0x6E, 0x79,
33-
0x85, 0x90, 0x9B, 0xA6, 0xB1, 0xBC, 0xC7, 0xD2, 0xDD, 0xE8, 0xF3, 0xFF,
33+
0x08, 0x12, 0x1C, 0x26, 0x30, 0x3A, 0x44, 0x4E, 0x58, 0x62, 0x6C, 0x76,
34+
0x81, 0x8A, 0x94, 0x9E, 0xA8, 0xB2, 0xBC, 0xC6, 0xD0, 0xDA, 0xE4, 0xEE,
3435
};
3536

3637
static int lookup_colour_ansi(const VTermState *state, long index, VTermColor *col)

src/terminal.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@
4141
* - in GUI vertical split causes problems. Cursor is flickering. (Hirohito
4242
* Higashi, 2017 Sep 19)
4343
* - Shift-Tab does not work.
44-
* - click in Window toolbar of other window: save/restore Insert and Visual
44+
* - double click in Window toolbar starts Visual mode.
4545
* - Redirecting output does not work on MS-Windows, Test_terminal_redir_file()
4646
* is disabled.
47+
* - cursor blinks in terminal on widows with a timer. (xtal8, #2142)
4748
* - implement term_setsize()
49+
* - MS-Windows GUI: WinBar has tearoff item
4850
* - MS-Windows GUI: still need to type a key after shell exits? #1924
4951
* - add test for giving error for invalid 'termsize' value.
5052
* - support minimal size when 'termsize' is "rows*cols".
@@ -1791,23 +1793,38 @@ color2index(VTermColor *color, int fg, int *boldp)
17911793
{
17921794
if (red == blue && red == green)
17931795
{
1794-
/* 24-color greyscale */
1796+
/* 24-color greyscale plus white and black */
17951797
static int cutoff[23] = {
1796-
0x05, 0x10, 0x1B, 0x26, 0x31, 0x3C, 0x47, 0x52,
1797-
0x5D, 0x68, 0x73, 0x7F, 0x8A, 0x95, 0xA0, 0xAB,
1798-
0xB6, 0xC1, 0xCC, 0xD7, 0xE2, 0xED, 0xF9};
1798+
0x0D, 0x17, 0x21, 0x2B, 0x35, 0x3F, 0x49, 0x53, 0x5D, 0x67,
1799+
0x71, 0x7B, 0x85, 0x8F, 0x99, 0xA3, 0xAD, 0xB7, 0xC1, 0xCB,
1800+
0xD5, 0xDF, 0xE9};
17991801
int i;
18001802

1803+
if (red < 5)
1804+
return 17; /* 00/00/00 */
1805+
if (red > 245) /* ff/ff/ff */
1806+
return 232;
18011807
for (i = 0; i < 23; ++i)
18021808
if (red < cutoff[i])
18031809
return i + 233;
18041810
return 256;
18051811
}
1812+
{
1813+
static int cutoff[5] = {0x2F, 0x73, 0x9B, 0xC3, 0xEB};
1814+
int ri, gi, bi;
18061815

1807-
/* 216-color cube */
1808-
return 17 + ((red + 25) / 0x33) * 36
1809-
+ ((green + 25) / 0x33) * 6
1810-
+ (blue + 25) / 0x33;
1816+
/* 216-color cube */
1817+
for (ri = 0; ri < 5; ++ri)
1818+
if (red < cutoff[ri])
1819+
break;
1820+
for (gi = 0; gi < 5; ++gi)
1821+
if (green < cutoff[gi])
1822+
break;
1823+
for (bi = 0; bi < 5; ++bi)
1824+
if (blue < cutoff[bi])
1825+
break;
1826+
return 17 + ri * 36 + gi * 6 + bi;
1827+
}
18111828
}
18121829
return 0;
18131830
}
@@ -2426,16 +2443,17 @@ static VTermColor ansi_table[16] = {
24262443
};
24272444

24282445
static int cube_value[] = {
2429-
0x00, 0x33, 0x66, 0x99, 0xCC, 0xFF,
2446+
0x00, 0x5F, 0x87, 0xAF, 0xD7, 0xFF
24302447
};
24312448

24322449
static int grey_ramp[] = {
2433-
0x00, 0x0B, 0x16, 0x21, 0x2C, 0x37, 0x42, 0x4D, 0x58, 0x63, 0x6E, 0x79,
2434-
0x85, 0x90, 0x9B, 0xA6, 0xB1, 0xBC, 0xC7, 0xD2, 0xDD, 0xE8, 0xF3, 0xFF,
2450+
0x08, 0x12, 0x1C, 0x26, 0x30, 0x3A, 0x44, 0x4E, 0x58, 0x62, 0x6C, 0x76,
2451+
0x80, 0x8A, 0x94, 0x9E, 0xA8, 0xB2, 0xBC, 0xC6, 0xD0, 0xDA, 0xE4, 0xEE
24352452
};
24362453

24372454
/*
24382455
* Convert a cterm color number 0 - 255 to RGB.
2456+
* This is compatible with xterm.
24392457
*/
24402458
static void
24412459
cterm_color2rgb(int nr, VTermColor *rgb)

src/testdir/xterm_ramp.vim

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
" Script to generate a file that shows al 256 xterm colors
2+
3+
new
4+
call setline(1, 'ANSI')
5+
6+
" ANSI colors
7+
let s = ''
8+
for nr in range(0, 7)
9+
let s .= "\033[4" . nr . "m "
10+
endfor
11+
for nr in range(8, 15)
12+
let s .= "\033[10" . (nr - 8) . "m "
13+
endfor
14+
let s .= "\033[107m|"
15+
call setline(2, s)
16+
17+
" 6 x 6 x 6 color cube
18+
call setline(3, 'color cube')
19+
for high in range(0, 5)
20+
let s = ''
21+
for low in range(0, 35)
22+
let nr = low + high * 36
23+
let s .= "\033[48;5;" . (nr + 16) . "m "
24+
endfor
25+
let s .= "\033[107m|"
26+
call setline(high + 4, s)
27+
endfor
28+
29+
" 24 shades of grey
30+
call setline(10, 'grey ramp')
31+
let s = ''
32+
for nr in range(0, 23)
33+
let s .= "\033[48;5;" . (nr + 232) . "m "
34+
endfor
35+
let s .= "\033[107m|"
36+
call setline(11, s)
37+
38+
set binary
39+
write! <sfile>:h/xterm_ramp.txt
40+
quit

src/version.c

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

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1149,
764766
/**/
765767
1148,
766768
/**/

0 commit comments

Comments
 (0)