comparison src/term.c @ 28656:3f4e1326a003 v8.2.4852

patch 8.2.4852: ANSI color index to RGB value not correct Commit: https://github.com/vim/vim/commit/d2a46624300c5d02be69d0e4df12296ec9011d9e Author: LemonBoy <thatlemon@gmail.com> Date: Sun May 1 17:43:33 2022 +0100 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 https://github.com/vim/vim/issues/10321, closes #9836))
author Bram Moolenaar <Bram@vim.org>
date Sun, 01 May 2022 18:45:04 +0200
parents daad4c7b39be
children a3bcb2a30572
comparison
equal deleted inserted replaced
28655:c68977e0006e 28656:3f4e1326a003
6759 0x08, 0x12, 0x1C, 0x26, 0x30, 0x3A, 0x44, 0x4E, 0x58, 0x62, 0x6C, 0x76, 6759 0x08, 0x12, 0x1C, 0x26, 0x30, 0x3A, 0x44, 0x4E, 0x58, 0x62, 0x6C, 0x76,
6760 0x80, 0x8A, 0x94, 0x9E, 0xA8, 0xB2, 0xBC, 0xC6, 0xD0, 0xDA, 0xE4, 0xEE 6760 0x80, 0x8A, 0x94, 0x9E, 0xA8, 0xB2, 0xBC, 0xC6, 0xD0, 0xDA, 0xE4, 0xEE
6761 }; 6761 };
6762 6762
6763 static char_u ansi_table[16][4] = { 6763 static char_u ansi_table[16][4] = {
6764 // R G B idx 6764 // R G B
6765 { 0, 0, 0, 1}, // black 6765 { 0, 0, 0}, // black
6766 {224, 0, 0, 2}, // dark red 6766 {224, 0, 0}, // dark red
6767 { 0, 224, 0, 3}, // dark green 6767 { 0, 224, 0}, // dark green
6768 {224, 224, 0, 4}, // dark yellow / brown 6768 {224, 224, 0}, // dark yellow / brown
6769 { 0, 0, 224, 5}, // dark blue 6769 { 0, 0, 224}, // dark blue
6770 {224, 0, 224, 6}, // dark magenta 6770 {224, 0, 224}, // dark magenta
6771 { 0, 224, 224, 7}, // dark cyan 6771 { 0, 224, 224}, // dark cyan
6772 {224, 224, 224, 8}, // light grey 6772 {224, 224, 224}, // light grey
6773 6773
6774 {128, 128, 128, 9}, // dark grey 6774 {128, 128, 128}, // dark grey
6775 {255, 64, 64, 10}, // light red 6775 {255, 64, 64}, // light red
6776 { 64, 255, 64, 11}, // light green 6776 { 64, 255, 64}, // light green
6777 {255, 255, 64, 12}, // yellow 6777 {255, 255, 64}, // yellow
6778 { 64, 64, 255, 13}, // light blue 6778 { 64, 64, 255}, // light blue
6779 {255, 64, 255, 14}, // light magenta 6779 {255, 64, 255}, // light magenta
6780 { 64, 255, 255, 15}, // light cyan 6780 { 64, 255, 255}, // light cyan
6781 {255, 255, 255, 16}, // white 6781 {255, 255, 255}, // white
6782 }; 6782 };
6783
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
6783 6790
6784 #define ANSI_INDEX_NONE 0 6791 #define ANSI_INDEX_NONE 0
6785 6792
6786 void 6793 void
6787 cterm_color2rgb(int nr, char_u *r, char_u *g, char_u *b, char_u *ansi_idx) 6794 cterm_color2rgb(int nr, char_u *r, char_u *g, char_u *b, char_u *ansi_idx)
6788 { 6795 {
6789 int idx; 6796 int idx;
6790 6797
6791 if (nr < 16) 6798 if (nr < 16)
6792 { 6799 {
6793 *r = ansi_table[nr][0]; 6800 #if defined(MSWIN)
6794 *g = ansi_table[nr][1]; 6801 idx = cterm_ansi_idx[nr];
6795 *b = ansi_table[nr][2]; 6802 #else
6796 *ansi_idx = ansi_table[nr][3]; 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;
6797 } 6809 }
6798 else if (nr < 232) 6810 else if (nr < 232)
6799 { 6811 {
6800 // 216 color cube 6812 // 216 color cube
6801 idx = nr - 16; 6813 idx = nr - 16;