aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2016-05-06 14:47:56 -0400
committerJustin M. Keyes <justinkz@gmail.com>2016-05-06 14:47:56 -0400
commit6c3ead668422b1252f7ed07ce52776966c29e3cb (patch)
tree6583b1792b81dbdc2285cf85c82514a3a0b4af30
parent90995ba7889eca7f7604031eff88adeefdfebb42 (diff)
parentb16b27a1bef31d577cbf3ef5127559502e672f21 (diff)
downloadrneovim-6c3ead668422b1252f7ed07ce52776966c29e3cb.tar.gz
rneovim-6c3ead668422b1252f7ed07ce52776966c29e3cb.tar.bz2
rneovim-6c3ead668422b1252f7ed07ce52776966c29e3cb.zip
Merge pull request #4350 from DarkDefender/term_color
Fix guessing incorrect color index in terminal
-rw-r--r--src/nvim/terminal.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c
index 0440272eb9..104cc47cda 100644
--- a/src/nvim/terminal.c
+++ b/src/nvim/terminal.c
@@ -175,7 +175,16 @@ void terminal_init(void)
for (int color_index = 0; color_index < 256; color_index++) {
VTermColor color;
- vterm_state_get_palette_color(state, color_index, &color);
+ // Some of the default 16 colors has the same color as the later
+ // 240 colors. To avoid collisions, we will use the custom colors
+ // below in non true color mode.
+ if (color_index < 16) {
+ color.red = 0;
+ color.green = 0;
+ color.blue = (uint8_t)(color_index + 1);
+ } else {
+ vterm_state_get_palette_color(state, color_index, &color);
+ }
map_put(int, int)(color_indexes,
RGB(color.red, color.green, color.blue), color_index + 1);
}
@@ -248,6 +257,15 @@ Terminal *terminal_open(TerminalOptions opts)
rv->sb_buffer = xmalloc(sizeof(ScrollbackLine *) * rv->sb_size);
if (!true_color) {
+ // Change the first 16 colors so we can easily get the correct color
+ // index from them.
+ for (int i = 0; i < 16; i++) {
+ VTermColor color;
+ color.red = 0;
+ color.green = 0;
+ color.blue = (uint8_t)(i + 1);
+ vterm_state_set_palette_color(state, i, &color);
+ }
return rv;
}
@@ -548,9 +566,9 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr,
// Since libvterm does not expose the color index used by the program, we
// use the rgb value to find the appropriate index in the cache computed by
// `terminal_init`.
- int vt_fg_idx = vt_fg != default_vt_fg ?
+ int vt_fg_idx = vt_fg != -1 ?
map_get(int, int)(color_indexes, vt_fg) : 0;
- int vt_bg_idx = vt_bg != default_vt_bg ?
+ int vt_bg_idx = vt_bg != -1 ?
map_get(int, int)(color_indexes, vt_bg) : 0;
int hl_attrs = (cell.attrs.bold ? HL_BOLD : 0)