Skip to content

Commit d2a4662

Browse files
LemonBoybrammool
authored andcommitted
patch 8.2.4852: ANSI color index to RGB value not correct
Problem: ANSI color index to RGB value not correct. Solution: Convert the cterm index to ANSI index. (closes #10321, closes #9836))
1 parent b4011af commit d2a4662

2 files changed

Lines changed: 36 additions & 22 deletions

File tree

src/term.c

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6761,26 +6761,33 @@ static int grey_ramp[] = {
67616761
};
67626762

67636763
static char_u ansi_table[16][4] = {
6764-
// R G B idx
6765-
{ 0, 0, 0, 1}, // black
6766-
{224, 0, 0, 2}, // dark red
6767-
{ 0, 224, 0, 3}, // dark green
6768-
{224, 224, 0, 4}, // dark yellow / brown
6769-
{ 0, 0, 224, 5}, // dark blue
6770-
{224, 0, 224, 6}, // dark magenta
6771-
{ 0, 224, 224, 7}, // dark cyan
6772-
{224, 224, 224, 8}, // light grey
6773-
6774-
{128, 128, 128, 9}, // dark grey
6775-
{255, 64, 64, 10}, // light red
6776-
{ 64, 255, 64, 11}, // light green
6777-
{255, 255, 64, 12}, // yellow
6778-
{ 64, 64, 255, 13}, // light blue
6779-
{255, 64, 255, 14}, // light magenta
6780-
{ 64, 255, 255, 15}, // light cyan
6781-
{255, 255, 255, 16}, // white
6764+
// R G B
6765+
{ 0, 0, 0}, // black
6766+
{224, 0, 0}, // dark red
6767+
{ 0, 224, 0}, // dark green
6768+
{224, 224, 0}, // dark yellow / brown
6769+
{ 0, 0, 224}, // dark blue
6770+
{224, 0, 224}, // dark magenta
6771+
{ 0, 224, 224}, // dark cyan
6772+
{224, 224, 224}, // light grey
6773+
6774+
{128, 128, 128}, // dark grey
6775+
{255, 64, 64}, // light red
6776+
{ 64, 255, 64}, // light green
6777+
{255, 255, 64}, // yellow
6778+
{ 64, 64, 255}, // light blue
6779+
{255, 64, 255}, // light magenta
6780+
{ 64, 255, 255}, // light cyan
6781+
{255, 255, 255}, // white
67826782
};
67836783

6784+
#if defined(MSWIN)
6785+
// Mapping between cterm indices < 16 and their counterpart in the ANSI palette.
6786+
static const char_u cterm_ansi_idx[] = {
6787+
0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15
6788+
};
6789+
#endif
6790+
67846791
#define ANSI_INDEX_NONE 0
67856792

67866793
void
@@ -6790,10 +6797,15 @@ cterm_color2rgb(int nr, char_u *r, char_u *g, char_u *b, char_u *ansi_idx)
67906797

67916798
if (nr < 16)
67926799
{
6793-
*r = ansi_table[nr][0];
6794-
*g = ansi_table[nr][1];
6795-
*b = ansi_table[nr][2];
6796-
*ansi_idx = ansi_table[nr][3];
6800+
#if defined(MSWIN)
6801+
idx = cterm_ansi_idx[nr];
6802+
#else
6803+
idx = nr;
6804+
#endif
6805+
*r = ansi_table[idx][0];
6806+
*g = ansi_table[idx][1];
6807+
*b = ansi_table[idx][2];
6808+
*ansi_idx = idx + 1;
67976809
}
67986810
else if (nr < 232)
67996811
{

src/version.c

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

747747
static int included_patches[] =
748748
{ /* Add new patch number below this line */
749+
/**/
750+
4852,
749751
/**/
750752
4851,
751753
/**/

0 commit comments

Comments
 (0)