From 51e817dc1be46947073529fa97bb07a6a8078dd4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 3 Dec 2017 03:38:58 +0100 Subject: startup: stdin as text instead of commands Treat stdin as text by default (so the "-" file is not needed): echo foo | nvim It works with file args (implemented in next commit), too: echo foo | nvim file1.txt file2.txt Why? Because: - Execution of input is (1) almost always unintentional/confusing, and (2) potentially destructive. - Avoids the need for time-delayed warning. #7659 - The _common_ case is to open text in a buffer, not send commands. Note: - Not for Ex-mode (-es) because it is used by scripts. But maybe `-Es`? - Not for --headless, because stdio may be a protocol stream and may be used for any purpose by stdioopen(). To treat stdin as Normal-mode commands, use `-s -` instead: echo ifoo | nvim -s - Other alternatives: - Replay a register. E.g. the following mostly works, except @q aborts on any "beep" (e.g. if the cursor can't move). nvim -c '%d q|norm @q' - - Future: Let `:%source` work with unsaved buffer contents? closes #2087 closes #7659 --- test/functional/core/startup_spec.lua | 64 +++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 14 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index ae7f949e52..0d4199ea6e 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -9,11 +9,13 @@ local nvim_prog = helpers.nvim_prog local nvim_set = helpers.nvim_set local read_file = helpers.read_file local retry = helpers.retry +local sleep = helpers.sleep local iswin = helpers.iswin describe('startup', function() before_each(function() clear() + os.remove('Xtest_startup_ttyout') end) after_each(function() os.remove('Xtest_startup_ttyout') @@ -46,8 +48,8 @@ describe('startup', function() end -- Running in :terminal command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]] - ..nvim_set..[[\" ]] - ..[[-c \"echo has('ttyin') has('ttyout')\""]] + ..nvim_set..[[\"]] + ..[[ -c \"echo has('ttyin') has('ttyout')\""]] ..[[, shellescape(v:progpath))]]) screen:expect([[ ^ | @@ -56,41 +58,75 @@ describe('startup', function() ]]) end) it('output to pipe: has("ttyin")==1 has("ttyout")==0', function() - local screen = Screen.new(25, 5) - screen:attach() if iswin() then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]] - ..nvim_set..[[\" ]] - ..[[-c \"call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')\"]] - ..[[-c q | cat -v"]] -- Output to a pipe. + ..nvim_set..[[\"]] + ..[[ -c \"call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')\"]] + ..[[ -c q | cat -v"]] -- Output to a pipe. ..[[, shellescape(v:progpath))]]) retry(nil, 3000, function() - screen:sleep(1) + sleep(1) eq('1\n0\n', -- stdin is a TTY, stdout is a pipe read_file('Xtest_startup_ttyout')) end) end) it('input from pipe: has("ttyin")==0 has("ttyout")==1', function() - local screen = Screen.new(25, 5) - screen:attach() if iswin() then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end -- Running in :terminal command([[exe printf("terminal echo foo | ]] -- Input from a pipe. ..[[%s -u NONE -i NONE --cmd \"]] - ..nvim_set..[[\" ]] - ..[[-c \"call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')\"]] - ..[[-c q -- -"]] + ..nvim_set..[[\"]] + ..[[ -c \"call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')\"]] + ..[[ -c q -- -"]] ..[[, shellescape(v:progpath))]]) retry(nil, 3000, function() - screen:sleep(1) + sleep(1) eq('0\n1\n', -- stdin is a pipe, stdout is a TTY read_file('Xtest_startup_ttyout')) end) end) + it('input from pipe (implicit) #7679', function() + local screen = Screen.new(25, 3) + screen:attach() + if iswin() then + command([[set shellcmdflag=/s\ /c shellxquote=\"]]) + end + -- Running in :terminal + command([[exe printf("terminal echo foo | ]] -- Input from a pipe. + ..[[%s -u NONE -i NONE --cmd \"]] + ..nvim_set..[[\"]] + ..[[ -c \"echo has('ttyin') has('ttyout')\""]] + ..[[, shellescape(v:progpath))]]) + screen:expect([[ + ^foo | + 0 1 | + | + ]]) + end) + it('input from pipe (implicit) + file args #7679', function() + local screen = Screen.new(25, 3) + screen:attach() + if iswin() then + command([[set shellcmdflag=/s\ /c shellxquote=\"]]) + end + command([[exe "terminal echo ohyeah | "]] -- Input from a pipe. + ..[[.shellescape(v:progpath)." -u NONE -i NONE --cmd \"]] + ..nvim_set..[[\"]] + ..[[ --cmd \"set shortmess+=I\"]] + ..[[ -c \"echo has('ttyin') has('ttyout') 'bufs='.bufnr('$')\"]] + ..[[ -- test/functional/fixtures/shell-test.c]] + ..[[ test/functional/fixtures/tty-test.c]] + ..[["]]) + screen:expect([[ + ^ohyeah | + 0 1 bufs=3 | + | + ]]) + end) end) -- cgit From 63058fb5b05a1293dd50851af46f33fc15110829 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 27 May 2018 03:41:02 +0200 Subject: startup: fix -es/-Es so they are actually silent silent-mode (-es/-Es) has been broken for years. The workaround up to now was to include --headless. But --headless is not equivalent because it prints all messages, not the limited subset defined by silent-mode. --- test/functional/core/startup_spec.lua | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 0d4199ea6e..b8af5de664 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -109,13 +109,14 @@ describe('startup', function() ]]) end) it('input from pipe (implicit) + file args #7679', function() + if helpers.pending_win32(pending) then return end local screen = Screen.new(25, 3) screen:attach() if iswin() then command([[set shellcmdflag=/s\ /c shellxquote=\"]]) end command([[exe "terminal echo ohyeah | "]] -- Input from a pipe. - ..[[.shellescape(v:progpath)." -u NONE -i NONE --cmd \"]] + ..[[.shellescape(v:progpath)." -n -u NONE -i NONE --cmd \"]] ..nvim_set..[[\"]] ..[[ --cmd \"set shortmess+=I\"]] ..[[ -c \"echo has('ttyin') has('ttyout') 'bufs='.bufnr('$')\"]] @@ -128,5 +129,33 @@ describe('startup', function() | ]]) end) + + it('stdin with -es, -Es #7679', function() + local input = { 'append', 'line1', 'line2', '.', '%print', '' } + local inputstr = table.concat(input, '\n') + + -- + -- -Es: read stdin as text + -- + if not iswin() then + eq('partylikeits1999\n', + funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '-Es', '+.print', 'test/functional/fixtures/tty-test.c' }, + { 'partylikeits1999' })) + eq(inputstr, + funcs.system({nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' }, + input)) + end + + + -- + -- -es: read stdin as ex-commands + -- + eq(' encoding=utf-8\n', + funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '-es', 'test/functional/fixtures/tty-test.c' }, + { 'set encoding', '' })) + eq('line1\nline2\n', + funcs.system({nvim_prog, '-i', 'NONE', '-es', '-' }, + input)) + end) end) -- cgit From 4211255c755513aa91d4a9277b69b557fc6658ee Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 28 May 2018 07:09:55 +0200 Subject: startup: allow explicit "-" file arg with --headless --- test/functional/core/startup_spec.lua | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index b8af5de664..4223e55d90 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -109,25 +109,16 @@ describe('startup', function() ]]) end) it('input from pipe (implicit) + file args #7679', function() - if helpers.pending_win32(pending) then return end - local screen = Screen.new(25, 3) - screen:attach() - if iswin() then - command([[set shellcmdflag=/s\ /c shellxquote=\"]]) - end - command([[exe "terminal echo ohyeah | "]] -- Input from a pipe. - ..[[.shellescape(v:progpath)." -n -u NONE -i NONE --cmd \"]] - ..nvim_set..[[\"]] - ..[[ --cmd \"set shortmess+=I\"]] - ..[[ -c \"echo has('ttyin') has('ttyout') 'bufs='.bufnr('$')\"]] - ..[[ -- test/functional/fixtures/shell-test.c]] - ..[[ test/functional/fixtures/tty-test.c]] - ..[["]]) - screen:expect([[ - ^ohyeah | - 0 1 bufs=3 | - | - ]]) + eq('ohyeah\r\n0 0 bufs=3', + funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '--headless', + '+.print', + "+echo has('ttyin') has('ttyout') 'bufs='.bufnr('$')", + '+qall!', + '-', + 'test/functional/fixtures/tty-test.c', + 'test/functional/fixtures/shell-test.c', + }, + { 'ohyeah', '' })) end) it('stdin with -es, -Es #7679', function() @@ -137,15 +128,12 @@ describe('startup', function() -- -- -Es: read stdin as text -- - if not iswin() then eq('partylikeits1999\n', funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '-Es', '+.print', 'test/functional/fixtures/tty-test.c' }, - { 'partylikeits1999' })) + { 'partylikeits1999', '' })) eq(inputstr, funcs.system({nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' }, input)) - end - -- -- -es: read stdin as ex-commands -- cgit From 1f300e08b8c0c35b2f3d79506ae9817cd8591624 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 29 May 2018 07:22:15 +0200 Subject: win/startup: remove --literal Fixes 2 failing tests in startup_spec.lua. The Windows-only `--literal` option complicates support of "stdin-as-text + file-args" (#7679). Could work around it, but it's not worth the trouble: - users have a reasonable (and englightening) alternative: nvim +"n *" - "always literal" is more consistent/predictable - avoids platform-specific special-case Unrelated changes: - Replace fileno(stdxx) with STDXX_FILENO for consistency (not motivated by any observed technical reason). --- test/functional/core/startup_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 4223e55d90..d15faaf0a9 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -108,7 +108,7 @@ describe('startup', function() | ]]) end) - it('input from pipe (implicit) + file args #7679', function() + it('input from pipe + file args #7679', function() eq('ohyeah\r\n0 0 bufs=3', funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '--headless', '+.print', @@ -121,7 +121,7 @@ describe('startup', function() { 'ohyeah', '' })) end) - it('stdin with -es, -Es #7679', function() + it('stdin with -es/-Es #7679', function() local input = { 'append', 'line1', 'line2', '.', '%print', '' } local inputstr = table.concat(input, '\n') -- cgit From d8c7ff13352d7182826b5716ff3b6a66df241231 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 30 May 2018 07:21:45 +0200 Subject: cleanup, test interactive -E --- test/functional/core/startup_spec.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'test/functional/core') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index d15faaf0a9..f1f96ba626 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -4,6 +4,7 @@ local Screen = require('test.functional.ui.screen') local clear = helpers.clear local command = helpers.command local eq = helpers.eq +local feed = helpers.feed local funcs = helpers.funcs local nvim_prog = helpers.nvim_prog local nvim_set = helpers.nvim_set @@ -121,6 +122,18 @@ describe('startup', function() { 'ohyeah', '' })) end) + it('-e/-E interactive #7679', function() + clear('-E') + local screen = Screen.new(25, 3) + screen:attach() + feed("put ='from -E'") + screen:expect([[ + | + from -E | + :^ | + ]]) + end) + it('stdin with -es/-Es #7679', function() local input = { 'append', 'line1', 'line2', '.', '%print', '' } local inputstr = table.concat(input, '\n') -- cgit