diff --git a/src/nvim/msgpack_rpc/remote_ui.c b/src/nvim/msgpack_rpc/remote_ui.c index e1cb47453098d1..6a638df61cc50b 100644 --- a/src/nvim/msgpack_rpc/remote_ui.c +++ b/src/nvim/msgpack_rpc/remote_ui.c @@ -61,8 +61,9 @@ static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, return NIL; } - if (args.size != 2 || args.items[0].type != kObjectTypeInteger + if (args.size != 3 || args.items[0].type != kObjectTypeInteger || args.items[1].type != kObjectTypeInteger + || args.items[2].type != kObjectTypeBoolean || args.items[0].data.integer <= 0 || args.items[1].data.integer <= 0) { api_set_error(error, Validation, _("Arguments must be a pair of positive integers " @@ -75,6 +76,7 @@ static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, UI *ui = xcalloc(1, sizeof(UI)); ui->width = (int)args.items[0].data.integer; ui->height = (int)args.items[1].data.integer; + ui->rgb = args.items[2].data.boolean; ui->data = data; ui->resize = remote_ui_resize; ui->clear = remote_ui_clear; diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index c83968b7cc73c9..14bca0c0d6a045 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -6439,8 +6439,7 @@ do_highlight ( HL_TABLE()[idx].sg_cterm &= ~HL_BOLD; } color &= 7; /* truncate to 8 colors */ - } else if (t_colors == 16 || t_colors == 88 - || t_colors == 256) { + } else if (t_colors == 16 || t_colors == 88 || t_colors == 256) { /* * Guess: if the termcap entry ends in 'm', it is * probably an xterm-like terminal. Use the changed diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 424197ed779a98..7ef9751241e420 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -60,9 +60,6 @@ static struct { int top, bot, left, right; } sr; static int current_highlight_mask = 0; -static HlAttrs current_attrs = { - false, false, false, false, false, -1, -1 -}; static bool cursor_enabled = true; static int height, width; @@ -187,13 +184,8 @@ void ui_resize(int new_width, int new_height) width = new_width; height = new_height; - if (normal_fg != -1) { - UI_CALL(update_fg, normal_fg); - } - - if (normal_bg != -1) { - UI_CALL(update_bg, normal_bg); - } + UI_CALL(update_fg, (ui->rgb ? normal_fg : cterm_normal_fg_color - 1)); + UI_CALL(update_bg, (ui->rgb ? normal_bg : cterm_normal_bg_color - 1)); sr.top = 0; sr.bot = height - 1; @@ -314,8 +306,7 @@ static void highlight_start(int mask) return; } - set_highlight_args(current_highlight_mask, ¤t_attrs); - UI_CALL(highlight_set, current_attrs); + set_highlight_args(current_highlight_mask); } static void highlight_stop(int mask) @@ -328,12 +319,12 @@ static void highlight_stop(int mask) current_highlight_mask &= ~mask; } - set_highlight_args(current_highlight_mask, ¤t_attrs); - UI_CALL(highlight_set, current_attrs); + set_highlight_args(current_highlight_mask); } -static void set_highlight_args(int mask, HlAttrs *attrs) +static void set_highlight_args(int mask) { + HlAttrs rgb_attrs = { false, false, false, false, false, -1, -1 }; attrentry_T *aep = NULL; if (mask > HL_ALL) { @@ -341,13 +332,32 @@ static void set_highlight_args(int mask, HlAttrs *attrs) mask = aep ? aep->ae_attr : 0; } - attrs->bold = mask & HL_BOLD; - attrs->underline = mask & HL_UNDERLINE; - attrs->undercurl = mask & HL_UNDERCURL; - attrs->italic = mask & HL_ITALIC; - attrs->reverse = mask & (HL_INVERSE | HL_STANDOUT); - attrs->foreground = aep && aep->fg_color >= 0 ? aep->fg_color : normal_fg; - attrs->background = aep && aep->bg_color >= 0 ? aep->bg_color : normal_bg; + rgb_attrs.bold = mask & HL_BOLD; + rgb_attrs.underline = mask & HL_UNDERLINE; + rgb_attrs.undercurl = mask & HL_UNDERCURL; + rgb_attrs.italic = mask & HL_ITALIC; + rgb_attrs.reverse = mask & (HL_INVERSE | HL_STANDOUT); + HlAttrs cterm_attrs = rgb_attrs; + + if (aep) { + if (aep->fg_color != normal_fg) { + rgb_attrs.foreground = aep->fg_color; + } + + if (aep->bg_color != normal_bg) { + rgb_attrs.background = aep->bg_color; + } + + if (cterm_normal_fg_color != aep->ae_u.cterm.fg_color) { + cterm_attrs.foreground = aep->ae_u.cterm.fg_color - 1; + } + + if (cterm_normal_bg_color != aep->ae_u.cterm.bg_color) { + cterm_attrs.background = aep->ae_u.cterm.bg_color - 1; + } + } + + UI_CALL(highlight_set, (ui->rgb ? rgb_attrs : cterm_attrs)); } static void parse_abstract_ui_codes(uint8_t *ptr, int len) diff --git a/src/nvim/ui.h b/src/nvim/ui.h index 0fcd686e7bb664..9ec10db75ed3ad 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -13,6 +13,7 @@ typedef struct { typedef struct ui_t UI; struct ui_t { + bool rgb; int width, height; void *data; void (*resize)(UI *ui, int rows, int columns); diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua index 23ad66aeb6831a..7e8811fe2f79d3 100644 --- a/test/functional/ui/screen.lua +++ b/test/functional/ui/screen.lua @@ -115,7 +115,7 @@ function Screen:set_default_attr_ids(attr_ids) end function Screen:attach() - request('ui_attach', self._width, self._height) + request('ui_attach', self._width, self._height, true) self._suspended = false end