From 85be914879d49435c3b689efd5f1dae70e81d168 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 30 Nov 2023 10:55:21 +0800 Subject: test: unskip more terminal tests on Windows (#26315) --- test/functional/terminal/buffer_spec.lua | 1 - 1 file changed, 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 6fcd029a5b..6d8c214d87 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -261,7 +261,6 @@ describe(':terminal buffer', function() end) it('it works with set rightleft #11438', function() - skip(is_os('win')) local columns = eval('&columns') feed(string.rep('a', columns)) command('set rightleft') -- cgit From 64a14026d76ba1798d91e15a941fcb6af7cbc5ad Mon Sep 17 00:00:00 2001 From: Evgeni Chasnovski Date: Wed, 29 Nov 2023 22:16:09 +0200 Subject: 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. --- test/functional/terminal/buffer_spec.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 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 6d8c214d87..423e7bdf21 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -446,8 +446,10 @@ 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)) + local screen = thelpers.screen_setup( + 0, + string.format([=[["%s", "-u", "NONE", "-i", "NONE", "--cmd", 'colorscheme vim', "--cmd", "startinsert"]]=], nvim_prog) + ) screen:expect{grid=[[ {1: } | {4:~ }| -- cgit From a5a346678a8211ea07f318de42e557ad3909f65e Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 5 Dec 2023 14:26:46 -0800 Subject: test: set notermguicolors in tests Set 'notermguicolors' in tests which spawn a child Nvim process to force existing tests to use 16 colors. Also refactor the child process invocation to make things a little bit less messy. --- test/functional/terminal/buffer_spec.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 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 423e7bdf21..b92f1b1592 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -17,7 +17,6 @@ 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 @@ -446,10 +445,13 @@ 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", 'colorscheme vim', "--cmd", "startinsert"]]=], nvim_prog) - ) + local screen = thelpers.setup_child_nvim({ + '-u', 'NONE', + '-i', 'NONE', + '--cmd', 'colorscheme vim', + '--cmd', 'set notermguicolors', + '--cmd', 'startinsert', + }) screen:expect{grid=[[ {1: } | {4:~ }| -- cgit From 6b00b8a369480a6535e7d286dd6ea27a6b0c94a5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 7 Dec 2023 07:15:37 +0800 Subject: test(terminal): remove unnecessary string operations (#26434) --- 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 b92f1b1592..7a52ee2b13 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -487,7 +487,7 @@ if is_os('win') then clear() feed_command('set modifiable swapfile undolevels=20') poke_eventloop() - local cmd = '["cmd.exe","/K","PROMPT=$g$s"]' + local cmd = { "cmd.exe", "/K", "PROMPT=$g$s" } screen = thelpers.screen_setup(nil, cmd) end) -- cgit From aba954b662cc1223d11ac3dc99323b9ebf687085 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 7 Dec 2023 19:14:56 +0800 Subject: fix(terminal): never propagate $COLORTERM from outer env (#26440) If $COLORTERM is "truecolor" but the user sets 'notermguicolors', propagating $COLORTERM to :terminal usually doesn't work well. --- test/functional/terminal/buffer_spec.lua | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 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 7a52ee2b13..ece09bca88 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -1,8 +1,10 @@ local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') local thelpers = require('test.functional.terminal.helpers') local assert_alive = helpers.assert_alive local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim local poke_eventloop = helpers.poke_eventloop +local nvim_prog = helpers.nvim_prog local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source local pcall_err = helpers.pcall_err local eq, neq = helpers.eq, helpers.neq @@ -559,4 +561,52 @@ describe('termopen()', function() eq("Vim:E11: Invalid in command-line window; executes, CTRL-C quits", pcall_err(funcs.termopen, "bar")) end) + + describe('$COLORTERM value', function() + if skip(is_os('win'), 'Not applicable for Windows') then return end + + before_each(function() + -- Outer value should never be propagated to :terminal + funcs.setenv('COLORTERM', 'wrongvalue') + end) + + local function test_term_colorterm(expected, opts) + local screen = Screen.new(50, 4) + screen:attach() + funcs.termopen({ + nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', + '-c', 'echo $COLORTERM | quit', + }, opts) + screen:expect(([[ + ^%s{MATCH:%%s+}| + [Process exited 0] | + | + | + ]]):format(expected)) + end + + describe("with 'notermguicolors'", function() + before_each(function() + command('set notermguicolors') + end) + it('is empty by default', function() + test_term_colorterm('') + end) + it('can be overridden', function() + test_term_colorterm('expectedvalue', { env = { COLORTERM = 'expectedvalue' } }) + end) + end) + + describe("with 'termguicolors'", function() + before_each(function() + command('set termguicolors') + end) + it('is "truecolor" by default', function() + test_term_colorterm('truecolor') + end) + it('can be overridden', function() + test_term_colorterm('expectedvalue', { env = { COLORTERM = 'expectedvalue' } }) + end) + end) + end) end) -- cgit From 1037ce2e461034a20e35ad59969fd05d5ad68b91 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 9 Dec 2023 20:42:00 +0800 Subject: test: avoid repeated screen lines in expected states This is the command invoked repeatedly to make the changes: :%s/^\(.*\)|\%(\*\(\d\+\)\)\?$\n\1|\%(\*\(\d\+\)\)\?$/\=submatch(1)..'|*'..(max([str2nr(submatch(2)),1])+max([str2nr(submatch(3)),1]))/g --- test/functional/terminal/buffer_spec.lua | 81 +++++++------------------------- 1 file changed, 17 insertions(+), 64 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 ece09bca88..02958a69e0 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -60,11 +60,7 @@ describe(':terminal buffer', function() feed(':set bufhidden=wipe:enew') screen:expect([[ ^ | - {4:~ }| - {4:~ }| - {4:~ }| - {4:~ }| - {4:~ }| + {4:~ }|*5 :enew | ]]) end) @@ -73,11 +69,7 @@ describe(':terminal buffer', function() feed(':bnext:l') screen:expect([[ ^ | - {4:~ }| - {4:~ }| - {4:~ }| - {4:~ }| - {4:~ }| + {4:~ }|*5 | ]]) end) @@ -89,11 +81,7 @@ describe(':terminal buffer', function() screen:expect([[ tty ready | {2:^ } | - | - | - | - | - | + |*5 ]]) end) @@ -113,10 +101,7 @@ describe(':terminal buffer', function() screen:expect([[ tty ready | {2:^ } | - | - | - | - | + |*4 {8:E21: Cannot make changes, 'modifiable' is off} | ]]) end) @@ -127,22 +112,16 @@ describe(':terminal buffer', function() feed('"ap"ap') screen:expect([[ ^tty ready | - appended tty ready | - appended tty ready | + appended tty ready |*2 {2: } | - | - | + |*2 :let @a = "appended " . @a | ]]) -- operator count is also taken into consideration feed('3"ap') screen:expect([[ ^tty ready | - appended tty ready | - appended tty ready | - appended tty ready | - appended tty ready | - appended tty ready | + appended tty ready |*5 :let @a = "appended " . @a | ]]) end) @@ -155,17 +134,14 @@ describe(':terminal buffer', function() ^tty ready | appended tty ready | {2: } | - | - | - | + |*3 :put a | ]]) -- line argument is only used to move the cursor feed_command('6put a') screen:expect([[ tty ready | - appended tty ready | - appended tty ready | + appended tty ready |*2 {2: } | | ^ | @@ -177,21 +153,13 @@ describe(':terminal buffer', function() feed(':bd!') screen:expect([[ ^ | - {4:~ }| - {4:~ }| - {4:~ }| - {4:~ }| - {4:~ }| + {4:~ }|*5 :bd! | ]]) feed_command('bnext') screen:expect([[ ^ | - {4:~ }| - {4:~ }| - {4:~ }| - {4:~ }| - {4:~ }| + {4:~ }|*5 :bnext | ]]) end) @@ -268,10 +236,7 @@ describe(':terminal buffer', function() screen:expect([[ ydaer ytt| {1:a}aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa| - | - | - | - | + |*4 {3:-- TERMINAL --} | ]]) command('bdelete!') @@ -309,10 +274,7 @@ describe(':terminal buffer', function() screen:expect{grid=[[ tty ready | {2:^ } | - | - | - | - | + |*4 {3:-- (terminal) --} | ]]} eq('ntT', funcs.mode(1)) @@ -321,10 +283,7 @@ describe(':terminal buffer', function() screen:expect{grid=[[ tty ready | {2: } | - | - | - | - | + |*4 :let g:x = 17^ | ]]} @@ -332,10 +291,7 @@ describe(':terminal buffer', function() screen:expect{grid=[[ tty ready | {1: } | - | - | - | - | + |*4 {3:-- TERMINAL --} | ]]} eq('t', funcs.mode(1)) @@ -456,9 +412,7 @@ describe('terminal input', function() }) screen:expect{grid=[[ {1: } | - {4:~ }| - {4:~ }| - {4:~ }| + {4:~ }|*3 {5:[No Name] 0,1 All}| {3:-- INSERT --} | {3:-- TERMINAL --} | @@ -580,8 +534,7 @@ describe('termopen()', function() screen:expect(([[ ^%s{MATCH:%%s+}| [Process exited 0] | - | - | + |*2 ]]):format(expected)) end -- cgit From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: refactor: format test/* --- test/functional/terminal/buffer_spec.lua | 178 ++++++++++++++++++++++--------- 1 file changed, 127 insertions(+), 51 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 02958a69e0..480ca96289 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -32,13 +32,19 @@ describe(':terminal buffer', function() it('terminal-mode forces various options', function() feed([[]]) command('setlocal cursorline cursorlineopt=both cursorcolumn scrolloff=4 sidescrolloff=7') - eq({ 'both', 1, 1, 4, 7 }, eval('[&l:cursorlineopt, &l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]')) + eq( + { 'both', 1, 1, 4, 7 }, + eval('[&l:cursorlineopt, &l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]') + ) eq('nt', eval('mode(1)')) -- Enter terminal-mode ("insert" mode in :terminal). feed('i') eq('t', eval('mode(1)')) - eq({ 'number', 1, 0, 0, 0 }, eval('[&l:cursorlineopt, &l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]')) + eq( + { 'number', 1, 0, 0, 0 }, + eval('[&l:cursorlineopt, &l:cursorline, &l:cursorcolumn, &l:scrolloff, &l:sidescrolloff]') + ) end) it('terminal-mode does not change cursorlineopt if cursorline is disabled', function() @@ -170,9 +176,7 @@ describe(':terminal buffer', function() -- Save the buffer number of the terminal for later testing. local tbuf = eval('bufnr("%")') - local exitcmd = is_os('win') - and "['cmd', '/c', 'exit']" - or "['sh', '-c', 'exit']" + local exitcmd = is_os('win') and "['cmd', '/c', 'exit']" or "['sh', '-c', 'exit']" source([[ function! SplitWindow(id, data, event) new @@ -180,7 +184,7 @@ describe(':terminal buffer', function() endfunction startinsert - call jobstart(]]..exitcmd..[[, {'on_exit': function("SplitWindow")}) + call jobstart(]] .. exitcmd .. [[, {'on_exit': function("SplitWindow")}) call feedkeys("\", 't') " vim will expect , but be exited out of " the terminal before it can be entered. ]]) @@ -197,7 +201,7 @@ describe(':terminal buffer', function() ]]) neq(tbuf, eval('bufnr("%")')) - feed_command('quit!') -- Should exit the new window, not the terminal. + feed_command('quit!') -- Should exit the new window, not the terminal. eq(tbuf, eval('bufnr("%")')) end) @@ -212,18 +216,18 @@ describe(':terminal buffer', function() feed_command('terminal') feed('') feed_command('confirm bdelete') - screen:expect{any='Close "term://'} + screen:expect { any = 'Close "term://' } end) it('with &confirm', function() feed_command('terminal') feed('') feed_command('bdelete') - screen:expect{any='E89'} + screen:expect { any = 'E89' } feed('') eq('terminal', eval('&buftype')) feed_command('set confirm | bdelete') - screen:expect{any='Close "term://'} + screen:expect { any = 'Close "term://' } feed('y') neq('terminal', eval('&buftype')) end) @@ -243,11 +247,15 @@ 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") + 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%)$', - exc_exec(cmd)) + matches( + '^Vim%(' + .. cmd:gsub('%%', '') + .. '%):E89: term://.*tty%-test.* will be killed %(add %! to override%)$', + exc_exec(cmd) + ) end command('call jobstop(&channel)') assert(0 >= eval('jobwait([&channel], 1000)[0]')) @@ -264,42 +272,50 @@ describe(':terminal buffer', function() it('does not segfault when pasting empty register #13955', function() feed('') - feed_command('put a') -- register a is empty + feed_command('put a') -- register a is empty helpers.assert_alive() end) it([[can use temporary normal mode ]], function() eq('t', funcs.mode(1)) feed [[]] - screen:expect{grid=[[ + screen:expect { + grid = [[ tty ready | {2:^ } | |*4 {3:-- (terminal) --} | - ]]} + ]], + } eq('ntT', funcs.mode(1)) feed [[:let g:x = 17]] - screen:expect{grid=[[ + screen:expect { + grid = [[ tty ready | {2: } | |*4 :let g:x = 17^ | - ]]} + ]], + } feed [[]] - screen:expect{grid=[[ + screen:expect { + grid = [[ tty ready | {1: } | |*4 {3:-- TERMINAL --} | - ]]} + ]], + } eq('t', funcs.mode(1)) end) it('writing to an existing file with :w fails #13549', function() - eq('Vim(write):E13: File exists (add ! to override)', - pcall_err(command, 'write test/functional/fixtures/tty-test.c')) + eq( + 'Vim(write):E13: File exists (add ! to override)', + pcall_err(command, 'write test/functional/fixtures/tty-test.c') + ) end) end) @@ -307,7 +323,7 @@ describe('No heap-buffer-overflow when using', function() local testfilename = 'Xtestfile-functional-terminal-buffers_spec' before_each(function() - write_file(testfilename, "aaaaaaaaaaaaaaaaaaaaaaaaaaaa") + write_file(testfilename, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa') end) after_each(function() @@ -373,7 +389,9 @@ it('terminal truncates number of composing characters to 5', function() local chan = meths.open_term(0, {}) local composing = ('a̳'):sub(2) meths.chan_send(chan, 'a' .. composing:rep(8)) - retry(nil, nil, function() eq('a' .. composing:rep(5), meths.get_current_line()) end) + retry(nil, nil, function() + eq('a' .. composing:rep(5), meths.get_current_line()) + end) end) describe('terminal input', function() @@ -404,33 +422,79 @@ describe('terminal input', function() it('sends various special keys with modifiers', function() clear() local screen = thelpers.setup_child_nvim({ - '-u', 'NONE', - '-i', 'NONE', - '--cmd', 'colorscheme vim', - '--cmd', 'set notermguicolors', - '--cmd', 'startinsert', + '-u', + 'NONE', + '-i', + 'NONE', + '--cmd', + 'colorscheme vim', + '--cmd', + 'set notermguicolors', + '--cmd', + 'startinsert', }) - screen:expect{grid=[[ + screen:expect { + grid = [[ {1: } | {4:~ }|*3 {5:[No Name] 0,1 All}| {3:-- INSERT --} | {3:-- TERMINAL --} | - ]]} + ]], + } for _, key in ipairs({ - '', '', '', - '', '', '', '', '', '', - '', '', '', '', '', '', - '', '', '', '', '', '', - '', '', '', '', '', '', - '', '', '<2-LeftMouse>', '<2-LeftRelease>', - '', '', '<2-RightMouse>', '<2-RightRelease>', - '', '', '<2-MiddleMouse>', '<2-MiddleRelease>', - '', '', '', '', - '', '', '', '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '<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) + retry(nil, nil, function() + eq(key, meths.get_current_line()) + end) end end) end) @@ -443,7 +507,7 @@ if is_os('win') then clear() feed_command('set modifiable swapfile undolevels=20') poke_eventloop() - local cmd = { "cmd.exe", "/K", "PROMPT=$g$s" } + local cmd = { 'cmd.exe', '/K', 'PROMPT=$g$s' } screen = thelpers.screen_setup(nil, cmd) end) @@ -508,16 +572,22 @@ describe('termopen()', function() 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")) + 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")) + feed('q:') + eq( + 'Vim:E11: Invalid in command-line window; executes, CTRL-C quits', + pcall_err(funcs.termopen, 'bar') + ) end) describe('$COLORTERM value', function() - if skip(is_os('win'), 'Not applicable for Windows') then return end + if skip(is_os('win'), 'Not applicable for Windows') then + return + end before_each(function() -- Outer value should never be propagated to :terminal @@ -528,8 +598,14 @@ describe('termopen()', function() local screen = Screen.new(50, 4) screen:attach() funcs.termopen({ - nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', - '-c', 'echo $COLORTERM | quit', + nvim_prog, + '-u', + 'NONE', + '-i', + 'NONE', + '--headless', + '-c', + 'echo $COLORTERM | quit', }, opts) screen:expect(([[ ^%s{MATCH:%%s+}| -- cgit From beca827212b106114c371f8bb61aa1a50810062f Mon Sep 17 00:00:00 2001 From: Ghjuvan Lacambre Date: Tue, 9 Jan 2024 15:27:56 +0100 Subject: feat(terminal): trigger TermRequest autocommand events (#22159) This commit implements a new TermRequest autocommand event and has Neovim emit this event when children of terminal buffers emit an OSC or DCS sequence libvterm does not handle. The TermRequest autocommand event has additional data in the v:termrequest variable. Co-authored-by: Gregory Anders --- test/functional/terminal/buffer_spec.lua | 12 ++++++++++++ 1 file changed, 12 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 480ca96289..d0462b5619 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -317,6 +317,18 @@ describe(':terminal buffer', function() pcall_err(command, 'write test/functional/fixtures/tty-test.c') ) end) + + it('emits TermRequest events', function() + command('split') + command('enew') + local term = meths.open_term(0, {}) + -- cwd will be inserted in a file URI, which cannot contain backs + local cwd = funcs.getcwd():gsub('\\', '/') + local parent = cwd:match('^(.+/)') + local expected = '\027]7;file://host' .. parent + meths.chan_send(term, string.format('%s\027\\', expected)) + eq(expected, eval('v:termrequest')) + end) end) describe('No heap-buffer-overflow when using', function() -- cgit From fa17a5ab49dff5a2e4de7bd2faee31f5458993aa Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Tue, 9 Jan 2024 21:31:37 -0600 Subject: fix(terminal): use terminal buffer for TermRequest autocommand (#26974) --- test/functional/terminal/buffer_spec.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 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 d0462b5619..497d7668e8 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -318,16 +318,23 @@ describe(':terminal buffer', function() ) end) - it('emits TermRequest events', function() + it('emits TermRequest events #26972', function() command('split') command('enew') local term = meths.open_term(0, {}) + local termbuf = meths.get_current_buf().id + + -- Test that autocommand buffer is associated with the terminal buffer, not the current buffer + command('au TermRequest * let g:termbuf = +expand("")') + command('wincmd p') + -- cwd will be inserted in a file URI, which cannot contain backs local cwd = funcs.getcwd():gsub('\\', '/') local parent = cwd:match('^(.+/)') local expected = '\027]7;file://host' .. parent meths.chan_send(term, string.format('%s\027\\', expected)) eq(expected, eval('v:termrequest')) + eq(termbuf, eval('g:termbuf')) end) end) -- cgit From 7a259d01aed52134a1675e47d9054ccad7ef7cbb Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 11:41:09 +0000 Subject: test: remove helpers.sleep() --- 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 497d7668e8..48a38864d6 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -15,7 +15,7 @@ local command = helpers.command local exc_exec = helpers.exc_exec local matches = helpers.matches local exec_lua = helpers.exec_lua -local sleep = helpers.sleep +local sleep = vim.uv.sleep local funcs = helpers.funcs local is_os = helpers.is_os local skip = helpers.skip -- cgit From c30f2e3182e3b50e7c03932027ac55edfc8ada4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:44:54 +0000 Subject: test: typing for helpers.meths --- test/functional/terminal/buffer_spec.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 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 48a38864d6..541812b4be 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -321,8 +321,8 @@ describe(':terminal buffer', function() it('emits TermRequest events #26972', function() command('split') command('enew') - local term = meths.open_term(0, {}) - local termbuf = meths.get_current_buf().id + local term = meths.nvim_open_term(0, {}) + local termbuf = meths.nvim_get_current_buf().id -- Test that autocommand buffer is associated with the terminal buffer, not the current buffer command('au TermRequest * let g:termbuf = +expand("")') @@ -332,7 +332,7 @@ describe(':terminal buffer', function() local cwd = funcs.getcwd():gsub('\\', '/') local parent = cwd:match('^(.+/)') local expected = '\027]7;file://host' .. parent - meths.chan_send(term, string.format('%s\027\\', expected)) + meths.nvim_chan_send(term, string.format('%s\027\\', expected)) eq(expected, eval('v:termrequest')) eq(termbuf, eval('g:termbuf')) end) @@ -405,11 +405,11 @@ end) it('terminal truncates number of composing characters to 5', function() clear() - local chan = meths.open_term(0, {}) + local chan = meths.nvim_open_term(0, {}) local composing = ('a̳'):sub(2) - meths.chan_send(chan, 'a' .. composing:rep(8)) + meths.nvim_chan_send(chan, 'a' .. composing:rep(8)) retry(nil, nil, function() - eq('a' .. composing:rep(5), meths.get_current_line()) + eq('a' .. composing:rep(5), meths.nvim_get_current_line()) end) end) @@ -512,7 +512,7 @@ describe('terminal input', function() }) do feed('' .. key) retry(nil, nil, function() - eq(key, meths.get_current_line()) + eq(key, meths.nvim_get_current_line()) end) end end) -- cgit From 4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 13:11:28 +0000 Subject: test: normalise nvim bridge functions - remove helpers.cur*meths - remove helpers.nvim --- test/functional/terminal/buffer_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 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 541812b4be..7029b81de0 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local thelpers = require('test.functional.terminal.helpers') local assert_alive = helpers.assert_alive -local feed, clear, nvim = helpers.feed, helpers.clear, helpers.nvim +local feed, clear = helpers.feed, helpers.clear local poke_eventloop = helpers.poke_eventloop local nvim_prog = helpers.nvim_prog local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source @@ -92,12 +92,12 @@ describe(':terminal buffer', function() end) it('does not create swap files', function() - local swapfile = nvim('exec', 'swapname', true):gsub('\n', '') + local swapfile = meths.nvim_exec('swapname', true):gsub('\n', '') eq(nil, io.open(swapfile)) end) it('does not create undofiles files', function() - local undofile = nvim('eval', 'undofile(bufname("%"))') + local undofile = meths.nvim_eval('undofile(bufname("%"))') eq(nil, io.open(undofile)) end) end) @@ -172,7 +172,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_value', 'statusline', '==========', {}) + meths.nvim_set_option_value('statusline', '==========', {}) -- Save the buffer number of the terminal for later testing. local tbuf = eval('bufnr("%")') -- cgit From 795f896a5772d5e0795f86642bdf90c82efac45c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 17:59:57 +0000 Subject: test: rename (meths, funcs) -> (api, fn) --- test/functional/terminal/buffer_spec.lua | 38 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 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 7029b81de0..b6eb8ebdfd 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -8,7 +8,7 @@ local nvim_prog = helpers.nvim_prog local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source local pcall_err = helpers.pcall_err local eq, neq = helpers.eq, helpers.neq -local meths = helpers.meths +local api = helpers.api local retry = helpers.retry local write_file = helpers.write_file local command = helpers.command @@ -16,7 +16,7 @@ local exc_exec = helpers.exc_exec local matches = helpers.matches local exec_lua = helpers.exec_lua local sleep = vim.uv.sleep -local funcs = helpers.funcs +local fn = helpers.fn local is_os = helpers.is_os local skip = helpers.skip @@ -92,12 +92,12 @@ describe(':terminal buffer', function() end) it('does not create swap files', function() - local swapfile = meths.nvim_exec('swapname', true):gsub('\n', '') + local swapfile = api.nvim_exec('swapname', true):gsub('\n', '') eq(nil, io.open(swapfile)) end) it('does not create undofiles files', function() - local undofile = meths.nvim_eval('undofile(bufname("%"))') + local undofile = api.nvim_eval('undofile(bufname("%"))') eq(nil, io.open(undofile)) end) end) @@ -172,7 +172,7 @@ describe(':terminal buffer', function() it('handles loss of focus gracefully', function() -- Change the statusline to avoid printing the file name, which varies. - meths.nvim_set_option_value('statusline', '==========', {}) + api.nvim_set_option_value('statusline', '==========', {}) -- Save the buffer number of the terminal for later testing. local tbuf = eval('bufnr("%")') @@ -277,7 +277,7 @@ describe(':terminal buffer', function() end) it([[can use temporary normal mode ]], function() - eq('t', funcs.mode(1)) + eq('t', fn.mode(1)) feed [[]] screen:expect { grid = [[ @@ -287,7 +287,7 @@ describe(':terminal buffer', function() {3:-- (terminal) --} | ]], } - eq('ntT', funcs.mode(1)) + eq('ntT', fn.mode(1)) feed [[:let g:x = 17]] screen:expect { @@ -308,7 +308,7 @@ describe(':terminal buffer', function() {3:-- TERMINAL --} | ]], } - eq('t', funcs.mode(1)) + eq('t', fn.mode(1)) end) it('writing to an existing file with :w fails #13549', function() @@ -321,18 +321,18 @@ describe(':terminal buffer', function() it('emits TermRequest events #26972', function() command('split') command('enew') - local term = meths.nvim_open_term(0, {}) - local termbuf = meths.nvim_get_current_buf().id + local term = api.nvim_open_term(0, {}) + local termbuf = api.nvim_get_current_buf().id -- Test that autocommand buffer is associated with the terminal buffer, not the current buffer command('au TermRequest * let g:termbuf = +expand("")') command('wincmd p') -- cwd will be inserted in a file URI, which cannot contain backs - local cwd = funcs.getcwd():gsub('\\', '/') + local cwd = fn.getcwd():gsub('\\', '/') local parent = cwd:match('^(.+/)') local expected = '\027]7;file://host' .. parent - meths.nvim_chan_send(term, string.format('%s\027\\', expected)) + api.nvim_chan_send(term, string.format('%s\027\\', expected)) eq(expected, eval('v:termrequest')) eq(termbuf, eval('g:termbuf')) end) @@ -405,11 +405,11 @@ end) it('terminal truncates number of composing characters to 5', function() clear() - local chan = meths.nvim_open_term(0, {}) + local chan = api.nvim_open_term(0, {}) local composing = ('a̳'):sub(2) - meths.nvim_chan_send(chan, 'a' .. composing:rep(8)) + api.nvim_chan_send(chan, 'a' .. composing:rep(8)) retry(nil, nil, function() - eq('a' .. composing:rep(5), meths.nvim_get_current_line()) + eq('a' .. composing:rep(5), api.nvim_get_current_line()) end) end) @@ -512,7 +512,7 @@ describe('terminal input', function() }) do feed('' .. key) retry(nil, nil, function() - eq(key, meths.nvim_get_current_line()) + eq(key, api.nvim_get_current_line()) end) end end) @@ -599,7 +599,7 @@ describe('termopen()', function() feed('q:') eq( 'Vim:E11: Invalid in command-line window; executes, CTRL-C quits', - pcall_err(funcs.termopen, 'bar') + pcall_err(fn.termopen, 'bar') ) end) @@ -610,13 +610,13 @@ describe('termopen()', function() before_each(function() -- Outer value should never be propagated to :terminal - funcs.setenv('COLORTERM', 'wrongvalue') + fn.setenv('COLORTERM', 'wrongvalue') end) local function test_term_colorterm(expected, opts) local screen = Screen.new(50, 4) screen:attach() - funcs.termopen({ + fn.termopen({ nvim_prog, '-u', 'NONE', -- cgit From 8f02ae82e203920b472d17e75a61763f3a409a7b Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 16 Jan 2024 13:26:21 +0000 Subject: test: use integers for API Buffer/Window/Tabpage EXT types --- 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 b6eb8ebdfd..8dc52a4d5e 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -322,7 +322,7 @@ describe(':terminal buffer', function() command('split') command('enew') local term = api.nvim_open_term(0, {}) - local termbuf = api.nvim_get_current_buf().id + local termbuf = api.nvim_get_current_buf() -- Test that autocommand buffer is associated with the terminal buffer, not the current buffer command('au TermRequest * let g:termbuf = +expand("")') -- cgit From 99288ecc77e429ffe06842157e72ed612e97a419 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 24 Feb 2024 05:12:30 +0800 Subject: fix(terminal): block input when there is pending TermRequest (#27589) --- test/functional/terminal/buffer_spec.lua | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 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 8dc52a4d5e..376b7b849e 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -319,8 +319,7 @@ describe(':terminal buffer', function() end) it('emits TermRequest events #26972', function() - command('split') - command('enew') + command('new') local term = api.nvim_open_term(0, {}) local termbuf = api.nvim_get_current_buf() @@ -336,6 +335,35 @@ describe(':terminal buffer', function() eq(expected, eval('v:termrequest')) eq(termbuf, eval('g:termbuf')) end) + + it('TermReqeust synchronization #27572', function() + command('new') + command('autocmd! nvim_terminal TermRequest') + local term = exec_lua([[ + _G.input = {} + local term = vim.api.nvim_open_term(0, { + on_input = function(_, _, _, data) + table.insert(_G.input, data) + end, + force_crlf = false, + }) + vim.api.nvim_create_autocmd('TermRequest', { + callback = function(args) + if args.data == '\027]11;?' then + table.insert(_G.input, '\027]11;rgb:0000/0000/0000\027\\') + end + end + }) + return term + ]]) + api.nvim_chan_send(term, '\027]11;?\007\027[5n\027]11;?\007\027[5n') + eq({ + '\027]11;rgb:0000/0000/0000\027\\', + '\027[0n', + '\027]11;rgb:0000/0000/0000\027\\', + '\027[0n', + }, exec_lua('return _G.input')) + end) end) describe('No heap-buffer-overflow when using', function() -- cgit From 268066e01400f55b0c38716f0d6ee3dece10c43e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 26 Feb 2024 09:47:49 +0800 Subject: fix(process): start pty process eof timer on main thread (#27625) --- test/functional/terminal/buffer_spec.lua | 1 - 1 file changed, 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 376b7b849e..a8dddc0c1c 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -247,7 +247,6 @@ 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( -- cgit From 8b4e26915612caf2d143edca31919cae18a848a1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 26 Feb 2024 10:11:59 +0800 Subject: test(terminal/buffer_spec): re-skip bang 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 a8dddc0c1c..376b7b849e 100644 --- a/test/functional/terminal/buffer_spec.lua +++ b/test/functional/terminal/buffer_spec.lua @@ -247,6 +247,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( -- cgit