2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2017-04-01 04:08:42 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2024-04-20 08:44:13 -07:00
|
|
|
|
|
|
|
local clear, api = n.clear, n.api
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local command = n.command
|
2017-04-01 04:08:42 -07:00
|
|
|
|
|
|
|
describe('ui/cursor', function()
|
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
screen = Screen.new(25, 5)
|
|
|
|
screen:attach()
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("'guicursor' is published as a UI event", function()
|
2017-04-18 04:42:04 -07:00
|
|
|
local expected_mode_info = {
|
|
|
|
[1] = {
|
2017-04-25 16:43:03 -07:00
|
|
|
blinkoff = 0,
|
|
|
|
blinkon = 0,
|
|
|
|
blinkwait = 0,
|
2017-04-18 04:42:04 -07:00
|
|
|
cell_percentage = 0,
|
|
|
|
cursor_shape = 'block',
|
|
|
|
name = 'normal',
|
2017-04-25 16:43:03 -07:00
|
|
|
hl_id = 0,
|
|
|
|
id_lm = 0,
|
2018-07-26 12:27:41 -07:00
|
|
|
attr = {},
|
|
|
|
attr_lm = {},
|
2017-04-01 04:08:42 -07:00
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'n',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[2] = {
|
2017-04-25 16:43:03 -07:00
|
|
|
blinkoff = 0,
|
|
|
|
blinkon = 0,
|
|
|
|
blinkwait = 0,
|
2017-04-01 04:08:42 -07:00
|
|
|
cell_percentage = 0,
|
|
|
|
cursor_shape = 'block',
|
2017-04-18 04:42:04 -07:00
|
|
|
name = 'visual',
|
2017-04-25 16:43:03 -07:00
|
|
|
hl_id = 0,
|
|
|
|
id_lm = 0,
|
2018-07-26 12:27:41 -07:00
|
|
|
attr = {},
|
|
|
|
attr_lm = {},
|
2017-04-01 04:08:42 -07:00
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'v',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[3] = {
|
2017-04-25 16:43:03 -07:00
|
|
|
blinkoff = 0,
|
|
|
|
blinkon = 0,
|
|
|
|
blinkwait = 0,
|
2017-04-18 04:42:04 -07:00
|
|
|
cell_percentage = 25,
|
|
|
|
cursor_shape = 'vertical',
|
|
|
|
name = 'insert',
|
2017-04-25 16:43:03 -07:00
|
|
|
hl_id = 0,
|
|
|
|
id_lm = 0,
|
2018-07-26 12:27:41 -07:00
|
|
|
attr = {},
|
|
|
|
attr_lm = {},
|
2017-04-01 04:08:42 -07:00
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'i',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[4] = {
|
2017-04-25 16:43:03 -07:00
|
|
|
blinkoff = 0,
|
|
|
|
blinkon = 0,
|
|
|
|
blinkwait = 0,
|
2017-04-18 04:42:04 -07:00
|
|
|
cell_percentage = 20,
|
|
|
|
cursor_shape = 'horizontal',
|
|
|
|
name = 'replace',
|
2017-04-25 16:43:03 -07:00
|
|
|
hl_id = 0,
|
|
|
|
id_lm = 0,
|
2018-07-26 12:27:41 -07:00
|
|
|
attr = {},
|
|
|
|
attr_lm = {},
|
2017-04-01 04:08:42 -07:00
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'r',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[5] = {
|
2017-04-25 16:43:03 -07:00
|
|
|
blinkoff = 0,
|
|
|
|
blinkon = 0,
|
|
|
|
blinkwait = 0,
|
2017-04-01 04:08:42 -07:00
|
|
|
cell_percentage = 0,
|
|
|
|
cursor_shape = 'block',
|
2017-04-18 04:42:04 -07:00
|
|
|
name = 'cmdline_normal',
|
2017-04-25 16:43:03 -07:00
|
|
|
hl_id = 0,
|
|
|
|
id_lm = 0,
|
2018-07-26 12:27:41 -07:00
|
|
|
attr = {},
|
|
|
|
attr_lm = {},
|
2017-04-01 04:08:42 -07:00
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'c',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[6] = {
|
2017-04-25 16:43:03 -07:00
|
|
|
blinkoff = 0,
|
|
|
|
blinkon = 0,
|
|
|
|
blinkwait = 0,
|
2017-04-18 04:42:04 -07:00
|
|
|
cell_percentage = 25,
|
|
|
|
cursor_shape = 'vertical',
|
|
|
|
name = 'cmdline_insert',
|
2017-04-25 16:43:03 -07:00
|
|
|
hl_id = 0,
|
|
|
|
id_lm = 0,
|
2018-07-26 12:27:41 -07:00
|
|
|
attr = {},
|
|
|
|
attr_lm = {},
|
2017-04-01 04:08:42 -07:00
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'ci',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[7] = {
|
2017-04-25 16:43:03 -07:00
|
|
|
blinkoff = 0,
|
|
|
|
blinkon = 0,
|
|
|
|
blinkwait = 0,
|
2017-04-01 04:08:42 -07:00
|
|
|
cell_percentage = 20,
|
|
|
|
cursor_shape = 'horizontal',
|
2017-04-18 04:42:04 -07:00
|
|
|
name = 'cmdline_replace',
|
2017-04-25 16:43:03 -07:00
|
|
|
hl_id = 0,
|
|
|
|
id_lm = 0,
|
2018-07-26 12:27:41 -07:00
|
|
|
attr = {},
|
|
|
|
attr_lm = {},
|
2017-04-01 04:08:42 -07:00
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'cr',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[8] = {
|
2017-04-25 16:43:03 -07:00
|
|
|
blinkoff = 0,
|
|
|
|
blinkon = 0,
|
|
|
|
blinkwait = 0,
|
|
|
|
cell_percentage = 20,
|
2017-04-18 04:42:04 -07:00
|
|
|
cursor_shape = 'horizontal',
|
|
|
|
name = 'operator',
|
2017-04-25 16:43:03 -07:00
|
|
|
hl_id = 0,
|
|
|
|
id_lm = 0,
|
2018-07-26 12:27:41 -07:00
|
|
|
attr = {},
|
|
|
|
attr_lm = {},
|
2017-04-01 04:08:42 -07:00
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'o',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[9] = {
|
2017-04-25 16:43:03 -07:00
|
|
|
blinkoff = 0,
|
|
|
|
blinkon = 0,
|
|
|
|
blinkwait = 0,
|
|
|
|
cell_percentage = 25,
|
2017-04-01 04:08:42 -07:00
|
|
|
cursor_shape = 'vertical',
|
2017-04-18 04:42:04 -07:00
|
|
|
name = 'visual_select',
|
2017-04-25 16:43:03 -07:00
|
|
|
hl_id = 0,
|
|
|
|
id_lm = 0,
|
2018-07-26 12:27:41 -07:00
|
|
|
attr = {},
|
|
|
|
attr_lm = {},
|
2017-04-01 04:08:42 -07:00
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 've',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[10] = {
|
|
|
|
name = 'cmdline_hover',
|
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'e',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[11] = {
|
|
|
|
name = 'statusline_hover',
|
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 's',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[12] = {
|
|
|
|
name = 'statusline_drag',
|
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'sd',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[13] = {
|
|
|
|
name = 'vsep_hover',
|
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'vs',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[14] = {
|
|
|
|
name = 'vsep_drag',
|
2017-04-01 13:32:16 -07:00
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'vd',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[15] = {
|
|
|
|
name = 'more',
|
2017-04-01 04:08:42 -07:00
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'm',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[16] = {
|
|
|
|
name = 'more_lastline',
|
|
|
|
mouse_shape = 0,
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'ml',
|
|
|
|
},
|
2017-04-18 04:42:04 -07:00
|
|
|
[17] = {
|
2017-04-25 16:43:03 -07:00
|
|
|
blinkoff = 0,
|
|
|
|
blinkon = 0,
|
|
|
|
blinkwait = 0,
|
2017-04-18 04:42:04 -07:00
|
|
|
cell_percentage = 0,
|
|
|
|
cursor_shape = 'block',
|
|
|
|
name = 'showmatch',
|
2017-04-25 16:43:03 -07:00
|
|
|
hl_id = 0,
|
|
|
|
id_lm = 0,
|
2018-07-26 12:27:41 -07:00
|
|
|
attr = {},
|
|
|
|
attr_lm = {},
|
2024-01-02 18:09:18 -07:00
|
|
|
short_name = 'sm',
|
|
|
|
},
|
|
|
|
}
|
2017-04-04 08:47:23 -07:00
|
|
|
|
|
|
|
screen:expect(function()
|
2017-04-25 16:43:03 -07:00
|
|
|
-- Default 'guicursor', published on startup.
|
2017-04-18 04:42:04 -07:00
|
|
|
eq(expected_mode_info, screen._mode_info)
|
2017-04-04 08:47:23 -07:00
|
|
|
eq(true, screen._cursor_style_enabled)
|
|
|
|
eq('normal', screen.mode)
|
|
|
|
end)
|
2017-04-01 04:08:42 -07:00
|
|
|
|
|
|
|
-- Event is published ONLY if the cursor style changed.
|
2017-04-18 04:42:04 -07:00
|
|
|
screen._mode_info = nil
|
2017-04-04 08:47:23 -07:00
|
|
|
command("echo 'test'")
|
2024-01-02 18:09:18 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
2017-04-04 08:47:23 -07:00
|
|
|
^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
2017-04-04 08:47:23 -07:00
|
|
|
test |
|
2024-01-02 18:09:18 -07:00
|
|
|
]],
|
|
|
|
condition = function()
|
|
|
|
eq(nil, screen._mode_info)
|
|
|
|
end,
|
|
|
|
}
|
2017-04-01 04:08:42 -07:00
|
|
|
|
|
|
|
-- Change the cursor style.
|
2024-04-20 08:44:13 -07:00
|
|
|
n.command('hi Cursor guibg=DarkGray')
|
|
|
|
n.command(
|
2024-01-02 18:09:18 -07:00
|
|
|
'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'
|
|
|
|
)
|
2017-04-25 16:43:03 -07:00
|
|
|
|
|
|
|
-- Update the expected values.
|
|
|
|
for _, m in ipairs(expected_mode_info) do
|
|
|
|
if m.name == 'showmatch' then
|
2024-01-02 18:09:18 -07:00
|
|
|
if m.blinkon then
|
|
|
|
m.blinkon = 175
|
|
|
|
end
|
|
|
|
if m.blinkoff then
|
|
|
|
m.blinkoff = 150
|
|
|
|
end
|
|
|
|
if m.blinkwait then
|
|
|
|
m.blinkwait = 175
|
|
|
|
end
|
2017-04-25 16:43:03 -07:00
|
|
|
else
|
2024-01-02 18:09:18 -07:00
|
|
|
if m.blinkon then
|
|
|
|
m.blinkon = 250
|
|
|
|
end
|
|
|
|
if m.blinkoff then
|
|
|
|
m.blinkoff = 400
|
|
|
|
end
|
|
|
|
if m.blinkwait then
|
|
|
|
m.blinkwait = 700
|
|
|
|
end
|
2017-04-25 16:43:03 -07:00
|
|
|
end
|
2018-07-26 12:27:41 -07:00
|
|
|
if m.hl_id then
|
2024-01-02 18:09:18 -07:00
|
|
|
m.hl_id = 64
|
|
|
|
m.attr = { background = Screen.colors.DarkGray }
|
|
|
|
end
|
|
|
|
if m.id_lm then
|
2024-06-11 09:10:34 -07:00
|
|
|
m.id_lm = 71
|
2018-07-26 12:27:41 -07:00
|
|
|
end
|
2017-04-25 16:43:03 -07:00
|
|
|
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)
|
|
|
|
|
2018-07-26 12:27:41 -07:00
|
|
|
-- Change hl groups only, should update the styles
|
2024-04-20 08:44:13 -07:00
|
|
|
n.command('hi Cursor guibg=Red')
|
|
|
|
n.command('hi lCursor guibg=Green')
|
2018-07-26 12:27:41 -07:00
|
|
|
|
|
|
|
-- Update the expected values.
|
|
|
|
for _, m in ipairs(expected_mode_info) do
|
|
|
|
if m.hl_id then
|
2024-01-02 18:09:18 -07:00
|
|
|
m.attr = { background = Screen.colors.Red }
|
2018-07-26 12:27:41 -07:00
|
|
|
end
|
|
|
|
if m.id_lm then
|
2024-01-02 18:09:18 -07:00
|
|
|
m.attr_lm = { background = Screen.colors.Green }
|
2018-07-26 12:27:41 -07:00
|
|
|
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)
|
|
|
|
|
2019-12-19 13:27:21 -07:00
|
|
|
-- update the highlight again to hide cursor
|
2024-04-20 08:44:13 -07:00
|
|
|
n.command('hi Cursor blend=100')
|
2019-12-19 13:27:21 -07:00
|
|
|
|
|
|
|
for _, m in ipairs(expected_mode_info) do
|
|
|
|
if m.hl_id then
|
2024-01-02 18:09:18 -07:00
|
|
|
m.attr = { background = Screen.colors.Red, blend = 100 }
|
2019-12-19 13:27:21 -07:00
|
|
|
end
|
|
|
|
end
|
2024-01-02 18:09:18 -07:00
|
|
|
screen:expect {
|
|
|
|
grid = [[
|
2019-12-19 13:27:21 -07:00
|
|
|
^ |
|
2024-03-22 03:02:52 -07:00
|
|
|
{1:~ }|*3
|
2019-12-19 13:27:21 -07:00
|
|
|
test |
|
2024-01-02 18:09:18 -07:00
|
|
|
]],
|
|
|
|
condition = function()
|
|
|
|
eq(expected_mode_info, screen._mode_info)
|
|
|
|
end,
|
2019-12-19 13:27:21 -07:00
|
|
|
}
|
|
|
|
|
2017-04-25 16:43:03 -07:00
|
|
|
-- Another cursor style.
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value(
|
2024-01-02 18:09:18 -07:00
|
|
|
'guicursor',
|
|
|
|
'n-v-c:ver35-blinkwait171-blinkoff172-blinkon173'
|
|
|
|
.. ',ve:hor35,o:ver50,i-ci:block,r-cr:hor90,sm:ver42',
|
|
|
|
{}
|
|
|
|
)
|
2017-04-04 08:47:23 -07:00
|
|
|
screen:expect(function()
|
2017-04-18 04:42:04 -07:00
|
|
|
local named = {}
|
|
|
|
for _, m in ipairs(screen._mode_info) do
|
|
|
|
named[m.name] = m
|
|
|
|
end
|
|
|
|
eq('vertical', named.normal.cursor_shape)
|
2017-04-25 16:43:03 -07:00
|
|
|
eq(35, named.normal.cell_percentage)
|
2017-04-18 04:42:04 -07:00
|
|
|
eq('horizontal', named.visual_select.cursor_shape)
|
2017-04-25 16:43:03 -07:00
|
|
|
eq(35, named.visual_select.cell_percentage)
|
2017-04-18 04:42:04 -07:00
|
|
|
eq('vertical', named.operator.cursor_shape)
|
2017-04-25 16:43:03 -07:00
|
|
|
eq(50, named.operator.cell_percentage)
|
2017-04-18 04:42:04 -07:00
|
|
|
eq('block', named.insert.cursor_shape)
|
|
|
|
eq('vertical', named.showmatch.cursor_shape)
|
2017-04-25 16:43:03 -07:00
|
|
|
eq(90, named.cmdline_replace.cell_percentage)
|
2017-04-18 04:42:04 -07:00
|
|
|
eq(171, named.normal.blinkwait)
|
|
|
|
eq(172, named.normal.blinkoff)
|
|
|
|
eq(173, named.normal.blinkon)
|
2017-04-25 16:43:03 -07:00
|
|
|
eq(42, named.showmatch.cell_percentage)
|
2017-04-04 08:47:23 -07:00
|
|
|
end)
|
2020-09-12 11:38:49 -07:00
|
|
|
|
|
|
|
-- If there is no setting for guicursor, it becomes the default setting.
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value(
|
2024-01-02 18:09:18 -07:00
|
|
|
'guicursor',
|
|
|
|
'n:ver35-blinkwait171-blinkoff172-blinkon173-Cursor/lCursor',
|
|
|
|
{}
|
|
|
|
)
|
2020-09-12 11:38:49 -07:00
|
|
|
screen:expect(function()
|
2024-01-02 18:09:18 -07:00
|
|
|
for _, m in ipairs(screen._mode_info) do
|
2020-09-12 11:38:49 -07:00
|
|
|
if m.name ~= 'normal' then
|
|
|
|
eq('block', m.cursor_shape or 'block')
|
|
|
|
eq(0, m.blinkon or 0)
|
|
|
|
eq(0, m.blinkoff or 0)
|
|
|
|
eq(0, m.blinkwait or 0)
|
|
|
|
eq(0, m.hl_id or 0)
|
|
|
|
eq(0, m.id_lm or 0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
2017-04-01 04:08:42 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("empty 'guicursor' sets cursor_shape=block in all modes", function()
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('guicursor', '', {})
|
2017-04-04 08:47:23 -07:00
|
|
|
screen:expect(function()
|
|
|
|
-- Empty 'guicursor' sets enabled=false.
|
|
|
|
eq(false, screen._cursor_style_enabled)
|
2017-04-18 04:42:04 -07:00
|
|
|
for _, m in ipairs(screen._mode_info) do
|
|
|
|
if m['cursor_shape'] ~= nil then
|
|
|
|
eq('block', m.cursor_shape)
|
|
|
|
eq(0, m.blinkon)
|
2020-09-12 11:38:49 -07:00
|
|
|
eq(0, m.hl_id)
|
|
|
|
eq(0, m.id_lm)
|
2017-04-18 04:42:04 -07:00
|
|
|
end
|
2017-04-04 08:47:23 -07:00
|
|
|
end
|
|
|
|
end)
|
2017-04-01 04:08:42 -07:00
|
|
|
end)
|
|
|
|
end)
|