diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-05-28 07:09:55 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2018-06-04 02:09:27 +0200 |
commit | 4211255c755513aa91d4a9277b69b557fc6658ee (patch) | |
tree | cf2a45252abaa216787d1f5e891ad9177348447b | |
parent | 63058fb5b05a1293dd50851af46f33fc15110829 (diff) | |
download | rneovim-4211255c755513aa91d4a9277b69b557fc6658ee.tar.gz rneovim-4211255c755513aa91d4a9277b69b557fc6658ee.tar.bz2 rneovim-4211255c755513aa91d4a9277b69b557fc6658ee.zip |
startup: allow explicit "-" file arg with --headless
-rw-r--r-- | src/nvim/main.c | 23 | ||||
-rw-r--r-- | src/nvim/os/input.c | 2 | ||||
-rw-r--r-- | test/functional/core/startup_spec.lua | 34 |
3 files changed, 27 insertions, 32 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c index 5d3e3ff083..79d5d40a8a 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -722,13 +722,14 @@ static void init_locale(void) /// Decides whether text (as opposed to commands) will be read from stdin. /// @see EDIT_STDIN -static bool edit_stdin(mparm_T *parmp) +static bool edit_stdin(bool explicit, mparm_T *parmp) { - return !headless_mode + bool implicit = !headless_mode && !embedded_mode && exmode_active != EXMODE_NORMAL // -E/-Es but not -e/-es. && !parmp->input_isatty && scriptin[0] == NULL; // `-s -` was not given. + return explicit || implicit; } /// Scan the command line arguments. @@ -737,7 +738,8 @@ static void command_line_scan(mparm_T *parmp) int argc = parmp->argc; char **argv = parmp->argv; int argv_idx; // index in argv[n][] - int had_minmin = false; // found "--" argument + bool had_stdin_file = false; // found explicit "-" argument + bool had_minmin = false; // found "--" argument int want_argument; // option argument with argument int c; char_u *p = NULL; @@ -769,9 +771,12 @@ static void command_line_scan(mparm_T *parmp) // "nvim -e -" silent mode silent_mode = true; } else { - if (parmp->edit_type != EDIT_NONE) { + if (parmp->edit_type != EDIT_NONE + && parmp->edit_type != EDIT_FILE + && parmp->edit_type != EDIT_STDIN) { mainerr(err_too_many_args, argv[0]); } + had_stdin_file = true; parmp->edit_type = EDIT_STDIN; } argv_idx = -1; // skip to next argument @@ -1181,7 +1186,9 @@ scripterror: argv_idx = -1; // skip to next argument // Check for only one type of editing. - if (parmp->edit_type != EDIT_NONE && parmp->edit_type != EDIT_FILE) { + if (parmp->edit_type != EDIT_NONE + && parmp->edit_type != EDIT_FILE + && parmp->edit_type != EDIT_STDIN) { mainerr(err_too_many_args, argv[0]); } parmp->edit_type = EDIT_FILE; @@ -1203,7 +1210,7 @@ scripterror: path_fix_case(p); #endif - int alist_fnum_flag = edit_stdin(parmp) + int alist_fnum_flag = edit_stdin(had_stdin_file, parmp) ? 1 // add buffer nr after exp. : 2; // add buffer number now and use curbuf #if !defined(UNIX) @@ -1230,8 +1237,8 @@ scripterror: xfree(swcmd); } - // Handle "foo | nvim". #6299 - if (edit_stdin(parmp)) { + // Handle "foo | nvim". EDIT_FILE may be overwritten now. #6299 + if (edit_stdin(had_stdin_file, parmp)) { parmp->edit_type = EDIT_STDIN; } diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index a2d1a7bace..c999396a6a 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -109,7 +109,7 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt) } else { if ((result = inbuf_poll((int)p_ut)) == kInputNone) { if (read_stream.closed && silent_mode) { - // Input drained and eventloop drained: exit silent/batch-mode (-es). + // Drained input and eventloop: exit silent/batch-mode (-es/-Es). read_error_exit(); } 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 |