From 4f5f246a958e66e04a5d62b3bf0d8986afb51c09 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 12 Dec 2014 16:25:11 -0300 Subject: ui: Add update_fg/update_bg methods It is necessary to notify the UI when the default background/foreground colors change in order to render correctly. --- src/nvim/ui.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 9c58193e8c..b37bc92b1a 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -113,6 +113,18 @@ void ui_write(uint8_t *s, int len) free(tofree); } +void ui_fg_updated(void) +{ + UI_CALL(update_fg, normal_fg); + UI_CALL(flush); +} + +void ui_bg_updated(void) +{ + UI_CALL(update_bg, normal_bg); + UI_CALL(flush); +} + /* * If the machine has job control, use it to suspend the program, * otherwise fake it by starting a new shell. @@ -167,6 +179,8 @@ void ui_cursor_shape(void) void ui_resize(int width, int height) { + ui_fg_updated(); + ui_bg_updated(); sr.top = 0; sr.bot = height - 1; sr.left = 0; -- cgit From b17005edd98dd7b46b5ff689d83d7bcebac756e5 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 12 Dec 2014 16:26:27 -0300 Subject: ui: Increase cursor row when text being rendered would cross its limit --- src/nvim/ui.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index b37bc92b1a..cd8c3b73e6 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -458,6 +458,9 @@ static void parse_abstract_ui_codes(uint8_t *ptr, int len) UI_CALL(put, NULL, 0); col++; } + if (col >= width) { + ui_cursor_goto(row + 1, 0); + } p += clen; } ptr = p; -- cgit From 213c3c3e53459a77c77166cda85ba619e7eb2eb1 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Sat, 13 Dec 2014 12:58:06 -0300 Subject: ui: Fix ui resizing and change some method names --- src/nvim/ui.c | 74 ++++++++++++++++++++++------------------------------------- 1 file changed, 28 insertions(+), 46 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index cd8c3b73e6..de92079ada 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -64,7 +64,7 @@ static HlAttrs current_attrs = { false, false, false, false, false, false, -1, -1 }; static bool cursor_enabled = true; -static int height = INT_MAX, width = INT_MAX; +static int height, width; // This set of macros allow us to use UI_CALL to invoke any function on // registered UI instances. The functions can have 0-5 arguments(configurable @@ -113,18 +113,6 @@ void ui_write(uint8_t *s, int len) free(tofree); } -void ui_fg_updated(void) -{ - UI_CALL(update_fg, normal_fg); - UI_CALL(flush); -} - -void ui_bg_updated(void) -{ - UI_CALL(update_bg, normal_bg); - UI_CALL(flush); -} - /* * If the machine has job control, use it to suspend the program, * otherwise fake it by starting a new shell. @@ -177,10 +165,32 @@ void ui_cursor_shape(void) } } -void ui_resize(int width, int height) +void ui_refresh(void) { - ui_fg_updated(); - ui_bg_updated(); + width = height = INT_MAX; + + for (size_t i = 0; i < ui_count; i++) { + UI *ui = uis[i]; + width = ui->width < width ? ui->width : width; + height = ui->height < height ? ui->height : height; + } + + screen_resize(width, height, true); +} + +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); + } + sr.top = 0; sr.bot = height - 1; sr.left = 0; @@ -254,7 +264,7 @@ void ui_attach(UI *ui) } uis[ui_count++] = ui; - resized(ui); + ui_refresh(); } void ui_detach(UI *ui) @@ -281,17 +291,8 @@ void ui_detach(UI *ui) ui_count--; - if (ui->width == width || ui->height == height) { - // It is possible that the UI being detached had the smallest screen, - // so check for the new minimum dimensions - width = height = INT_MAX; - for (size_t i = 0; i < ui_count; i++) { - check_dimensions(uis[i]); - } - } - if (ui_count) { - screen_resize(width, height, true); + ui_refresh(); } } @@ -474,25 +475,6 @@ static void parse_abstract_ui_codes(uint8_t *ptr, int len) UI_CALL(flush); } -static void resized(UI *ui) -{ - check_dimensions(ui); - screen_resize(width, height, true); -} - -static void check_dimensions(UI *ui) -{ - // The internal screen dimensions are always the minimum required to fit on - // all connected screens - if (ui->width < width) { - width = ui->width; - } - - if (ui->height < height) { - height = ui->height; - } -} - static void ui_linefeed(void) { int new_col = 0; -- cgit From 0887c5446ee8ec6ea53ef69e5d02bd319e1bca1c Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Tue, 30 Dec 2014 08:24:22 -0300 Subject: ui: Merge standout and reverse into one attribute --- src/nvim/ui.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index de92079ada..b95fdd1104 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -61,7 +61,7 @@ static struct { } sr; static int current_highlight_mask = 0; static HlAttrs current_attrs = { - false, false, false, false, false, false, -1, -1 + false, false, false, false, false, -1, -1 }; static bool cursor_enabled = true; static int height, width; @@ -338,11 +338,10 @@ static void set_highlight_args(int mask, HlAttrs *attrs) } attrs->bold = mask & HL_BOLD; - attrs->standout = mask & HL_STANDOUT; attrs->underline = mask & HL_UNDERLINE; attrs->undercurl = mask & HL_UNDERCURL; attrs->italic = mask & HL_ITALIC; - attrs->reverse = mask & HL_INVERSE; + 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; } -- cgit From a8fe32040b039c134087c4c0d8c9e14bf50fef1a Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Thu, 8 Jan 2015 10:42:12 -0300 Subject: ui: Dont resize screen if no UIs are attached This prevents a race condition when a UI attaches early in the program and can receive redraw commands for a invalid screen --- src/nvim/ui.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index b95fdd1104..80f8b9221a 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -167,6 +167,10 @@ void ui_cursor_shape(void) void ui_refresh(void) { + if (!ui_count) { + return; + } + width = height = INT_MAX; for (size_t i = 0; i < ui_count; i++) { -- cgit From 74c247f75baec5778296adf164831c5ffea0fb88 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Thu, 8 Jan 2015 11:23:45 -0300 Subject: ui: Add 'rgb' parameter to ui_attach When set to false, nvim will send cterm color numbers with `highlight_set`. --- src/nvim/ui.c | 54 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'src/nvim/ui.c') 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, ¤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) -- cgit From abc147a9775ef7de221443ff68ddfbc8ff6e0177 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 9 Jan 2015 09:18:23 -0300 Subject: ui: Don't parse abstract_ui codes if there are no attached UIs --- src/nvim/ui.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 8012bb4ee7..da47080045 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -362,6 +362,10 @@ static void set_highlight_args(int mask) static void parse_abstract_ui_codes(uint8_t *ptr, int len) { + if (!ui_count) { + return; + } + int arg1 = 0, arg2 = 0; uint8_t *end = ptr + len, *p, c; bool update_cursor = false; -- cgit From d992213678ecd14902ae74ff765e682fb76d5ad9 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 9 Jan 2015 09:51:11 -0300 Subject: ui: Reimplement `:suspend` command for remote UIs. - Remove suspend method from the UI protocol - Handle `:suspend` by disconnecting the last channel that sent a request to nvim. --- src/nvim/ui.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index da47080045..5bd4382483 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -117,9 +117,7 @@ void ui_write(uint8_t *s, int len) */ void ui_suspend(void) { - if (abstract_ui) { - UI_CALL(suspend); - } else { + if (!abstract_ui) { mch_suspend(); } } -- cgit From e1da130ca9bb132335e4255421fded3e80ca4fad Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Sat, 10 Jan 2015 02:37:22 -0300 Subject: ui: Fix out_flush/ui_write behavior to always flush for abstract_ui --- src/nvim/ui.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 5bd4382483..5b28cf2243 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -95,6 +95,10 @@ void ui_write(uint8_t *s, int len) return; } + if (!len) { + return; + } + char_u *tofree = NULL; if (output_conv.vc_type != CONV_NONE) { -- cgit From 7703fd328c44793cc3793fe4c2bf1b58d63dec45 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Sat, 10 Jan 2015 22:44:29 -0300 Subject: ui: Use ui_linefeed to handle line breaks correctly ui_linefeed will scroll the screen when it becomes full. This can happen when executing external commands. --- src/nvim/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 5b28cf2243..d66be0f8df 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -479,7 +479,7 @@ static void parse_abstract_ui_codes(uint8_t *ptr, int len) col++; } if (col >= width) { - ui_cursor_goto(row + 1, 0); + ui_linefeed(); } p += clen; } -- cgit From a16cd73eadf473e3f2da104e2620680c4b5dd9d6 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Mon, 12 Jan 2015 08:59:51 -0300 Subject: ui: Fix redraw bug caused by race conditions with remote clients Before sending a resize command to the UIs, flush the current output buffer to ensure no redraw commands for a screen with invalid size are processed. --- src/nvim/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index d66be0f8df..80dbea31cb 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -170,7 +170,7 @@ void ui_refresh(void) return; } - width = height = INT_MAX; + int width = INT_MAX, height = INT_MAX; for (size_t i = 0; i < ui_count; i++) { UI *ui = uis[i]; -- cgit