From 1b6442034f6a821d357fe59cd75fdae47a7f7cff Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Wed, 20 Nov 2024 21:11:20 +0100 Subject: fix(messages): more ext_messages kinds #31279 Add kinds for various commands that output a list, the 'wildmode' list, and for number prompts. --- test/functional/lua/ui_event_spec.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index c8616e3e11..f1cf657d78 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -285,6 +285,26 @@ describe('vim.ui_attach', function() }, }, }) + feed(':call inputlist(["Select:", "One", "Two"])') + screen:expect({ + grid = [[ + E122: {10:Function} Foo already exists, add !| + to replace it | + Type number and or click with th| + e mouse (q or empty cancels): | + {1:^~ }| + ]], + messages = { + { + content = { { 'Select:\nOne\nTwo\n' } }, + kind = 'list_cmd', + }, + { + content = { { 'Type number and or click with the mouse (q or empty cancels): ' } }, + kind = 'number_prompt', + }, + }, + }) end) end) -- 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/lua/ui_event_spec.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index f1cf657d78..25cc46e260 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -263,7 +263,7 @@ describe('vim.ui_attach', function() ]], messages = { { - content = { { 'E122: Function Foo already exists, add ! to replace it', 9, 7 } }, + content = { { 'E122: Function Foo already exists, add ! to replace it', 9, 6 } }, kind = 'emsg', }, }, @@ -280,7 +280,7 @@ describe('vim.ui_attach', function() ]], messages = { { - content = { { 'replace with Replacement (y/n/a/q/l/^E/^Y)?', 6, 19 } }, + content = { { 'replace with Replacement (y/n/a/q/l/^E/^Y)?', 6, 18 } }, kind = 'confirm_sub', }, }, @@ -348,7 +348,7 @@ describe('vim.ui_attach', function() foo^ | {1:~ }|*4 ]], - showmode = { { '-- INSERT --', 5, 12 } }, + showmode = { { '-- INSERT --', 5, 11 } }, }) feed(':1mes clear:mes') screen:expect({ @@ -375,7 +375,7 @@ describe('vim.ui_attach', function() { 'Error executing vim.schedule lua callback: [string ""]:2: attempt to index global \'err\' (a nil value)\nstack traceback:\n\t[string ""]:2: in function <[string ""]:2>', 9, - 7, + 6, }, }, kind = 'lua_error', @@ -385,13 +385,13 @@ describe('vim.ui_attach', function() { 'Error executing vim.schedule lua callback: [string ""]:2: attempt to index global \'err\' (a nil value)\nstack traceback:\n\t[string ""]:2: in function <[string ""]:2>', 9, - 7, + 6, }, }, kind = 'lua_error', }, { - content = { { 'Press ENTER or type command to continue', 100, 19 } }, + content = { { 'Press ENTER or type command to continue', 100, 18 } }, kind = 'return_prompt', }, }, -- cgit From 394f69a25dc32c5b101ba2d34ac6376b0c75b2a2 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Fri, 20 Dec 2024 21:11:38 +0100 Subject: feat(ui): additional arguments for cmdline_show/hide events Problem: Unable to tell what highlight the prompt part of a cmdline_show event should have, and whether cmdline_hide was emitted after aborting. Solution: Add additional arguments hl_id to cmdline_show, and abort to cmdline_hide. --- test/functional/lua/ui_event_spec.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 25cc46e260..2922fb5414 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -261,6 +261,7 @@ describe('vim.ui_attach', function() lled in a fast event context | {1:~ }| ]], + cmdline = { { abort = false } }, messages = { { content = { { 'E122: Function Foo already exists, add ! to replace it', 9, 6 } }, @@ -278,6 +279,7 @@ describe('vim.ui_attach', function() Y)? | {1:~ }| ]], + cmdline = { { abort = false } }, messages = { { content = { { 'replace with Replacement (y/n/a/q/l/^E/^Y)?', 6, 18 } }, @@ -294,6 +296,7 @@ describe('vim.ui_attach', function() e mouse (q or empty cancels): | {1:^~ }| ]], + cmdline = { { abort = false } }, messages = { { content = { { 'Select:\nOne\nTwo\n' } }, @@ -359,6 +362,7 @@ describe('vim.ui_attach', function() {9:back from ns: 1.} | {100:Press ENTER or type command to continue}^ | ]], + cmdline = { { abort = false } }, }) feed('') -- Also when scheduled -- cgit From a10636fbe7bb4dba45c42c64548e5e32fe8f8d12 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Sun, 22 Dec 2024 13:21:57 +0100 Subject: feat(ui): specify whether msg_show event is added to history Pass along whether message in msg_show event is added to the internal :messages history. --- test/functional/lua/ui_event_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 2922fb5414..7e890e8ae0 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -265,6 +265,7 @@ describe('vim.ui_attach', function() messages = { { content = { { 'E122: Function Foo already exists, add ! to replace it', 9, 6 } }, + history = true, kind = 'emsg', }, }, @@ -283,6 +284,7 @@ describe('vim.ui_attach', function() messages = { { content = { { 'replace with Replacement (y/n/a/q/l/^E/^Y)?', 6, 18 } }, + history = true, kind = 'confirm_sub', }, }, @@ -300,10 +302,12 @@ describe('vim.ui_attach', function() messages = { { content = { { 'Select:\nOne\nTwo\n' } }, + history = false, kind = 'list_cmd', }, { content = { { 'Type number and or click with the mouse (q or empty cancels): ' } }, + history = false, kind = 'number_prompt', }, }, @@ -382,6 +386,7 @@ describe('vim.ui_attach', function() 6, }, }, + history = true, kind = 'lua_error', }, { @@ -392,10 +397,12 @@ describe('vim.ui_attach', function() 6, }, }, + history = true, kind = 'lua_error', }, { content = { { 'Press ENTER or type command to continue', 100, 18 } }, + history = false, kind = 'return_prompt', }, }, -- cgit From 48e2a73610ca5639408f79b3d8eebd3e5f57a327 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Thu, 2 Jan 2025 14:51:03 +0100 Subject: feat(ui)!: emit prompt "messages" as cmdline events #31525 Problem: Prompts are emitted as messages events, where cmdline events are more appropriate. The user input is also emitted as message events in fast context, so cannot be displayed with vim.ui_attach(). Solution: Prompt for user input through cmdline prompts. --- test/functional/lua/ui_event_spec.lua | 42 ----------------------------------- 1 file changed, 42 deletions(-) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 7e890e8ae0..27640d6066 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -270,48 +270,6 @@ describe('vim.ui_attach', function() }, }, }) - -- No fast context for prompt message kinds - feed(':%s/Function/Replacement/c') - screen:expect({ - grid = [[ - ^E122: {10:Function} Foo already exists, add !| - to replace it | - replace with Replacement (y/n/a/q/l/^E/^| - Y)? | - {1:~ }| - ]], - cmdline = { { abort = false } }, - messages = { - { - content = { { 'replace with Replacement (y/n/a/q/l/^E/^Y)?', 6, 18 } }, - history = true, - kind = 'confirm_sub', - }, - }, - }) - feed(':call inputlist(["Select:", "One", "Two"])') - screen:expect({ - grid = [[ - E122: {10:Function} Foo already exists, add !| - to replace it | - Type number and or click with th| - e mouse (q or empty cancels): | - {1:^~ }| - ]], - cmdline = { { abort = false } }, - messages = { - { - content = { { 'Select:\nOne\nTwo\n' } }, - history = false, - kind = 'list_cmd', - }, - { - content = { { 'Type number and or click with the mouse (q or empty cancels): ' } }, - history = false, - kind = 'number_prompt', - }, - }, - }) end) end) -- 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/lua/ui_event_spec.lua | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 27640d6066..af6b2ceac3 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -106,20 +106,15 @@ describe('vim.ui_attach', function() end) it('does not crash on exit', function() - fn.system({ - n.nvim_prog, - '-u', - 'NONE', - '-i', - 'NONE', + local p = n.spawn_wait( '--cmd', [[ lua ns = vim.api.nvim_create_namespace 'testspace' ]], '--cmd', [[ lua vim.ui_attach(ns, {ext_popupmenu=true}, function() end) ]], '--cmd', - 'quitall!', - }) - eq(0, n.eval('v:shell_error')) + 'quitall!' + ) + eq(0, p.status) end) it('can receive accurate message kinds even if they are history', function() -- cgit From bbf36ef8ef86534e317e4e0153730a40ae4c936e Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Wed, 15 Jan 2025 15:55:21 +0100 Subject: fix(cmdline): prevent cmdline_show events after exiting cmdline #32033 Problem: If a (vim.ui_attach) cmdline_hide callback triggers a redraw, it may cause cmdline_show events for an already exited cmdline. Solution: Avoid emitting cmdline_show event when ccline.cmdbuff is already NULL. Unset ccline.cmdbuff before emitting cmdline_hide. --- test/functional/lua/ui_event_spec.lua | 63 +++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 7 deletions(-) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index af6b2ceac3..c6f98c8640 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -168,18 +168,67 @@ describe('vim.ui_attach', function() vim.ui_attach(ns, { ext_messages = true }, function(ev) if ev == 'msg_show' then vim.schedule(function() vim.cmd.redraw() end) - else - vim.cmd.redraw() + elseif ev:find('cmdline') then + _G.cmdline = _G.cmdline + (ev == 'cmdline_show' and 1 or 0) + vim.api.nvim_buf_set_lines(0, 0, -1, false, { tostring(_G.cmdline) }) + vim.cmd('redraw') end - _G.cmdline = _G.cmdline + (ev == 'cmdline_show' and 1 or 0) end )]]) + screen:expect([[ + ^ | + {1:~ }|*4 + ]]) feed(':') - n.assert_alive() - eq(2, exec_lua('return _G.cmdline')) - n.assert_alive() + screen:expect({ + grid = [[ + ^1 | + {1:~ }|*4 + ]], + cmdline = { { + content = { { '' } }, + firstc = ':', + pos = 0, + } }, + }) feed('versionv') - n.assert_alive() + screen:expect({ + grid = [[ + ^2 | + {1:~ }|*4 + ]], + cmdline = { { abort = false } }, + }) + feed([[:call confirm("Save changes?", "&Yes\n&No\n&Cancel")]]) + screen:expect({ + grid = [[ + ^5 | + {1:~ }|*4 + ]], + cmdline = { + { + content = { { '' } }, + hl_id = 10, + pos = 0, + prompt = '[Y]es, (N)o, (C)ancel: ', + }, + }, + messages = { + { + content = { { '\nSave changes?\n', 6, 10 } }, + history = false, + kind = 'confirm', + }, + }, + }) + feed('n') + screen:expect({ + grid = [[ + ^5 | + {1:~ }|*4 + ]], + cmdline = { { abort = false } }, + }) end) it("preserved 'incsearch/command' screen state after :redraw from ext_cmdline", function() -- cgit From d98827b634af29d74079d1848dd5e8c5d2be1233 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Wed, 22 Jan 2025 23:13:40 +0100 Subject: fix(messages): avoid empty msg_showmode with 'noshowmode' --- test/functional/lua/ui_event_spec.lua | 63 ++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 30 deletions(-) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index c6f98c8640..8bfd574fb9 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -345,31 +345,36 @@ describe('vim.ui_attach', function() vim.api.nvim_buf_set_lines(0, -2, -1, false, { err[1] }) end) ]]) + local s1 = [[ + ^ | + {1:~ }|*4 + ]] + screen:expect(s1) + feed('QQQQQQ') screen:expect({ grid = [[ - ^ | - {1:~ }|*4 - ]], - }) - feed('ifoo') - screen:expect({ - grid = [[ - foo^ | - {1:~ }|*4 - ]], - showmode = { { '-- INSERT --', 5, 11 } }, - }) - feed(':1mes clear:mes') - screen:expect({ - grid = [[ - foo | - {3: }| - {9:Excessive errors in vim.ui_attach() call}| - {9:back from ns: 1.} | + {9:obal 'err' (a nil value)} | + {9:stack traceback:} | + {9: [string ""]:2: in function}| + {9: <[string ""]:1>} | {100:Press ENTER or type command to continue}^ | ]], - cmdline = { { abort = false } }, + messages = { + { + content = { { 'Press ENTER or type command to continue', 100, 18 } }, + history = true, + kind = 'return_prompt', + }, + }, }) + feed(':1mes clear:mes') + screen:expect([[ + | + {3: }| + {9:Excessive errors in vim.ui_attach() call}| + {9:back from ns: 1.} | + {100:Press ENTER or type command to continue}^ | + ]]) feed('') -- Also when scheduled exec_lua([[ @@ -378,7 +383,7 @@ describe('vim.ui_attach', function() end) ]]) screen:expect({ - any = 'fo^o', + grid = s1, messages = { { content = { @@ -410,14 +415,12 @@ describe('vim.ui_attach', function() }, }) feed(':1mes clear:mes') - screen:expect({ - grid = [[ - foo | - {3: }| - {9:Excessive errors in vim.ui_attach() call}| - {9:back from ns: 2.} | - {100:Press ENTER or type command to continue}^ | - ]], - }) + screen:expect([[ + | + {3: }| + {9:Excessive errors in vim.ui_attach() call}| + {9:back from ns: 2.} | + {100:Press ENTER or type command to continue}^ | + ]]) end) end) -- cgit From c6d2cbf8f51abfa0c9d244ef384a15b0b69e16c6 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 23 Jan 2025 12:42:38 +0100 Subject: fix(lua): pop retval for fast context LuaRef Problem: nlua_call_ref_ctx() does not pop the return value in fast context that did not error. Solution: Fall through to end; calling nlua_call_pop_retval(). --- test/functional/lua/ui_event_spec.lua | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 8bfd574fb9..80457555d4 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -423,4 +423,13 @@ describe('vim.ui_attach', function() {100:Press ENTER or type command to continue}^ | ]]) end) + + it('sourcing invalid file does not crash #32166', function() + exec_lua([[ + local ns = vim.api.nvim_create_namespace("") + vim.ui_attach(ns, { ext_messages = true }, function() end) + ]]) + feed((':luafile %s'):format(testlog)) + n.assert_alive() + end) end) -- cgit From 216ec739721494fb31111f19b1dee356a0d88ba1 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Wed, 29 Jan 2025 12:07:27 +0100 Subject: fix(ui): avoid redundant ext_cmdline events (#32237) Problem: `cmdline_show` is emitted unnecessarily each event loop iteration, because `cmdline_was_last_drawn` is never set. Solution: Keep track of whether the cmdline was last drawn to avoid unnecessarily emitting cmdline_show. Set `redraw_state` to emit `cmdline_pos` when emitting `CursorMovedC`. Only emit `cmdline_pos` when cmdline was last drawn. --- test/functional/lua/ui_event_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/lua/ui_event_spec.lua') diff --git a/test/functional/lua/ui_event_spec.lua b/test/functional/lua/ui_event_spec.lua index 80457555d4..ddb10127e4 100644 --- a/test/functional/lua/ui_event_spec.lua +++ b/test/functional/lua/ui_event_spec.lua @@ -202,7 +202,7 @@ describe('vim.ui_attach', function() feed([[:call confirm("Save changes?", "&Yes\n&No\n&Cancel")]]) screen:expect({ grid = [[ - ^5 | + ^4 | {1:~ }|*4 ]], cmdline = { @@ -224,7 +224,7 @@ describe('vim.ui_attach', function() feed('n') screen:expect({ grid = [[ - ^5 | + ^4 | {1:~ }|*4 ]], cmdline = { { abort = false } }, -- cgit