From 07db909eb5ae2a559771068be64439eba394cd61 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 20 Nov 2024 23:50:30 +0100 Subject: docs: misc (#31138) Co-authored-by: zeertzjq --- test/functional/core/startup_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 7062211187..f3c477d210 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -343,7 +343,7 @@ describe('startup', function() local screen = Screen.new(25, 3) -- Remote UI connected by --embed. -- TODO: a lot of tests in this file already use the new default color scheme. - -- once we do the batch update of tests to use it, remove this workarond + -- once we do the batch update of tests to use it, remove this workaround screen._default_attr_ids = nil command([[echo has('ttyin') has('ttyout')]]) screen:expect([[ -- cgit From 0dd933265ff2e64786fd30f949e767e10f401519 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 17 Dec 2024 07:11:41 -0600 Subject: feat(terminal)!: cursor shape and blink (#31562) When a terminal application running inside the terminal emulator sets the cursor shape or blink status of the cursor, update the cursor in the parent terminal to match. This removes the "virtual cursor" that has been in use by the terminal emulator since the beginning. The original rationale for using the virtual cursor was to avoid having to support additional UI methods to change the cursor color for other (non-TUI) UIs, instead relying on the TermCursor and TermCursorNC highlight groups. The TermCursor highlight group is now used in the default 'guicursor' value, which has a new entry for Terminal mode. However, the TermCursorNC highlight group is no longer supported: since terminal windows now use the real cursor, when the window is not focused there is no cursor displayed in the window at all, so there is nothing to highlight. Users can still use the StatusLineTermNC highlight group to differentiate non-focused terminal windows. BREAKING CHANGE: The TermCursorNC highlight group is no longer supported. --- test/functional/core/startup_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index f3c477d210..319a037342 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -1153,7 +1153,7 @@ describe('user config init', function() -- `i` to enter Terminal mode, `a` to allow feed('ia') screen:expect([[ - | + ^ | ~ |*4 [No Name] 0,0-1 All| | @@ -1162,7 +1162,7 @@ describe('user config init', function() feed(':echo g:exrc_file') screen:expect(string.format( [[ - | + ^ | ~ |*4 [No Name] 0,0-1 All| %s%s| -- cgit From 8ef41f590224dfeea2e51d9fec150e363fd72ee0 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 19 Dec 2024 07:07:04 -0800 Subject: feat(jobs): jobstart(…,{term=true}), deprecate termopen() #31343 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: `termopen` has long been a superficial wrapper around `jobstart`, and has no real purpose. Also, `vim.system` and `nvim_open_term` presumably will replace all features of `jobstart` and `termopen`, so centralizing the logic will help with that. Solution: - Introduce `eval/deprecated.c`, where all deprecated eval funcs will live. - Introduce "term" flag of `jobstart`. - Deprecate `termopen`. --- test/functional/core/startup_spec.lua | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 319a037342..76b0755441 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -55,7 +55,10 @@ describe('startup', function() clear() local screen screen = Screen.new(84, 3) - fn.termopen({ nvim_prog, '-u', 'NONE', '--server', eval('v:servername'), '--remote-ui' }) + fn.jobstart( + { nvim_prog, '-u', 'NONE', '--server', eval('v:servername'), '--remote-ui' }, + { term = true } + ) screen:expect([[ ^Cannot attach UI of :terminal child to its parent. (Unset $NVIM to skip this check) | |*2 @@ -98,7 +101,7 @@ describe('startup', function() screen = Screen.new(60, 7) -- not the same colors on windows for some reason screen._default_attr_ids = nil - local id = fn.termopen({ + local id = fn.jobstart({ nvim_prog, '-u', 'NONE', @@ -108,6 +111,7 @@ describe('startup', function() 'set noruler', '-D', }, { + term = true, env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), }, @@ -360,7 +364,7 @@ describe('startup', function() command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal - fn.termopen({ + fn.jobstart({ nvim_prog, '-u', 'NONE', @@ -371,6 +375,7 @@ describe('startup', function() '-c', 'echo has("ttyin") has("ttyout")', }, { + term = true, env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), }, @@ -393,13 +398,14 @@ describe('startup', function() os.remove('Xtest_startup_ttyout') end) -- Running in :terminal - fn.termopen( + fn.jobstart( ( [["%s" -u NONE -i NONE --cmd "%s"]] .. [[ -c "call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')"]] .. [[ -c q | cat -v]] ):format(nvim_prog, nvim_set), { + term = true, env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), }, @@ -424,7 +430,7 @@ describe('startup', function() os.remove('Xtest_startup_ttyout') end) -- Running in :terminal - fn.termopen( + fn.jobstart( ( [[echo foo | ]] -- Input from a pipe. .. [["%s" -u NONE -i NONE --cmd "%s"]] @@ -432,6 +438,7 @@ describe('startup', function() .. [[ -c q -- -]] ):format(nvim_prog, nvim_set), { + term = true, env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), }, @@ -454,13 +461,14 @@ describe('startup', function() command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal - fn.termopen( + fn.jobstart( ( [[echo foo | ]] .. [["%s" -u NONE -i NONE --cmd "%s"]] .. [[ -c "echo has('ttyin') has('ttyout')"]] ):format(nvim_prog, nvim_set), { + term = true, env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), }, @@ -614,7 +622,7 @@ describe('startup', function() local screen screen = Screen.new(60, 6) screen._default_attr_ids = nil - local id = fn.termopen({ + local id = fn.jobstart({ nvim_prog, '-u', 'NONE', @@ -625,6 +633,7 @@ describe('startup', function() '--cmd', 'let g:foo = g:bar', }, { + term = true, env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), }, @@ -1144,7 +1153,8 @@ describe('user config init', function() local screen = Screen.new(50, 8) screen._default_attr_ids = nil - fn.termopen({ nvim_prog }, { + fn.jobstart({ nvim_prog }, { + term = true, env = { VIMRUNTIME = os.getenv('VIMRUNTIME'), }, @@ -1418,7 +1428,7 @@ describe('inccommand on ex mode', function() clear() local screen screen = Screen.new(60, 10) - local id = fn.termopen({ + local id = fn.jobstart({ nvim_prog, '-u', 'NONE', @@ -1429,6 +1439,7 @@ describe('inccommand on ex mode', function() '-E', 'test/README.md', }, { + term = true, env = { VIMRUNTIME = os.getenv('VIMRUNTIME') }, }) fn.chansend(id, '%s/N') -- cgit From a1ba655dee0f89230ea09712e4df981cc3b15bea Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 12 Sep 2024 03:04:33 +0200 Subject: test: spawn_wait() starts a non-RPC Nvim process Problem: Can't use `n.clear()` to test non-RPC `nvim` invocations. So tests end up creating ad-hoc wrappers around `system()` or `jobstart()`. Solution: - Introduce `n.spawn_wait()` - TODO (followup PR): Rename `n.spawn()` and `n.spawn_wait()`. It's misleading that `n.spawn()` returns a RPC session... --- test/functional/core/startup_spec.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 76b0755441..c9ea280646 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -154,8 +154,9 @@ describe('startup', function() it('failure modes', function() -- nvim -l - matches('nvim%.?e?x?e?: Argument missing after: "%-l"', fn.system({ nvim_prog, '-l' })) - eq(1, eval('v:shell_error')) + local proc = n.spawn_wait('-l') + matches('nvim%.?e?x?e?: Argument missing after: "%-l"', proc.stderr) + eq(1, proc.status) end) it('os.exit() sets Nvim exitcode', function() @@ -182,12 +183,11 @@ describe('startup', function() end) it('Lua-error sets Nvim exitcode', function() + local proc = n.spawn_wait('-l', 'test/functional/fixtures/startup-fail.lua') + matches('E5113: .* my pearls!!', proc.output) + eq(1, proc.status) + eq(0, eval('v:shell_error')) - matches( - 'E5113: .* my pearls!!', - fn.system({ nvim_prog, '-l', 'test/functional/fixtures/startup-fail.lua' }) - ) - eq(1, eval('v:shell_error')) matches( 'E5113: .* %[string "error%("whoa"%)"%]:1: whoa', fn.system({ nvim_prog, '-l', '-' }, 'error("whoa")') -- cgit From 975c2124a6e057e3f50ca5b2ad56572a39c633d9 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 4 Jan 2025 06:29:13 -0800 Subject: test: use spawn_wait() instead of system() #31852 Problem: Tests that need to check `nvim` CLI behavior (no RPC session) create their own ad-hoc `system()` wrappers. Solution: - Use `n.spawn_wait` instead of `system()`. - Bonus: this also improves the tests by explicitly checking for `stdout` or `stderr`. And if a signal is raised, `ProcStream.status` will reflect it. --- test/functional/core/startup_spec.lua | 43 ++++++++--------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index c9ea280646..642e2b0287 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -77,22 +77,9 @@ describe('startup', function() end) it('--startuptime does not crash on error #31125', function() - eq( - "E484: Can't open file .", - fn.system({ - nvim_prog, - '-u', - 'NONE', - '-i', - 'NONE', - '--headless', - '--startuptime', - '.', - '-c', - '42cquit', - }) - ) - eq(42, api.nvim_get_vvar('shell_error')) + local p = n.spawn_wait('--startuptime', '.', '-c', '42cquit') + eq("E484: Can't open file .", p.stderr) + eq(42, p.status) end) it('-D does not hang #12647', function() @@ -184,7 +171,7 @@ describe('startup', function() it('Lua-error sets Nvim exitcode', function() local proc = n.spawn_wait('-l', 'test/functional/fixtures/startup-fail.lua') - matches('E5113: .* my pearls!!', proc.output) + matches('E5113: .* my pearls!!', proc:output()) eq(1, proc.status) eq(0, eval('v:shell_error')) @@ -606,15 +593,15 @@ describe('startup', function() it('fails on --embed with -es/-Es/-l', function() matches( 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', - fn.system({ nvim_prog, '--embed', '-es' }) + n.spawn_wait('--embed', '-es').stderr ) matches( 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', - fn.system({ nvim_prog, '--embed', '-Es' }) + n.spawn_wait('--embed', '-Es').stderr ) matches( 'nvim[.exe]*: %-%-embed conflicts with %-es/%-Es/%-l', - fn.system({ nvim_prog, '--embed', '-l', 'foo.lua' }) + n.spawn_wait('--embed', '-l', 'foo.lua').stderr ) end) @@ -698,20 +685,8 @@ describe('startup', function() end) it('get command line arguments from v:argv', function() - local out = fn.system({ - nvim_prog, - '-u', - 'NONE', - '-i', - 'NONE', - '--headless', - '--cmd', - nvim_set, - '-c', - [[echo v:argv[-1:] len(v:argv) > 1]], - '+q', - }) - eq("['+q'] 1", out) + local p = n.spawn_wait('--cmd', nvim_set, '-c', [[echo v:argv[-1:] len(v:argv) > 1]], '+q') + eq("['+q'] 1", p.stderr) end) end) -- cgit From 5e02a2c47072ec08279b830daa6f82e39ba86c6e Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 5 Jan 2025 17:10:16 -0800 Subject: "nvim -es": disable shada #21723 Problem: `nvim -es` (and `nvim -Es`) is the recommended way to non-interactively run commands/vimscript. But it enables shada by default, which is usually not wanted. Solution: - Disable shada by default for `nvim -es/-Es`. This can be overridden by `-i foo` if needed. - Do NOT change the 'loadplugins' default. - User config + packages _should_ be enabled by default, for both `nvim -es` and `nvim -l`. Else any Lua packages you have can't be accessed without `-u path/to/config`, which is clumsy. - Use-cases: ``` nvim --headless "+Lazy! sync" +qa would become: nvim -es "+Lazy! sync" nvim --headless +PlugInstall +qall would become: nvim -es +PlugInstall ``` - Opt-out (`--clean` or `-u NONE`) is much easier than opt-in (`-u path/to/config`). - User config/packages are analogous to pip packages, which are expected when doing `python -c ...`. related: 7c94bcd2d77e2e54b8836ab8325460a367b79eae related: ddd0eb6f5120a09b97867d2561ea61309038ccd2 --- test/functional/core/startup_spec.lua | 39 ++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'test/functional/core/startup_spec.lua') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 642e2b0287..8ecd3dca97 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -136,7 +136,11 @@ describe('startup', function() vim.list_extend(args, { '-l', (script or 'test/functional/fixtures/startup.lua') }) vim.list_extend(args, lua_args or {}) local out = fn.system(args, input):gsub('\r\n', '\n') - return eq(dedent(expected), out) + if type(expected) == 'function' then + return expected(out) + else + return eq(dedent(expected), out) + end end it('failure modes', function() @@ -172,6 +176,7 @@ describe('startup', function() it('Lua-error sets Nvim exitcode', function() local proc = n.spawn_wait('-l', 'test/functional/fixtures/startup-fail.lua') matches('E5113: .* my pearls!!', proc:output()) + eq(0, proc.signal) eq(1, proc.status) eq(0, eval('v:shell_error')) @@ -282,14 +287,30 @@ describe('startup', function() eq(0, eval('v:shell_error')) end) - it('disables swapfile/shada/config/plugins', function() + it('disables swapfile/shada/config/plugins unless overridden', function() + local script = [[print(('updatecount=%d shadafile=%s loadplugins=%s scripts=%d'):format( + vim.o.updatecount, vim.o.shadafile, tostring(vim.o.loadplugins), math.max(1, #vim.fn.getscriptinfo())))]] + finally(function() + os.remove('Xtest_shada') + end) + assert_l_out( 'updatecount=0 shadafile=NONE loadplugins=false scripts=1\n', nil, nil, '-', - [[print(('updatecount=%d shadafile=%s loadplugins=%s scripts=%d'):format( - vim.o.updatecount, vim.o.shadafile, tostring(vim.o.loadplugins), math.max(1, #vim.fn.getscriptinfo())))]] + script + ) + + -- User can override. + assert_l_out( + function(out) + return matches('updatecount=99 shadafile=Xtest_shada loadplugins=true scripts=2%d\n', out) + end, + { '+set updatecount=99', '-i', 'Xtest_shada', '+set loadplugins', '-u', 'NORC' }, + nil, + '-', + script ) end) end) @@ -572,19 +593,21 @@ describe('startup', function() eq(' encoding=utf-8\n', fn.system({ nvim_prog, '-n', '-es' }, { 'set encoding', '' })) end) - it('-es/-Es disables swapfile, user config #8540', function() + it('-es/-Es disables swapfile/shada/config #8540', function() for _, arg in ipairs({ '-es', '-Es' }) do local out = fn.system({ nvim_prog, arg, - '+set swapfile? updatecount? shadafile?', + '+set updatecount? shadafile? loadplugins?', '+put =map(getscriptinfo(), {-> v:val.name})', '+%print', }) local line1 = string.match(out, '^.-\n') -- updatecount=0 means swapfile was disabled. - eq(' swapfile updatecount=0 shadafile=\n', line1) - -- Standard plugins were loaded, but not user config. + eq(' updatecount=0 shadafile=NONE loadplugins\n', line1) + -- Standard plugins were loaded, but not user config. #31878 + local nrlines = #vim.split(out, '\n') + ok(nrlines > 20, '>20', nrlines) ok(string.find(out, 'man.lua') ~= nil) ok(string.find(out, 'init.vim') == nil) end -- cgit