From 6c5f9219ef55bab06850346d256a09c7c89f297e Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 2 Aug 2018 08:51:57 +0200 Subject: tui: use bce properly --- src/nvim/tui/tui.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index df14ddf988..58d1b09d55 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -95,6 +95,7 @@ typedef struct { bool can_set_lr_margin; bool can_set_left_right_margin; bool immediate_wrap_after_last_column; + bool bce; bool mouse_enabled; bool busy, is_invisible; bool cork, overflow; @@ -236,6 +237,7 @@ static void terminfo_start(UI *ui) data->immediate_wrap_after_last_column = terminfo_is_term_family(term, "cygwin") || terminfo_is_term_family(term, "interix"); + data->bce = unibi_get_bool(data->ut, unibi_back_color_erase); data->normlen = unibi_pre_fmt_str(data, unibi_cursor_normal, data->norm, sizeof data->norm); data->invislen = unibi_pre_fmt_str(data, unibi_cursor_invisible, @@ -435,6 +437,12 @@ static bool attrs_differ(HlAttrs a1, HlAttrs a2, bool rgb) } } +static bool no_bg(UI *ui, HlAttrs attrs) +{ + return ui->rgb ? attrs.rgb_bg_color == -1 + : attrs.cterm_bg_color == 0; +} + static void update_attrs(UI *ui, HlAttrs attrs) { TUIData *data = ui->data; @@ -693,10 +701,11 @@ static void clear_region(UI *ui, int top, int bot, int left, int right, UGrid *grid = &data->grid; bool cleared = false; - // TODO(bfredl): support BCE for non-default background - bool nobg = ui->rgb ? attrs.rgb_bg_color == -1 - : attrs.cterm_bg_color == 0; - if (nobg && right == ui->width -1) { + + // non-BCE terminals can't clear with non-default background color + bool can_clear = data->bce || no_bg(ui, attrs); + + if (can_clear && right == ui->width -1) { // Background is set to the default color and the right edge matches the // screen end, try to use terminal codes for clearing the requested area. update_attrs(ui, attrs); @@ -984,18 +993,13 @@ static void tui_grid_scroll(UI *ui, Integer g, Integer top, Integer bot, ugrid_scroll(grid, (int)rows, &clear_top, &clear_bot); if (can_use_scroll(ui)) { - bool scroll_clears_to_current_colour = - unibi_get_bool(data->ut, unibi_back_color_erase); - // Change terminal scroll region and move cursor to the top if (!data->scroll_region_is_full_screen) { set_scroll_region(ui); } cursor_goto(ui, grid->top, grid->left); // also set default color attributes or some terminals can become funny - if (scroll_clears_to_current_colour) { - update_attrs(ui, data->clear_attrs); - } + update_attrs(ui, data->clear_attrs); if (rows > 0) { if (rows == 1) { @@ -1019,7 +1023,7 @@ static void tui_grid_scroll(UI *ui, Integer g, Integer top, Integer bot, } cursor_goto(ui, data->row, data->col); - if (!scroll_clears_to_current_colour) { + if (!(data->bce || no_bg(ui, data->clear_attrs))) { // Scrolling will leave wrong background in the cleared area on non-BCE // terminals. Update the cleared area. clear_region(ui, clear_top, clear_bot, grid->left, grid->right, -- cgit From e5bcf8338054c92ae5c505c110208274e5b52b7d Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 2 Aug 2018 14:03:22 +0200 Subject: tui: hack for invalid first line with non-bce resize --- src/nvim/tui/tui.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 58d1b09d55..e80d1cdc59 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -88,6 +88,7 @@ typedef struct { bool cont_received; UGrid grid; kvec_t(Rect) invalid_regions; + bool did_resize; int row, col; int out_fd; bool scroll_region_is_full_screen; @@ -738,6 +739,14 @@ static void clear_region(UI *ui, int top, int bot, int left, int right, cursor_goto(ui, row, col); print_cell(ui, cell); }); + + if (data->did_resize && top == 0) { + // TODO(bfredl): the first line of the screen doesn't gets properly + // cleared after resize by the loop above, so redraw the final state + // after the next flush. + invalidate(ui, 0, bot, left, right); + data->did_resize = false; + } } // restore cursor @@ -813,6 +822,7 @@ static void tui_grid_resize(UI *ui, Integer g, Integer width, Integer height) TUIData *data = ui->data; UGrid *grid = &data->grid; ugrid_resize(grid, (int)width, (int)height); + data->did_resize = true; // resize might not always be followed by a clear before flush // so clip the invalid region -- cgit From 5fad02c081e9123234d3554c2158f9ef8bac8b8e Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 2 Aug 2018 17:56:00 +0200 Subject: tui: reenable cursor movement optimizations (leftover from #8221) --- src/nvim/tui/tui.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index e80d1cdc59..4bf476ef2d 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -606,8 +606,6 @@ static void cursor_goto(UI *ui, int row, int col) if (row == grid->row && col == grid->col) { return; } - grid->row = row; - grid->col = col; if (0 == row && 0 == col) { unibi_out(ui, unibi_cursor_home); ugrid_goto(grid, row, col); -- cgit From 5a0d0286ff4d9ea2cc4621d9b514722922e77c78 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 3 Aug 2018 23:30:51 +0200 Subject: TUI: use BCE again more often, as it provides smoother resizes and scrolling add exceptions for terminals we know doesn't support BCE --- src/nvim/tui/tui.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 4bf476ef2d..0781b03965 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -1394,6 +1394,7 @@ static void patch_terminfo_bugs(TUIData *data, const char *term, bool roxterm = !!os_getenv("ROXTERM_ID"); #endif bool xterm = terminfo_is_term_family(term, "xterm"); + bool kitty = terminfo_is_term_family(term, "xterm-kitty"); bool linuxvt = terminfo_is_term_family(term, "linux"); bool rxvt = terminfo_is_term_family(term, "rxvt"); bool teraterm = terminfo_is_term_family(term, "teraterm"); @@ -1449,8 +1450,8 @@ static void patch_terminfo_bugs(TUIData *data, const char *term, } } - if (!true_xterm) { - // Cannot trust terminfo; safer to disable BCE. #7624 + if (tmux || screen || kitty) { + // Disable BCE in some cases we know it is not working. #8806 unibi_set_bool(ut, unibi_back_color_erase, false); } -- cgit