mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 00:08:19 +00:00
startup: allow explicit "-" file arg with --headless
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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();
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user