diff options
author | Matthieu Coudron <coudron@iij.ad.jp> | 2019-12-19 21:27:21 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2019-12-19 12:27:21 -0800 |
commit | 65aca4d857ab9ff278f410b17ef31d91e48a37b7 (patch) | |
tree | 9ccdeede16c5f8c2c19d08df49e544232098a583 | |
parent | 486ddb6eb706575e3af35c4db5b0d3fbe2095545 (diff) | |
download | rneovim-65aca4d857ab9ff278f410b17ef31d91e48a37b7.tar.gz rneovim-65aca4d857ab9ff278f410b17ef31d91e48a37b7.tar.bz2 rneovim-65aca4d857ab9ff278f410b17ef31d91e48a37b7.zip |
TUI: can make the cursor transparent #11519
when setting 'guicursor' highlight blend=100.
-rw-r--r-- | runtime/doc/term.txt | 2 | ||||
-rw-r--r-- | runtime/doc/ui.txt | 3 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 19 | ||||
-rw-r--r-- | test/functional/ui/cursor_spec.lua | 19 |
4 files changed, 36 insertions, 7 deletions
diff --git a/runtime/doc/term.txt b/runtime/doc/term.txt index 4f4d379f01..6a271c08d3 100644 --- a/runtime/doc/term.txt +++ b/runtime/doc/term.txt @@ -149,6 +149,8 @@ Nvim will adjust the shape of the cursor from a block to a line when in insert mode (or as specified by the 'guicursor' option), on terminals that support it. It uses the same |terminfo| extensions that were pioneered by tmux for this: "Ss" and "Se". +Similarly, if you set the cursor highlight group with blend=100, Nvim hides +the cursor through the "cvvis" and "civis" extensions. If your terminfo definition is missing them, then Nvim will decide whether to add them to your terminfo definition, by looking at $TERM and other diff --git a/runtime/doc/ui.txt b/runtime/doc/ui.txt index d5f4a59ab3..de54ce59b6 100644 --- a/runtime/doc/ui.txt +++ b/runtime/doc/ui.txt @@ -294,7 +294,8 @@ numerical highlight ids to the actual attributes. `underline`: underlined text. The line has `special` color. `undercurl`: undercurled text. The curl has `special` color. `blend`: Blend level (0-100). Could be used by UIs to support - blending floating windows to the background. + blending floating windows to the background or to + signal a transparent cursor. For absent color keys the default color should be used. Don't store the default value in the table, rather a sentinel value, so that diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 60e1353000..e168cf079a 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -100,7 +100,7 @@ typedef struct { bool immediate_wrap_after_last_column; bool bce; bool mouse_enabled; - bool busy, is_invisible; + bool busy, is_invisible, want_invisible; bool cork, overflow; bool cursor_color_changed; bool is_starting; @@ -198,6 +198,7 @@ static void terminfo_start(UI *ui) data->default_attr = false; data->can_clear_attr = false; data->is_invisible = true; + data->want_invisible = false; data->busy = false; data->cork = false; data->overflow = false; @@ -1032,7 +1033,11 @@ static void tui_set_mode(UI *ui, ModeShape mode) if (c.id != 0 && c.id < (int)kv_size(data->attrs) && ui->rgb) { HlAttrs aep = kv_A(data->attrs, c.id); - if (aep.rgb_ae_attr & HL_INVERSE) { + + data->want_invisible = aep.hl_blend == 100; + if (data->want_invisible) { + unibi_out(ui, unibi_cursor_invisible); + } else if (aep.rgb_ae_attr & HL_INVERSE) { // We interpret "inverse" as "default" (no termcode for "inverse"...). // Hopefully the user's default cursor color is inverse. unibi_out_ext(ui, data->unibi_ext.reset_cursor_color); @@ -1980,10 +1985,12 @@ static void flush_buf(UI *ui) assert(data->is_invisible); // not busy and the cursor is invisible. Write a "cursor normal" command // after writing the buffer. - bufp->base = data->norm; - bufp->len = UV_BUF_LEN(data->normlen); - bufp++; - data->is_invisible = data->busy; + if (!data->want_invisible) { + bufp->base = data->norm; + bufp->len = UV_BUF_LEN(data->normlen); + bufp++; + } + data->is_invisible = false; } uv_write(&req, STRUCT_CAST(uv_stream_t, &data->output_handle), diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index 8ad4182f41..6c913124ac 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -245,6 +245,25 @@ describe('ui/cursor', function() eq('normal', screen.mode) end) + -- update the highlight again to hide cursor + helpers.command('hi Cursor blend=100') + + for _, m in ipairs(expected_mode_info) do + if m.hl_id then + m.attr = {background = Screen.colors.Red, blend = 100} + end + end + screen:expect{grid=[[ + ^ | + ~ | + ~ | + ~ | + test | + ]], condition=function() + eq(expected_mode_info, screen._mode_info) + end + } + -- Another cursor style. meths.set_option('guicursor', 'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173' ..',ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42') |