neovim/test/functional/ui/embed_spec.lua

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

287 lines
8.9 KiB
Lua
Raw Normal View History

local uv = vim.uv
2022-04-22 11:56:31 -07:00
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local feed = helpers.feed
local eq = helpers.eq
local neq = helpers.neq
local clear = helpers.clear
local ok = helpers.ok
local fn = helpers.fn
local nvim_prog = helpers.nvim_prog
local retry = helpers.retry
2018-09-28 05:19:37 -07:00
local function test_embed(ext_linegrid)
local screen
local function startup(...)
2024-01-02 18:09:18 -07:00
clear { args_rm = { '--headless' }, args = { ... } }
-- attach immediately after startup, for early UI
screen = Screen.new(60, 8)
2024-01-02 18:09:18 -07:00
screen:attach { ext_linegrid = ext_linegrid }
screen:set_default_attr_ids({
2024-01-02 18:09:18 -07:00
[1] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
[2] = { bold = true, foreground = Screen.colors.SeaGreen4 },
[3] = { bold = true, foreground = Screen.colors.Blue1 },
[4] = { bold = true, foreground = Screen.colors.Green },
[5] = { bold = true, reverse = true },
[6] = { foreground = Screen.colors.NvimLightGrey3, background = Screen.colors.NvimDarkGrey3 },
2024-01-02 18:09:18 -07:00
[7] = { foreground = Screen.colors.NvimDarkRed },
[8] = { foreground = Screen.colors.NvimDarkCyan },
})
end
it('can display errors', function()
startup('--cmd', 'echoerr invalid+')
screen:expect([[
|*4
feat(highlight): update default color scheme Problem: Default color scheme is suboptimal. Solution: Start using new color scheme. Introduce new `vim` color scheme for opt-in backward compatibility. ------ Main design ideas - Be "Neovim branded". - Be minimal for 256 colors with a bit more shades for true colors. - Be accessible through high enough contrast ratios. - Be suitable for dark and light backgrounds via exchange of dark and light palettes. ------ Palettes - Have dark and light variants. Implemented through exporeted `NvimDark*` and `NvimLight*` hex colors. - Palettes have 4 shades of grey for UI elements and 6 colors (red, yellow, green, cyan, blue, magenta). - Actual values are computed procedurally in Oklch color space based on a handful of hyperparameters. - Each color has a 256 colors variant with perceptually closest color. ------ Highlight groups Use: - Grey shades for general UI according to their design. - Bold text for keywords (`Statement` highlight group). This is an important choice to increase accessibility for people with color deficiencies, as it doesn't rely on actual color. - Green for strings, `DiffAdd` (as background), `DiagnosticOk`, and some minor text UI elements. - Cyan as main syntax color, i.e. for function usage (`Function` highlight group), `DiffText`, `DiagnosticInfo`, and some minor text UI elements. - Red to generally mean high user attention, i.e. errors; in particular for `ErrorMsg`, `DiffDelete`, `DiagnosticError`. - Yellow very sparingly only with true colors to mean mild user attention, i.e. warnings. That is, `DiagnosticWarn` and `WarningMsg`. - Blue very sparingly only with true colors as `DiagnosticHint` and some additional important syntax group (like `Identifier`). - Magenta very carefully (if at all). ------ Notes - To make tests work without relatively larege updates, each one is prepended with an equivalent of the call `:colorscheme vim`. Plus some tests which spawn new Neovim instances also now use 'vim' color scheme. In some cases tests are updated to fit new default color scheme.
2023-11-29 13:16:09 -07:00
{6: }|
{7:Error detected while processing pre-vimrc command line:} |
{7:E121: Undefined variable: invalid} |
{8:Press ENTER or type command to continue}^ |
]])
feed('<cr>')
screen:expect([[
^ |
{3:~ }|*6
|
]])
end)
it("doesn't erase output when setting color scheme", function()
if helpers.is_os('openbsd') then
pending('FIXME #10804')
end
startup('--cmd', 'echoerr "foo"', '--cmd', 'color default', '--cmd', 'echoerr "bar"')
screen:expect([[
|*3
{6: }|
feat(highlight): update default color scheme Problem: Default color scheme is suboptimal. Solution: Start using new color scheme. Introduce new `vim` color scheme for opt-in backward compatibility. ------ Main design ideas - Be "Neovim branded". - Be minimal for 256 colors with a bit more shades for true colors. - Be accessible through high enough contrast ratios. - Be suitable for dark and light backgrounds via exchange of dark and light palettes. ------ Palettes - Have dark and light variants. Implemented through exporeted `NvimDark*` and `NvimLight*` hex colors. - Palettes have 4 shades of grey for UI elements and 6 colors (red, yellow, green, cyan, blue, magenta). - Actual values are computed procedurally in Oklch color space based on a handful of hyperparameters. - Each color has a 256 colors variant with perceptually closest color. ------ Highlight groups Use: - Grey shades for general UI according to their design. - Bold text for keywords (`Statement` highlight group). This is an important choice to increase accessibility for people with color deficiencies, as it doesn't rely on actual color. - Green for strings, `DiffAdd` (as background), `DiagnosticOk`, and some minor text UI elements. - Cyan as main syntax color, i.e. for function usage (`Function` highlight group), `DiffText`, `DiagnosticInfo`, and some minor text UI elements. - Red to generally mean high user attention, i.e. errors; in particular for `ErrorMsg`, `DiffDelete`, `DiagnosticError`. - Yellow very sparingly only with true colors to mean mild user attention, i.e. warnings. That is, `DiagnosticWarn` and `WarningMsg`. - Blue very sparingly only with true colors as `DiagnosticHint` and some additional important syntax group (like `Identifier`). - Magenta very carefully (if at all). ------ Notes - To make tests work without relatively larege updates, each one is prepended with an equivalent of the call `:colorscheme vim`. Plus some tests which spawn new Neovim instances also now use 'vim' color scheme. In some cases tests are updated to fit new default color scheme.
2023-11-29 13:16:09 -07:00
{7:Error detected while processing pre-vimrc command line:} |
{7:foo} |
{7:bar} |
{8:Press ENTER or type command to continue}^ |
]])
end)
it("doesn't erase output when setting Normal colors", function()
startup('--cmd', 'echoerr "foo"', '--cmd', 'hi Normal guibg=Green', '--cmd', 'echoerr "bar"')
2024-01-02 18:09:18 -07:00
screen:expect {
grid = [[
|*3
feat(highlight): update default color scheme Problem: Default color scheme is suboptimal. Solution: Start using new color scheme. Introduce new `vim` color scheme for opt-in backward compatibility. ------ Main design ideas - Be "Neovim branded". - Be minimal for 256 colors with a bit more shades for true colors. - Be accessible through high enough contrast ratios. - Be suitable for dark and light backgrounds via exchange of dark and light palettes. ------ Palettes - Have dark and light variants. Implemented through exporeted `NvimDark*` and `NvimLight*` hex colors. - Palettes have 4 shades of grey for UI elements and 6 colors (red, yellow, green, cyan, blue, magenta). - Actual values are computed procedurally in Oklch color space based on a handful of hyperparameters. - Each color has a 256 colors variant with perceptually closest color. ------ Highlight groups Use: - Grey shades for general UI according to their design. - Bold text for keywords (`Statement` highlight group). This is an important choice to increase accessibility for people with color deficiencies, as it doesn't rely on actual color. - Green for strings, `DiffAdd` (as background), `DiagnosticOk`, and some minor text UI elements. - Cyan as main syntax color, i.e. for function usage (`Function` highlight group), `DiffText`, `DiagnosticInfo`, and some minor text UI elements. - Red to generally mean high user attention, i.e. errors; in particular for `ErrorMsg`, `DiffDelete`, `DiagnosticError`. - Yellow very sparingly only with true colors to mean mild user attention, i.e. warnings. That is, `DiagnosticWarn` and `WarningMsg`. - Blue very sparingly only with true colors as `DiagnosticHint` and some additional important syntax group (like `Identifier`). - Magenta very carefully (if at all). ------ Notes - To make tests work without relatively larege updates, each one is prepended with an equivalent of the call `:colorscheme vim`. Plus some tests which spawn new Neovim instances also now use 'vim' color scheme. In some cases tests are updated to fit new default color scheme.
2023-11-29 13:16:09 -07:00
{6: }|
{7:Error detected while processing pre-vimrc command line:} |
{7:foo} |
{7:bar} |
{8:Press ENTER or type command to continue}^ |
2024-01-02 18:09:18 -07:00
]],
condition = function()
eq(Screen.colors.Green, screen.default_colors.rgb_bg)
end,
}
end)
end
2024-01-02 18:09:18 -07:00
describe('--embed UI on startup (ext_linegrid=true)', function()
test_embed(true)
end)
describe('--embed UI on startup (ext_linegrid=false)', function()
test_embed(false)
end)
2022-04-22 11:56:31 -07:00
describe('--embed UI', function()
it('can pass stdin', function()
local pipe = assert(uv.pipe())
local writer = assert(uv.new_pipe(false))
writer:open(pipe.write)
2024-01-02 18:09:18 -07:00
clear { args_rm = { '--headless' }, io_extra = pipe.read }
2022-04-22 11:56:31 -07:00
-- attach immediately after startup, for early UI
local screen = Screen.new(40, 8)
2024-01-02 18:09:18 -07:00
screen.rpc_async = true -- Avoid hanging. #24888
screen:attach { stdin_fd = 3 }
2022-04-22 11:56:31 -07:00
screen:set_default_attr_ids {
2024-01-02 18:09:18 -07:00
[1] = { bold = true, foreground = Screen.colors.Blue1 },
[2] = { bold = true },
2022-04-22 11:56:31 -07:00
}
2024-01-02 18:09:18 -07:00
writer:write 'hello nvim\nfrom external input\n'
writer:shutdown(function()
writer:close()
end)
2022-04-22 11:56:31 -07:00
2024-01-02 18:09:18 -07:00
screen:expect {
grid = [[
2022-04-22 11:56:31 -07:00
^hello nvim |
from external input |
{1:~ }|*5
2022-04-22 11:56:31 -07:00
|
2024-01-02 18:09:18 -07:00
]],
}
2022-04-22 11:56:31 -07:00
-- stdin (rpc input) still works
feed 'o'
2024-01-02 18:09:18 -07:00
screen:expect {
grid = [[
2022-04-22 11:56:31 -07:00
hello nvim |
^ |
from external input |
{1:~ }|*4
2022-04-22 11:56:31 -07:00
{2:-- INSERT --} |
2024-01-02 18:09:18 -07:00
]],
}
2022-04-22 11:56:31 -07:00
end)
2024-01-02 18:09:18 -07:00
it('only sets background colors once even if overridden', function()
local screen, current, seen
local function handle_default_colors_set(_, _, rgb_bg, _, _, _)
seen[rgb_bg] = true
current = rgb_bg
end
local function startup(...)
seen = {}
current = nil
2024-01-02 18:09:18 -07:00
clear { args_rm = { '--headless' }, args = { ... } }
-- attach immediately after startup, for early UI
screen = Screen.new(40, 8)
screen._handle_default_colors_set = handle_default_colors_set
screen:attach()
end
startup()
2024-01-02 18:09:18 -07:00
screen:expect {
condition = function()
eq(16777215, current)
end,
}
eq({ [16777215] = true }, seen)
-- NB: by accident how functional/helpers.lua currently handles the default color scheme, the
-- above is sufficient to test the behavior. But in case that workaround is removed, we need
-- a test with an explicit override like below, so do it to remain safe.
startup('--cmd', 'hi NORMAL guibg=#FF00FF')
2024-01-02 18:09:18 -07:00
screen:expect {
condition = function()
eq(16711935, current)
end,
}
eq({ [16711935] = true }, seen) -- we only saw the last one, despite 16777215 was set internally earlier
end)
it('updates cwd of attached UI #21771', function()
clear { args_rm = { '--headless' } }
local screen = Screen.new(40, 8)
screen:attach()
screen:expect {
condition = function()
eq(helpers.paths.test_source_path, screen.pwd)
end,
}
-- Change global cwd
helpers.command(string.format('cd %s/src/nvim', helpers.paths.test_source_path))
screen:expect {
condition = function()
eq(string.format('%s/src/nvim', helpers.paths.test_source_path), screen.pwd)
end,
}
-- Split the window and change the cwd in the split
helpers.command('new')
helpers.command(string.format('lcd %s/test', helpers.paths.test_source_path))
screen:expect {
condition = function()
eq(string.format('%s/test', helpers.paths.test_source_path), screen.pwd)
end,
}
-- Move to the original window
helpers.command('wincmd p')
screen:expect {
condition = function()
eq(string.format('%s/src/nvim', helpers.paths.test_source_path), screen.pwd)
end,
}
-- Change global cwd again
helpers.command(string.format('cd %s', helpers.paths.test_source_path))
screen:expect {
condition = function()
eq(helpers.paths.test_source_path, screen.pwd)
end,
}
end)
2022-04-22 11:56:31 -07:00
end)
describe('--embed --listen UI', function()
it('waits for connection on listening address', function()
helpers.skip(helpers.is_os('win'))
clear()
local child_server = assert(helpers.new_pipename())
fn.jobstart({
2024-01-02 18:09:18 -07:00
nvim_prog,
'--embed',
'--listen',
child_server,
'--clean',
'--cmd',
'colorscheme vim',
})
retry(nil, nil, function()
neq(nil, uv.fs_stat(child_server))
end)
local child_session = helpers.connect(child_server)
local info_ok, api_info = child_session:request('nvim_get_api_info')
ok(info_ok)
eq(2, #api_info)
ok(api_info[1] > 2, 'channel_id > 2', api_info[1])
2024-01-02 18:09:18 -07:00
child_session:request(
'nvim_exec2',
[[
let g:evs = []
autocmd UIEnter * call add(g:evs, $"UIEnter:{v:event.chan}")
autocmd VimEnter * call add(g:evs, "VimEnter")
2024-01-02 18:09:18 -07:00
]],
{}
)
-- VimEnter and UIEnter shouldn't be triggered until after attach
local var_ok, var = child_session:request('nvim_get_var', 'evs')
ok(var_ok)
eq({}, var)
local child_screen = Screen.new(40, 6)
child_screen:attach(nil, child_session)
2024-01-02 18:09:18 -07:00
child_screen:expect {
grid = [[
^ |
{1:~ }|*3
{2:[No Name] 0,0-1 All}|
|
2024-01-02 18:09:18 -07:00
]],
attr_ids = {
[1] = { foreground = Screen.colors.Blue, bold = true },
[2] = { reverse = true, bold = true },
},
}
-- VimEnter and UIEnter should now be triggered
var_ok, var = child_session:request('nvim_get_var', 'evs')
ok(var_ok)
2024-01-02 18:09:18 -07:00
eq({ 'VimEnter', ('UIEnter:%d'):format(api_info[1]) }, var)
end)
end)