aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2017-04-30 14:36:40 +0200
committerGitHub <noreply@github.com>2017-04-30 14:36:40 +0200
commit4afc93b926dc14365db4bad4cd4030d5d5a69747 (patch)
treef3d8be1c04a86dd576b6f238d408bac923169a41
parent26a479ae41135a6efc6a77bb72ccb5a3c092fce9 (diff)
parentc1d3bcc1842d7ca4edb514ef162696afd910f532 (diff)
downloadrneovim-4afc93b926dc14365db4bad4cd4030d5d5a69747.tar.gz
rneovim-4afc93b926dc14365db4bad4cd4030d5d5a69747.tar.bz2
rneovim-4afc93b926dc14365db4bad4cd4030d5d5a69747.zip
Merge #6588 from justinmk/guicursor
-rw-r--r--runtime/doc/options.txt36
-rw-r--r--src/nvim/cursor_shape.c6
-rw-r--r--src/nvim/options.lua2
-rw-r--r--src/nvim/tui/tui.c29
-rw-r--r--test/functional/ui/cursor_spec.lua141
5 files changed, 122 insertions, 92 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 93ab956471..d3683f5135 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -2756,23 +2756,24 @@ A jump table for the options with a short description can be found at |Q_op|.
security reasons.
*'guicursor'* *'gcr'* *E545* *E546* *E548* *E549*
-'guicursor' 'gcr' string (default "n-v-c:block-Cursor/lCursor,
- ve:ver35-Cursor,
- o:hor50-Cursor,
- i-ci:ver25-Cursor/lCursor,
- r-cr:hor20-Cursor/lCursor,
- sm:block-Cursor
- -blinkwait175-blinkoff150-blinkon175")
+'guicursor' 'gcr' string (default "n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20")
global
Configures the cursor style for each mode. Works in the GUI and some
- terminals. Unset to disable: >
- :set guicursor=
-<
+ terminals.
+
With tmux you might need this in ~/.tmux.conf (see terminal-overrides
in the tmux(1) manual page): >
set -ga terminal-overrides ',*:Ss=\E[%p1%d q:Se=\E[2 q'
-<
- The option is a comma separated list of parts. Each part consists of a
+
+< To disable cursor-styling, reset the option: >
+ :set guicursor=
+
+< To enable mode shapes, "Cursor" highlight, and blinking: >
+ :set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
+ \,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor
+ \,sm:block-blinkwait175-blinkoff150-blinkon175
+
+< The option is a comma separated list of parts. Each part consists of a
mode-list and an argument-list:
mode-list:argument-list,mode-list:argument-list,..
The mode-list is a dash separated list of these modes:
@@ -2800,14 +2801,9 @@ A jump table for the options with a short description can be found at |Q_op|.
the cursor starts blinking, blinkon is the time that
the cursor is shown and blinkoff is the time that the
cursor is not shown. The times are in msec. When one
- of the numbers is zero, there is no blinking. The
- default is: "blinkwait700-blinkon400-blinkoff250".
- These numbers are used for a missing entry. This
- means that blinking is enabled by default. To switch
- blinking off you can use "blinkon0". The cursor only
- blinks when Vim is waiting for input, not while
- executing a command.
- {group-name}
+ of the numbers is zero, there is no blinking. E.g.: >
+ :set guicursor=n:blinkon0
+< {group-name}
a highlight group name, that sets the color and font
for the cursor
{group-name}/{group-name}
diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c
index dcc680f806..e302d5aa4c 100644
--- a/src/nvim/cursor_shape.c
+++ b/src/nvim/cursor_shape.c
@@ -142,9 +142,9 @@ char_u *parse_shape_opt(int what)
{
// Set the defaults, for the missing parts
shape_table[idx].shape = SHAPE_BLOCK;
- shape_table[idx].blinkwait = 700L;
- shape_table[idx].blinkon = 400L;
- shape_table[idx].blinkoff = 250L;
+ shape_table[idx].blinkwait = 0L;
+ shape_table[idx].blinkon = 0L;
+ shape_table[idx].blinkoff = 0L;
}
}
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 4e7be63b63..ba7bf5bafb 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -1000,7 +1000,7 @@ return {
deny_duplicates=true,
vi_def=true,
varname='p_guicursor',
- defaults={if_true={vi="n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"}}
+ defaults={if_true={vi="n-v-c-sm:block,i-ci-ve:ver25,r-cr-o:hor20"}}
},
{
full_name='guifont', abbreviation='gfn',
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c
index 5653924154..522f7d59f2 100644
--- a/src/nvim/tui/tui.c
+++ b/src/nvim/tui/tui.c
@@ -44,6 +44,7 @@
#define TOO_MANY_EVENTS 1000000
#define STARTS_WITH(str, prefix) (!memcmp(str, prefix, sizeof(prefix) - 1))
+#define TMUX_WRAP(seq) (is_tmux ? "\x1bPtmux;\x1b" seq "\x1b\\" : seq)
typedef enum TermType {
kTermUnknown,
@@ -95,6 +96,7 @@ typedef struct {
static bool volatile got_winch = false;
static bool cursor_style_enabled = false;
+static bool is_tmux = false;
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "tui/tui.c.generated.h"
@@ -545,13 +547,20 @@ static void tui_set_mode(UI *ui, ModeShape mode)
TUIData *data = ui->data;
cursorentry_T c = data->cursor_shapes[mode];
int shape = c.shape;
- bool is_tmux = os_getenv("TMUX") != NULL;
unibi_var_t vars[26 + 26] = { { 0 } };
-# define TMUX_WRAP(seq) (is_tmux ? "\x1bPtmux;\x1b" seq "\x1b\\" : seq)
// Support changing cursor shape on some popular terminals.
const char *vte_version = os_getenv("VTE_VERSION");
+ if (c.id != 0 && ui->rgb) {
+ int attr = syn_id2attr(c.id);
+ if (attr > 0) {
+ attrentry_T *aep = syn_cterm_attr2entry(attr);
+ data->params[0].i = aep->rgb_bg_color;
+ unibi_out(ui, data->unibi_ext.set_cursor_color);
+ }
+ }
+
if (data->term == kTermKonsole) {
// Konsole uses a proprietary escape code to set the cursor shape
// and does not support DECSCUSR.
@@ -575,23 +584,14 @@ static void tui_set_mode(UI *ui, ModeShape mode)
switch (shape) {
case SHAPE_BLOCK: shape = 1; break;
- case SHAPE_VER: shape = 5; break;
case SHAPE_HOR: shape = 3; break;
+ case SHAPE_VER: shape = 5; break;
default: WLOG("Unknown shape value %d", shape); break;
}
- data->params[0].i = shape + (c.blinkon ==0);
+ data->params[0].i = shape + (int)(c.blinkon == 0);
unibi_format(vars, vars + 26, "\x1b[%p1%d q",
data->params, out, ui, NULL, NULL);
}
-
- if (c.id != 0 && ui->rgb) {
- int attr = syn_id2attr(c.id);
- if (attr > 0) {
- attrentry_T *aep = syn_cterm_attr2entry(attr);
- data->params[0].i = aep->rgb_bg_color;
- unibi_out(ui, data->unibi_ext.set_cursor_color);
- }
- }
}
/// @param mode editor mode
@@ -952,6 +952,7 @@ static TermType detect_term(const char *term, const char *colorterm)
static void fix_terminfo(TUIData *data)
{
unibi_term *ut = data->ut;
+ is_tmux = os_getenv("TMUX") != NULL;
const char *term = os_getenv("TERM");
const char *colorterm = os_getenv("COLORTERM");
@@ -1019,7 +1020,7 @@ end:
// Fill some empty slots with common terminal strings
if (data->term == kTermiTerm) {
data->unibi_ext.set_cursor_color = (int)unibi_add_ext_str(
- ut, NULL, "\033]Pl%p1%06x\033\\");
+ ut, NULL, TMUX_WRAP("\033]Pl%p1%06x\033\\"));
} else {
data->unibi_ext.set_cursor_color = (int)unibi_add_ext_str(
ut, NULL, "\033]12;#%p1%06x\007");
diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua
index abe0e0b1fd..e6036a6b79 100644
--- a/test/functional/ui/cursor_spec.lua
+++ b/test/functional/ui/cursor_spec.lua
@@ -20,102 +20,102 @@ describe('ui/cursor', function()
it("'guicursor' is published as a UI event", function()
local expected_mode_info = {
[1] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 0,
cursor_shape = 'block',
name = 'normal',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'n' },
[2] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 0,
cursor_shape = 'block',
name = 'visual',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'v' },
[3] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 25,
cursor_shape = 'vertical',
name = 'insert',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'i' },
[4] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 20,
cursor_shape = 'horizontal',
name = 'replace',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'r' },
[5] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 0,
cursor_shape = 'block',
name = 'cmdline_normal',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'c' },
[6] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 25,
cursor_shape = 'vertical',
name = 'cmdline_insert',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'ci' },
[7] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 20,
cursor_shape = 'horizontal',
name = 'cmdline_replace',
- hl_id = 46,
- id_lm = 47,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'cr' },
[8] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
- cell_percentage = 50,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
+ cell_percentage = 20,
cursor_shape = 'horizontal',
name = 'operator',
- hl_id = 46,
- id_lm = 46,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 'o' },
[9] = {
- blinkoff = 250,
- blinkon = 400,
- blinkwait = 700,
- cell_percentage = 35,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
+ cell_percentage = 25,
cursor_shape = 'vertical',
name = 'visual_select',
- hl_id = 46,
- id_lm = 46,
+ hl_id = 0,
+ id_lm = 0,
mouse_shape = 0,
short_name = 've' },
[10] = {
@@ -147,19 +147,19 @@ describe('ui/cursor', function()
mouse_shape = 0,
short_name = 'ml' },
[17] = {
- blinkoff = 150,
- blinkon = 175,
- blinkwait = 175,
+ blinkoff = 0,
+ blinkon = 0,
+ blinkwait = 0,
cell_percentage = 0,
cursor_shape = 'block',
name = 'showmatch',
- hl_id = 46,
- id_lm = 46,
+ hl_id = 0,
+ id_lm = 0,
short_name = 'sm' },
}
screen:expect(function()
- -- Default 'guicursor' published on startup.
+ -- Default 'guicursor', published on startup.
eq(expected_mode_info, screen._mode_info)
eq(true, screen._cursor_style_enabled)
eq('normal', screen.mode)
@@ -179,20 +179,53 @@ describe('ui/cursor', function()
end)
-- Change the 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')
+ helpers.command('set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr-o:hor20'
+ ..',a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor'
+ ..',sm:block-blinkwait175-blinkoff150-blinkon175')
+
+ -- Update the expected values.
+ for _, m in ipairs(expected_mode_info) do
+ if m.name == 'showmatch' then
+ if m.blinkon then m.blinkon = 175 end
+ if m.blinkoff then m.blinkoff = 150 end
+ if m.blinkwait then m.blinkwait = 175 end
+ else
+ if m.blinkon then m.blinkon = 250 end
+ if m.blinkoff then m.blinkoff = 400 end
+ if m.blinkwait then m.blinkwait = 700 end
+ end
+ if m.hl_id then m.hl_id = 46 end
+ if m.id_lm then m.id_lm = 47 end
+ end
+
+ -- Assert the new expectation.
+ screen:expect(function()
+ eq(expected_mode_info, screen._mode_info)
+ eq(true, screen._cursor_style_enabled)
+ eq('normal', screen.mode)
+ 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')
screen:expect(function()
local named = {}
for _, m in ipairs(screen._mode_info) do
named[m.name] = m
end
eq('vertical', named.normal.cursor_shape)
+ eq(35, named.normal.cell_percentage)
eq('horizontal', named.visual_select.cursor_shape)
+ eq(35, named.visual_select.cell_percentage)
eq('vertical', named.operator.cursor_shape)
+ eq(50, named.operator.cell_percentage)
eq('block', named.insert.cursor_shape)
eq('vertical', named.showmatch.cursor_shape)
+ eq(90, named.cmdline_replace.cell_percentage)
eq(171, named.normal.blinkwait)
eq(172, named.normal.blinkoff)
eq(173, named.normal.blinkon)
+ eq(42, named.showmatch.cell_percentage)
end)
end)