From 2a590e2293638eb27bbedc7c5758e9241aea0a77 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 10 Sep 2019 11:17:48 +0200 Subject: bump libvterm to 0.1 + memleak patch --- third-party/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 849b66742e..9eaa75e48f 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -160,8 +160,8 @@ set(UNIBILIUM_SHA256 29815283c654277ef77a3adcc8840db79ddbb20a0f0b0c8f648bd8cd49a set(LIBTERMKEY_URL http://www.leonerd.org.uk/code/libtermkey/libtermkey-0.21.1.tar.gz) set(LIBTERMKEY_SHA256 cecbf737f35d18f433c8d7864f63c0f878af41f8bd0255a3ebb16010dc044d5f) -set(LIBVTERM_URL https://github.com/neovim/libvterm/archive/b45b648cab73f9667bde7c0c6045b285e22b3ecd.tar.gz) -set(LIBVTERM_SHA256 37cc123deff29327efa654358c2ebaaf8589da03754ca5adb8ec47be386a0433) +set(LIBVTERM_URL https://github.com/neovim/libvterm/archive/4a5fa43e0dbc0db4fe67d40d788d60852864df9e.tar.gz) +set(LIBVTERM_SHA256 49b3cf2dcb988b887671b1011cfeac98ff81bb5c23fb4ac34b91a59524992935) set(LUV_VERSION 1.30.0-0) set(LUV_URL https://github.com/luvit/luv/archive/${LUV_VERSION}.tar.gz) -- cgit From d57250ae64b61a37fbe84024be9706985186dbc1 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Sat, 12 Jan 2019 23:09:46 +0000 Subject: Changes for new VTermColor struct --- src/nvim/terminal.c | 57 +++++++++++------------------------------------------ 1 file changed, 12 insertions(+), 45 deletions(-) diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index ffa05e2599..936cf0dc0f 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -152,7 +152,6 @@ static VTermScreenCallbacks vterm_screen_callbacks = { }; static PMap(ptr_t) *invalidated_terminals; -static Map(int, int) *color_indexes; static int default_vt_fg, default_vt_bg; static VTermColor default_vt_bg_rgb; @@ -163,33 +162,13 @@ void terminal_init(void) // refresh_timer_cb will redraw the screen which can call vimscript refresh_timer.events = multiqueue_new_child(main_loop.events); - // initialize a rgb->color index map for cterm attributes(VTermScreenCell - // only has RGB information and we need color indexes for terminal UIs) - color_indexes = map_new(int, int)(); VTerm *vt = vterm_new(24, 80); VTermState *state = vterm_obtain_state(vt); - for (int color_index = 255; color_index >= 0; color_index--) { - VTermColor color; - // Some of the default 16 colors has the same color as the later - // 240 colors. To avoid collisions, we will use the custom colors - // below in non true color mode. - if (color_index < 16) { - color.red = 0; - color.green = 0; - color.blue = (uint8_t)(color_index + 1); - } else { - vterm_state_get_palette_color(state, color_index, &color); - } - map_put(int, int)(color_indexes, - RGB_(color.red, color.green, color.blue), - color_index + 1); - } - VTermColor fg, bg; vterm_state_get_default_colors(state, &fg, &bg); - default_vt_fg = RGB_(fg.red, fg.green, fg.blue); - default_vt_bg = RGB_(bg.red, bg.green, bg.blue); + default_vt_fg = RGB_(fg.rgb.red, fg.rgb.green, fg.rgb.blue); + default_vt_bg = RGB_(bg.rgb.red, bg.rgb.green, bg.rgb.blue); default_vt_bg_rgb = bg; vterm_free(vt); } @@ -200,7 +179,6 @@ void terminal_teardown(void) multiqueue_free(refresh_timer.events); time_watcher_close(&refresh_timer, NULL); pmap_free(ptr_t)(invalidated_terminals); - map_free(int, int)(color_indexes); } // public API {{{ @@ -256,15 +234,6 @@ Terminal *terminal_open(TerminalOptions opts) rv->sb_buffer = xmalloc(sizeof(ScrollbackLine *) * rv->sb_size); if (!true_color) { - // Change the first 16 colors so we can easily get the correct color - // index from them. - for (int i = 0; i < 16; i++) { - VTermColor color; - color.red = 0; - color.green = 0; - color.blue = (uint8_t)(i + 1); - vterm_state_set_palette_color(state, i, &color); - } return rv; } @@ -286,9 +255,10 @@ Terminal *terminal_open(TerminalOptions opts) if (color_val != -1) { VTermColor color; - color.red = (uint8_t)((color_val >> 16) & 0xFF); - color.green = (uint8_t)((color_val >> 8) & 0xFF); - color.blue = (uint8_t)((color_val >> 0) & 0xFF); + vterm_color_rgb(&color, + (uint8_t)(color_val >> 16) & 0xFF, + (uint8_t)(color_val >> 8) & 0xFF, + (uint8_t)(color_val >> 0) & 0xFF); vterm_state_set_palette_color(state, i, &color); } } @@ -630,17 +600,14 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, VTermScreenCell cell; fetch_cell(term, row, col, &cell); // Get the rgb value set by libvterm. - int vt_fg = RGB_(cell.fg.red, cell.fg.green, cell.fg.blue); - int vt_bg = RGB_(cell.bg.red, cell.bg.green, cell.bg.blue); + int vt_fg = RGB_(cell.fg.rgb.red, cell.fg.rgb.green, cell.fg.rgb.blue); + int vt_bg = RGB_(cell.bg.rgb.red, cell.bg.rgb.green, cell.bg.rgb.blue); vt_fg = vt_fg != default_vt_fg ? vt_fg : - 1; vt_bg = vt_bg != default_vt_bg ? vt_bg : - 1; - // Since libvterm does not expose the color index used by the program, we - // use the rgb value to find the appropriate index in the cache computed by - // `terminal_init`. - int vt_fg_idx = vt_fg != -1 ? - map_get(int, int)(color_indexes, vt_fg) : 0; - int vt_bg_idx = vt_bg != -1 ? - map_get(int, int)(color_indexes, vt_bg) : 0; + int vt_fg_idx = VTERM_COLOR_IS_DEFAULT_FG(&cell.fg) ? 0 : + VTERM_COLOR_IS_INDEXED(&cell.fg) ? cell.fg.indexed.idx + 1 : 0; + int vt_bg_idx = VTERM_COLOR_IS_DEFAULT_BG(&cell.bg) ? 0 : + VTERM_COLOR_IS_INDEXED(&cell.bg) ? cell.bg.indexed.idx + 1 : 0; int hl_attrs = (cell.attrs.bold ? HL_BOLD : 0) | (cell.attrs.italic ? HL_ITALIC : 0) -- cgit From 0bb466f0fcf4eb0915c6b2dd6abbb8cc7fb1c51d Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 23 Jun 2019 01:13:56 +0200 Subject: lint / test grouping --- src/nvim/terminal.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 936cf0dc0f..383ddebe34 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -256,9 +256,9 @@ Terminal *terminal_open(TerminalOptions opts) if (color_val != -1) { VTermColor color; vterm_color_rgb(&color, - (uint8_t)(color_val >> 16) & 0xFF, - (uint8_t)(color_val >> 8) & 0xFF, - (uint8_t)(color_val >> 0) & 0xFF); + (uint8_t)((color_val >> 16) & 0xFF), + (uint8_t)((color_val >> 8) & 0xFF), + (uint8_t)((color_val >> 0) & 0xFF)); vterm_state_set_palette_color(state, i, &color); } } @@ -604,10 +604,12 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, int vt_bg = RGB_(cell.bg.rgb.red, cell.bg.rgb.green, cell.bg.rgb.blue); vt_fg = vt_fg != default_vt_fg ? vt_fg : - 1; vt_bg = vt_bg != default_vt_bg ? vt_bg : - 1; - int vt_fg_idx = VTERM_COLOR_IS_DEFAULT_FG(&cell.fg) ? 0 : - VTERM_COLOR_IS_INDEXED(&cell.fg) ? cell.fg.indexed.idx + 1 : 0; - int vt_bg_idx = VTERM_COLOR_IS_DEFAULT_BG(&cell.bg) ? 0 : - VTERM_COLOR_IS_INDEXED(&cell.bg) ? cell.bg.indexed.idx + 1 : 0; + int vt_fg_idx = VTERM_COLOR_IS_DEFAULT_FG(&cell.fg) + ? 0 : VTERM_COLOR_IS_INDEXED(&cell.fg) + ? cell.fg.indexed.idx + 1 : 0; + int vt_bg_idx = VTERM_COLOR_IS_DEFAULT_BG(&cell.bg) + ? 0 : VTERM_COLOR_IS_INDEXED(&cell.bg) + ? cell.bg.indexed.idx + 1 : 0; int hl_attrs = (cell.attrs.bold ? HL_BOLD : 0) | (cell.attrs.italic ? HL_ITALIC : 0) -- cgit From e11dd1110fd018d9bd6d42460186ed69037f8651 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 9 Sep 2019 22:06:49 +0200 Subject: terminal: fix rgb rendering of palette colors simplify handling of default colors nvim is always true color internally, remove ui_rgb_attached() check. Fix "runtime termguicolors" test. The test actually reflected broken behavior in (parent) nvim: nvim_ui_set_option("rgb", true) was not respected by existing :terminal instances, so all 16-palette colors became dark blue. --- src/nvim/terminal.c | 56 +++++++++++++++-------------------- test/functional/terminal/tui_spec.lua | 6 ++-- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 383ddebe34..dfee11c468 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -152,8 +152,6 @@ static VTermScreenCallbacks vterm_screen_callbacks = { }; static PMap(ptr_t) *invalidated_terminals; -static int default_vt_fg, default_vt_bg; -static VTermColor default_vt_bg_rgb; void terminal_init(void) { @@ -161,16 +159,6 @@ void terminal_init(void) time_watcher_init(&main_loop, &refresh_timer, NULL); // refresh_timer_cb will redraw the screen which can call vimscript refresh_timer.events = multiqueue_new_child(main_loop.events); - - VTerm *vt = vterm_new(24, 80); - VTermState *state = vterm_obtain_state(vt); - - VTermColor fg, bg; - vterm_state_get_default_colors(state, &fg, &bg); - default_vt_fg = RGB_(fg.rgb.red, fg.rgb.green, fg.rgb.blue); - default_vt_bg = RGB_(bg.rgb.red, bg.rgb.green, bg.rgb.blue); - default_vt_bg_rgb = bg; - vterm_free(vt); } void terminal_teardown(void) @@ -185,7 +173,6 @@ void terminal_teardown(void) Terminal *terminal_open(TerminalOptions opts) { - bool true_color = ui_rgb_attached(); // Create a new terminal instance and configure it Terminal *rv = xcalloc(1, sizeof(Terminal)); rv->opts = opts; @@ -233,10 +220,6 @@ Terminal *terminal_open(TerminalOptions opts) rv->sb_size = (size_t)curbuf->b_p_scbk; rv->sb_buffer = xmalloc(sizeof(ScrollbackLine *) * rv->sb_size); - if (!true_color) { - return rv; - } - vterm_state_set_bold_highbright(state, true); // Configure the color palette. Try to get the color from: @@ -583,11 +566,19 @@ void terminal_receive(Terminal *term, char *data, size_t len) vterm_screen_flush_damage(term->vts); } +static int get_rgb(VTermState *state, VTermColor color) +{ + vterm_state_convert_color_to_rgb(state, &color); + return RGB_(color.rgb.red, color.rgb.green, color.rgb.blue); +} + + void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, int *term_attrs) { int height, width; vterm_get_size(term->vt, &height, &width); + VTermState *state = vterm_obtain_state(term->vt); assert(linenr); int row = linenr_to_row(term, linenr); if (row >= height) { @@ -598,18 +589,18 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, for (int col = 0; col < width; col++) { VTermScreenCell cell; - fetch_cell(term, row, col, &cell); + bool color_valid = fetch_cell(term, row, col, &cell); + bool fg_default = !color_valid || VTERM_COLOR_IS_DEFAULT_FG(&cell.fg); + bool bg_default = !color_valid || VTERM_COLOR_IS_DEFAULT_BG(&cell.bg); + // Get the rgb value set by libvterm. - int vt_fg = RGB_(cell.fg.rgb.red, cell.fg.rgb.green, cell.fg.rgb.blue); - int vt_bg = RGB_(cell.bg.rgb.red, cell.bg.rgb.green, cell.bg.rgb.blue); - vt_fg = vt_fg != default_vt_fg ? vt_fg : - 1; - vt_bg = vt_bg != default_vt_bg ? vt_bg : - 1; - int vt_fg_idx = VTERM_COLOR_IS_DEFAULT_FG(&cell.fg) - ? 0 : VTERM_COLOR_IS_INDEXED(&cell.fg) - ? cell.fg.indexed.idx + 1 : 0; - int vt_bg_idx = VTERM_COLOR_IS_DEFAULT_BG(&cell.bg) - ? 0 : VTERM_COLOR_IS_INDEXED(&cell.bg) - ? cell.bg.indexed.idx + 1 : 0; + int vt_fg = fg_default ? -1 : get_rgb(state, cell.fg); + int vt_bg = bg_default ? -1 : get_rgb(state, cell.bg); + + int vt_fg_idx = ((!fg_default && VTERM_COLOR_IS_INDEXED(&cell.fg)) + ? cell.fg.indexed.idx + 1 : 0); + int vt_bg_idx = ((!bg_default && VTERM_COLOR_IS_INDEXED(&cell.bg)) + ? cell.bg.indexed.idx + 1 : 0); int hl_attrs = (cell.attrs.bold ? HL_BOLD : 0) | (cell.attrs.italic ? HL_ITALIC : 0) @@ -618,7 +609,7 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr, int attr_id = 0; - if (hl_attrs || vt_fg != -1 || vt_bg != -1) { + if (hl_attrs ||!fg_default || !bg_default) { attr_id = hl_get_term_attr(&(HlAttrs) { .cterm_ae_attr = (int16_t)hl_attrs, .cterm_fg_color = vt_fg_idx, @@ -1082,8 +1073,8 @@ static void fetch_row(Terminal *term, int row, int end_col) term->textbuf[line_len] = 0; } -static void fetch_cell(Terminal *term, int row, int col, - VTermScreenCell *cell) +static bool fetch_cell(Terminal *term, int row, int col, + VTermScreenCell *cell) { if (row < 0) { ScrollbackLine *sbrow = term->sb_buffer[-row - 1]; @@ -1094,13 +1085,14 @@ static void fetch_cell(Terminal *term, int row, int col, *cell = (VTermScreenCell) { .chars = { 0 }, .width = 1, - .bg = default_vt_bg_rgb }; + return false; } } else { vterm_screen_get_cell(term->vts, (VTermPos){.row = row, .col = col}, cell); } + return true; } // queue a terminal instance for refresh diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 5bd39c72f3..3d9623a158 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -640,11 +640,11 @@ describe('TUI', function() screen:set_option('rgb', true) screen:set_default_attr_ids({ [1] = {reverse = true}, - [2] = {foreground = 13}, + [2] = {foreground = tonumber('0x4040ff')}, [3] = {bold = true, reverse = true}, [4] = {bold = true}, - [5] = {reverse = true, foreground = 4}, - [6] = {foreground = 4}, + [5] = {reverse = true, foreground = tonumber('0xe0e000')}, + [6] = {foreground = tonumber('0xe0e000')}, [7] = {reverse = true, foreground = Screen.colors.SeaGreen4}, [8] = {foreground = Screen.colors.SeaGreen4}, [9] = {bold = true, foreground = Screen.colors.Blue1}, -- cgit