Skip to content
forked from neovim/neovim

Commit

Permalink
ui: Add 'rgb' parameter to ui_attach
Browse files Browse the repository at this point in the history
When set to false, nvim will send cterm color numbers with `highlight_set`.
  • Loading branch information
tarruda committed Jan 13, 2015
1 parent 631099d commit 29bc6df
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 26 deletions.
4 changes: 3 additions & 1 deletion src/nvim/msgpack_rpc/remote_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/nvim/syntax.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 32 additions & 22 deletions src/nvim/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -328,26 +319,45 @@ 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) {
aep = syn_cterm_attr2entry(mask);
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)
Expand Down
1 change: 1 addition & 0 deletions src/nvim/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/functional/ui/screen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 29bc6df

Please sign in to comment.