aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2015-01-08 11:23:45 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2015-01-12 09:47:41 -0300
commit74c247f75baec5778296adf164831c5ffea0fb88 (patch)
tree1950d2681c1d659edf86477188020f04ea1492e6
parenta8fe32040b039c134087c4c0d8c9e14bf50fef1a (diff)
downloadrneovim-74c247f75baec5778296adf164831c5ffea0fb88.tar.gz
rneovim-74c247f75baec5778296adf164831c5ffea0fb88.tar.bz2
rneovim-74c247f75baec5778296adf164831c5ffea0fb88.zip
ui: Add 'rgb' parameter to ui_attach
When set to false, nvim will send cterm color numbers with `highlight_set`.
-rw-r--r--src/nvim/msgpack_rpc/remote_ui.c4
-rw-r--r--src/nvim/syntax.c7
-rw-r--r--src/nvim/ui.c54
-rw-r--r--src/nvim/ui.h1
-rw-r--r--test/functional/ui/screen.lua2
5 files changed, 41 insertions, 27 deletions
diff --git a/src/nvim/msgpack_rpc/remote_ui.c b/src/nvim/msgpack_rpc/remote_ui.c
index e1cb474530..6a638df61c 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 884a563fea..805f808449 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -6432,7 +6432,9 @@ do_highlight (
/* Use the _16 table to check if its a valid color name. */
color = color_numbers_16[i];
if (color >= 0) {
- if (t_colors == 8) {
+ if (abstract_ui) {
+ color = color_numbers_256[i];
+ } else if (t_colors == 8) {
/* t_Co is 8: use the 8 colors table */
#if defined(__QNXNTO__)
color = color_numbers_8_qansi[i];
@@ -6449,8 +6451,7 @@ do_highlight (
HL_TABLE()[idx].sg_cterm &= ~HL_BOLD;
}
color &= 7; /* truncate to 8 colors */
- } else if (abstract_ui || 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 80f8b9221a..8012bb4ee7 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, &current_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, &current_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 0fcd686e7b..9ec10db75e 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 a965b3626a..04d89d8331 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