From 8786b2066d39e45295eacfe7b10263af4a330f2e Mon Sep 17 00:00:00 2001 From: Enan Ajmain <3nan.ajmain@gmail.com> Date: Sun, 19 Mar 2023 23:23:34 +0600 Subject: fix: pasting in terminal buffer on windows #22566 Problem: On Windows, pasting multiple lines on a terminal buffer cause all the lines to appear on the same line, i.e., the line breaks are lost. Cause: Windows shells expect "\r\n" as line break but "terminal_paste" function uses "\n". Solution: Use "\r\n" as line break for pasting in terminal buffer on Windows. Note: Although this issue was reported with powershell set as 'shell', it occurs in cmd too. Fixes #14621 --- test/functional/terminal/buffer_spec.lua | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 9c8b983ff7..676be151ee 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -429,3 +429,71 @@ it('terminal truncates number of composing characters to 5', function() meths.chan_send(chan, 'a' .. composing:rep(8)) retry(nil, nil, function() eq('a' .. composing:rep(5), meths.get_current_line()) end) end) + +if is_os('win') then + describe(':terminal in Windows', function() + local screen + + before_each(function() + clear() + feed_command('set modifiable swapfile undolevels=20') + poke_eventloop() + local cmd = '["cmd.exe","/K","PROMPT=$g$s"]' + screen = thelpers.screen_setup(nil, cmd) + end) + + it('"put" operator sends data normally', function() + feed('G') + feed_command('let @a = ":: tty ready"') + feed_command('let @a = @a . "\\n:: appended " . @a . "\\n\\n"') + feed('"ap"ap') + screen:expect([[ + | + > :: tty ready | + > :: appended :: tty ready | + > :: tty ready | + > :: appended :: tty ready | + ^> {2: } | + :let @a = @a . "\n:: appended " . @a . "\n\n" | + ]]) + -- operator count is also taken into consideration + feed('3"ap') + screen:expect([[ + > :: appended :: tty ready | + > :: tty ready | + > :: appended :: tty ready | + > :: tty ready | + > :: appended :: tty ready | + ^> {2: } | + :let @a = @a . "\n:: appended " . @a . "\n\n" | + ]]) + end) + + it('":put" command sends data normally', function() + feed('G') + feed_command('let @a = ":: tty ready"') + feed_command('let @a = @a . "\\n:: appended " . @a . "\\n\\n"') + feed_command('put a') + screen:expect([[ + | + > :: tty ready | + > :: appended :: tty ready | + > {2: } | + | + ^ | + :put a | + ]]) + -- line argument is only used to move the cursor + feed_command('6put a') + screen:expect([[ + | + > :: tty ready | + > :: appended :: tty ready | + > :: tty ready | + > :: appended :: tty ready | + ^> {2: } | + :6put a | + ]]) + end) + end) +end -- cgit From a40eb7cc991eb4f8b89f467e8e42563868efa76b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 17 Mar 2023 01:12:33 +0100 Subject: feat(vim.version): more coercion with strict=false Problem: "tmux 3.2a" (output from "tmux -V") is not parsed easily. Solution: With `strict=false`, discard everything before the first digit. - rename Semver => Version - rename vim.version.version() => vim.version._version() - rename matches() => has() - remove `opts` from cmp() --- test/functional/terminal/buffer_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 676be151ee..b983ea89d5 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -202,7 +202,7 @@ describe(':terminal buffer', function() -- Save the buffer number of the terminal for later testing. local tbuf = eval('bufnr("%")') - local exitcmd = helpers.is_os('win') + local exitcmd = is_os('win') and "['cmd', '/c', 'exit']" or "['sh', '-c', 'exit']" source([[ -- cgit From ecd6d679a020ff97156de2fd3c443a77a671ac3d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 14 May 2023 14:29:18 +0200 Subject: test: skip flaky test on Windows --- test/functional/terminal/buffer_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index b983ea89d5..fa587e9364 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -281,6 +281,7 @@ describe(':terminal buffer', function() end) it('requires bang (!) to close a running job #15402', function() + skip(is_os('win'), "Test freezes the CI and makes it time out") eq('Vim(wqall):E948: Job still running', exc_exec('wqall')) for _, cmd in ipairs({ 'bdelete', '%bdelete', 'bwipeout', 'bunload' }) do matches('^Vim%('..cmd:gsub('%%', '')..'%):E89: term://.*tty%-test.* will be killed %(add %! to override%)$', -- cgit From 1fe1bb084d0099fc4f9bfdc11189485d0f74b75a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 19 Dec 2022 16:37:45 +0000 Subject: refactor(options): deprecate nvim[_buf|_win]_[gs]et_option Co-authored-by: zeertzjq Co-authored-by: famiu --- test/functional/terminal/buffer_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index fa587e9364..4ce354b9a9 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -197,7 +197,7 @@ describe(':terminal buffer', function() it('handles loss of focus gracefully', function() -- Change the statusline to avoid printing the file name, which varies. - nvim('set_option', 'statusline', '==========') + nvim('set_option_value', 'statusline', '==========', {}) feed_command('set laststatus=0') -- Save the buffer number of the terminal for later testing. -- cgit From aa4e47f704c53ab1d825260d2bf34e2872e3ca89 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Fri, 23 Jun 2023 22:32:07 +0100 Subject: fix(api): disallow some more functions during textlock Problem: nvim_buf_set_text(), nvim_open_term() and termopen() all change buffer text, which is forbidden during textlock. Additionally, nvim_open_term() and termopen() may be used to convert the cmdwin buffer into a terminal buffer, which is weird. Solution: Allow nvim_buf_set_text() and nvim_open_term() in the cmdwin, but disallow nvim_open_term() from converting the cmdwin buffer into a terminal buffer. termopen() is not allowed in the cmdwin (as it always operates on curbuf), so just check text_locked(). Also happens to improve the error in #21055: nvim_buf_set_text() was callable during textlock, but happened to check textlock indirectly via u_save(); however, this caused the error to be overwritten by an unhelpful "Failed to save undo information" message when msg_list == NULL (e.g: an `` mapping invoked outside of do_cmdline()). --- test/functional/terminal/buffer_spec.lua | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 4ce354b9a9..bd898ba99e 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -498,3 +498,17 @@ if is_os('win') then end) end) end + +describe('termopen()', function() + before_each(clear) + + it('disallowed when textlocked and in cmdwin buffer', function() + command("autocmd TextYankPost ++once call termopen('foo')") + matches("Vim%(call%):E565: Not allowed to change text or change window$", + pcall_err(command, "normal! yy")) + + feed("q:") + eq("Vim:E11: Invalid in command-line window; executes, CTRL-C quits", + pcall_err(funcs.termopen, "bar")) + end) +end) -- cgit From d0d132fbd055834cbecb3d4e3a123a6ea8f099ec Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Jul 2023 21:42:55 +0800 Subject: fix(terminal): don't send unknown special keys to terminal (#24378) Special keys are negative integers, so sending them to terminal leads to strange behavior. --- test/functional/terminal/buffer_spec.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index bd898ba99e..8b43f5cf9c 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -431,6 +431,30 @@ it('terminal truncates number of composing characters to 5', function() retry(nil, nil, function() eq('a' .. composing:rep(5), meths.get_current_line()) end) end) +describe('terminal input', function() + before_each(function() + clear() + exec_lua([[ + _G.input_data = '' + vim.api.nvim_open_term(0, { on_input = function(_, _, _, data) + _G.input_data = _G.input_data .. data + end }) + ]]) + command('startinsert') + poke_eventloop() + end) + + it(' is sent as NUL byte', function() + feed('aaabbb') + eq('aaa\0bbb', exec_lua([[return _G.input_data]])) + end) + + it('unknown special keys are not sent', function() + feed('aaabbb') + eq('aaabbb', exec_lua([[return _G.input_data]])) + end) +end) + if is_os('win') then describe(':terminal in Windows', function() local screen -- cgit From b74262a336d3e5cf69930fcec69a12fdad16d76c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 22 Jul 2023 08:00:42 +0800 Subject: fix(terminal): send Shift-Home Shift-End Ctrl-Home Ctrl-End (#24418) --- test/functional/terminal/buffer_spec.lua | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 8b43f5cf9c..3bc03a4117 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -17,6 +17,7 @@ local sleep = helpers.sleep local funcs = helpers.funcs local is_os = helpers.is_os local skip = helpers.skip +local nvim_prog = helpers.nvim_prog describe(':terminal buffer', function() local screen @@ -455,6 +456,33 @@ describe('terminal input', function() end) end) +describe('terminal input', function() + it('sends various special keys with modifiers', function() + clear() + local screen = thelpers.screen_setup(0, + string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--cmd", "startinsert"]]=], nvim_prog)) + screen:expect{grid=[[ + {1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] 0,1 All}| + {3:-- INSERT --} | + {3:-- TERMINAL --} | + ]]} + for _, key in ipairs({ + '', '', '', + '', '', '', '', '', '', + '', '', '', '', '', '', + '', '', '', '', '', '', + '', '', '', '', '', '', + }) do + feed('' .. key) + retry(nil, nil, function() eq(key, meths.get_current_line()) end) + end + end) +end) + if is_os('win') then describe(':terminal in Windows', function() local screen -- cgit From f0d618667a8a460b2c6135da19c74f0a4ad52128 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Jul 2023 08:53:59 +0800 Subject: test: check that TextChangedT cannot delete terminal buffer (#24437) --- test/functional/terminal/buffer_spec.lua | 8 -------- 1 file changed, 8 deletions(-) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 3bc03a4117..9b690bed74 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -414,14 +414,6 @@ describe('on_lines does not emit out-of-bounds line indexes when', function() feed_command('bdelete!') eq('', exec_lua([[return _G.cb_error]])) end) - - it('runs TextChangedT event', function() - meths.set_var('called', 0) - command('autocmd TextChangedT * ++once let g:called = 1') - feed_command('terminal') - feed('iaa') - eq(1, meths.get_var('called')) - end) end) it('terminal truncates number of composing characters to 5', function() -- cgit From ce56ad2ba7c93c5053b657cd99642b375a944607 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 23 Jul 2023 12:46:56 +0800 Subject: test: reduce flakiness (#24443) Avoid consecutive RPC requests involving :startinsert or :stopinsert, because consecutive RPC requests may be processed together, before the :startinsert or :stopinsert takes effect. Also change some feed_command() to command() to make tests faster. --- test/functional/terminal/buffer_spec.lua | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 9b690bed74..888d123b17 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -24,8 +24,7 @@ describe(':terminal buffer', function() before_each(function() clear() - feed_command('set modifiable swapfile undolevels=20') - poke_eventloop() + command('set modifiable swapfile undolevels=20') screen = thelpers.screen_setup() end) @@ -199,7 +198,6 @@ describe(':terminal buffer', function() it('handles loss of focus gracefully', function() -- Change the statusline to avoid printing the file name, which varies. nvim('set_option_value', 'statusline', '==========', {}) - feed_command('set laststatus=0') -- Save the buffer number of the terminal for later testing. local tbuf = eval('bufnr("%")') @@ -232,8 +230,6 @@ describe(':terminal buffer', function() neq(tbuf, eval('bufnr("%")')) feed_command('quit!') -- Should exit the new window, not the terminal. eq(tbuf, eval('bufnr("%")')) - - feed_command('set laststatus=1') -- Restore laststatus to the default. end) it('term_close() use-after-free #4393', function() @@ -433,7 +429,7 @@ describe('terminal input', function() _G.input_data = _G.input_data .. data end }) ]]) - command('startinsert') + feed('i') poke_eventloop() end) -- cgit From 0a7fda6fa0067ee61fee60d123967c3f14431007 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Aug 2023 09:34:13 +0800 Subject: fix(terminal): include modifiers when forwarding mouse (#24549) --- test/functional/terminal/buffer_spec.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index 888d123b17..ce47e4715c 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -464,6 +464,10 @@ describe('terminal input', function() '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', + '', '', '<2-LeftMouse>', '<2-LeftRelease>', + '', '', '<2-RightMouse>', '<2-RightRelease>', + '', '', '<2-MiddleMouse>', '<2-MiddleRelease>', + '', '', '', '', }) do feed('' .. key) retry(nil, nil, function() eq(key, meths.get_current_line()) end) -- cgit From 21d466c1b985bcb0b80cd71d3b33eef6c24004f1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 4 Aug 2023 10:24:27 +0800 Subject: fix(terminal): forward horizontal mouse scrolling (#24552) --- test/functional/terminal/buffer_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/functional/terminal/buffer_spec.lua') diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua index ce47e4715c..6fcd029a5b 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -468,6 +468,7 @@ describe('terminal input', function() '', '', '<2-RightMouse>', '<2-RightRelease>', '', '', '<2-MiddleMouse>', '<2-MiddleRelease>', '', '', '', '', + '', '', '', '', }) do feed('' .. key) retry(nil, nil, function() eq(key, meths.get_current_line()) end) -- cgit