Merge pull request #8806 from bfredl/bce

tui: fix resize and use BCE more often
This commit is contained in:
Björn Linse 2018-08-15 13:02:20 +02:00 committed by GitHub
commit b5cfac0894
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,6 +88,7 @@ typedef struct {
bool cont_received; bool cont_received;
UGrid grid; UGrid grid;
kvec_t(Rect) invalid_regions; kvec_t(Rect) invalid_regions;
bool did_resize;
int row, col; int row, col;
int out_fd; int out_fd;
bool scroll_region_is_full_screen; bool scroll_region_is_full_screen;
@ -95,6 +96,7 @@ typedef struct {
bool can_set_lr_margin; bool can_set_lr_margin;
bool can_set_left_right_margin; bool can_set_left_right_margin;
bool immediate_wrap_after_last_column; bool immediate_wrap_after_last_column;
bool bce;
bool mouse_enabled; bool mouse_enabled;
bool busy, is_invisible; bool busy, is_invisible;
bool cork, overflow; bool cork, overflow;
@ -236,6 +238,7 @@ static void terminfo_start(UI *ui)
data->immediate_wrap_after_last_column = data->immediate_wrap_after_last_column =
terminfo_is_term_family(term, "cygwin") terminfo_is_term_family(term, "cygwin")
|| terminfo_is_term_family(term, "interix"); || 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->normlen = unibi_pre_fmt_str(data, unibi_cursor_normal,
data->norm, sizeof data->norm); data->norm, sizeof data->norm);
data->invislen = unibi_pre_fmt_str(data, unibi_cursor_invisible, data->invislen = unibi_pre_fmt_str(data, unibi_cursor_invisible,
@ -435,6 +438,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) static void update_attrs(UI *ui, HlAttrs attrs)
{ {
TUIData *data = ui->data; TUIData *data = ui->data;
@ -597,8 +606,6 @@ static void cursor_goto(UI *ui, int row, int col)
if (row == grid->row && col == grid->col) { if (row == grid->row && col == grid->col) {
return; return;
} }
grid->row = row;
grid->col = col;
if (0 == row && 0 == col) { if (0 == row && 0 == col) {
unibi_out(ui, unibi_cursor_home); unibi_out(ui, unibi_cursor_home);
ugrid_goto(grid, row, col); ugrid_goto(grid, row, col);
@ -693,10 +700,11 @@ static void clear_region(UI *ui, int top, int bot, int left, int right,
UGrid *grid = &data->grid; UGrid *grid = &data->grid;
bool cleared = false; bool cleared = false;
// TODO(bfredl): support BCE for non-default background
bool nobg = ui->rgb ? attrs.rgb_bg_color == -1 // non-BCE terminals can't clear with non-default background color
: attrs.cterm_bg_color == 0; bool can_clear = data->bce || no_bg(ui, attrs);
if (nobg && right == ui->width -1) {
if (can_clear && right == ui->width -1) {
// Background is set to the default color and the right edge matches the // 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. // screen end, try to use terminal codes for clearing the requested area.
update_attrs(ui, attrs); update_attrs(ui, attrs);
@ -729,6 +737,14 @@ static void clear_region(UI *ui, int top, int bot, int left, int right,
cursor_goto(ui, row, col); cursor_goto(ui, row, col);
print_cell(ui, cell); 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 // restore cursor
@ -804,6 +820,7 @@ static void tui_grid_resize(UI *ui, Integer g, Integer width, Integer height)
TUIData *data = ui->data; TUIData *data = ui->data;
UGrid *grid = &data->grid; UGrid *grid = &data->grid;
ugrid_resize(grid, (int)width, (int)height); ugrid_resize(grid, (int)width, (int)height);
data->did_resize = true;
// resize might not always be followed by a clear before flush // resize might not always be followed by a clear before flush
// so clip the invalid region // so clip the invalid region
@ -984,18 +1001,13 @@ static void tui_grid_scroll(UI *ui, Integer g, Integer top, Integer bot,
ugrid_scroll(grid, (int)rows, &clear_top, &clear_bot); ugrid_scroll(grid, (int)rows, &clear_top, &clear_bot);
if (can_use_scroll(ui)) { 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 // Change terminal scroll region and move cursor to the top
if (!data->scroll_region_is_full_screen) { if (!data->scroll_region_is_full_screen) {
set_scroll_region(ui); set_scroll_region(ui);
} }
cursor_goto(ui, grid->top, grid->left); cursor_goto(ui, grid->top, grid->left);
// also set default color attributes or some terminals can become funny // 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 > 0) {
if (rows == 1) { if (rows == 1) {
@ -1019,7 +1031,7 @@ static void tui_grid_scroll(UI *ui, Integer g, Integer top, Integer bot,
} }
cursor_goto(ui, data->row, data->col); 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 // Scrolling will leave wrong background in the cleared area on non-BCE
// terminals. Update the cleared area. // terminals. Update the cleared area.
clear_region(ui, clear_top, clear_bot, grid->left, grid->right, clear_region(ui, clear_top, clear_bot, grid->left, grid->right,
@ -1382,6 +1394,7 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
bool roxterm = !!os_getenv("ROXTERM_ID"); bool roxterm = !!os_getenv("ROXTERM_ID");
#endif #endif
bool xterm = terminfo_is_term_family(term, "xterm"); 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 linuxvt = terminfo_is_term_family(term, "linux");
bool rxvt = terminfo_is_term_family(term, "rxvt"); bool rxvt = terminfo_is_term_family(term, "rxvt");
bool teraterm = terminfo_is_term_family(term, "teraterm"); bool teraterm = terminfo_is_term_family(term, "teraterm");
@ -1437,8 +1450,8 @@ static void patch_terminfo_bugs(TUIData *data, const char *term,
} }
} }
if (!true_xterm) { if (tmux || screen || kitty) {
// Cannot trust terminfo; safer to disable BCE. #7624 // Disable BCE in some cases we know it is not working. #8806
unibi_set_bool(ut, unibi_back_color_erase, false); unibi_set_bool(ut, unibi_back_color_erase, false);
} }