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.
|
/// Decides whether text (as opposed to commands) will be read from stdin.
|
||||||
/// @see EDIT_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
|
&& !embedded_mode
|
||||||
&& exmode_active != EXMODE_NORMAL // -E/-Es but not -e/-es.
|
&& exmode_active != EXMODE_NORMAL // -E/-Es but not -e/-es.
|
||||||
&& !parmp->input_isatty
|
&& !parmp->input_isatty
|
||||||
&& scriptin[0] == NULL; // `-s -` was not given.
|
&& scriptin[0] == NULL; // `-s -` was not given.
|
||||||
|
return explicit || implicit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Scan the command line arguments.
|
/// Scan the command line arguments.
|
||||||
@@ -737,7 +738,8 @@ static void command_line_scan(mparm_T *parmp)
|
|||||||
int argc = parmp->argc;
|
int argc = parmp->argc;
|
||||||
char **argv = parmp->argv;
|
char **argv = parmp->argv;
|
||||||
int argv_idx; // index in argv[n][]
|
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 want_argument; // option argument with argument
|
||||||
int c;
|
int c;
|
||||||
char_u *p = NULL;
|
char_u *p = NULL;
|
||||||
@@ -769,9 +771,12 @@ static void command_line_scan(mparm_T *parmp)
|
|||||||
// "nvim -e -" silent mode
|
// "nvim -e -" silent mode
|
||||||
silent_mode = true;
|
silent_mode = true;
|
||||||
} else {
|
} 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]);
|
mainerr(err_too_many_args, argv[0]);
|
||||||
}
|
}
|
||||||
|
had_stdin_file = true;
|
||||||
parmp->edit_type = EDIT_STDIN;
|
parmp->edit_type = EDIT_STDIN;
|
||||||
}
|
}
|
||||||
argv_idx = -1; // skip to next argument
|
argv_idx = -1; // skip to next argument
|
||||||
@@ -1181,7 +1186,9 @@ scripterror:
|
|||||||
argv_idx = -1; // skip to next argument
|
argv_idx = -1; // skip to next argument
|
||||||
|
|
||||||
// Check for only one type of editing.
|
// 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]);
|
mainerr(err_too_many_args, argv[0]);
|
||||||
}
|
}
|
||||||
parmp->edit_type = EDIT_FILE;
|
parmp->edit_type = EDIT_FILE;
|
||||||
@@ -1203,7 +1210,7 @@ scripterror:
|
|||||||
path_fix_case(p);
|
path_fix_case(p);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int alist_fnum_flag = edit_stdin(parmp)
|
int alist_fnum_flag = edit_stdin(had_stdin_file, parmp)
|
||||||
? 1 // add buffer nr after exp.
|
? 1 // add buffer nr after exp.
|
||||||
: 2; // add buffer number now and use curbuf
|
: 2; // add buffer number now and use curbuf
|
||||||
#if !defined(UNIX)
|
#if !defined(UNIX)
|
||||||
@@ -1230,8 +1237,8 @@ scripterror:
|
|||||||
xfree(swcmd);
|
xfree(swcmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle "foo | nvim". #6299
|
// Handle "foo | nvim". EDIT_FILE may be overwritten now. #6299
|
||||||
if (edit_stdin(parmp)) {
|
if (edit_stdin(had_stdin_file, parmp)) {
|
||||||
parmp->edit_type = EDIT_STDIN;
|
parmp->edit_type = EDIT_STDIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -109,7 +109,7 @@ int os_inchar(uint8_t *buf, int maxlen, int ms, int tb_change_cnt)
|
|||||||
} else {
|
} else {
|
||||||
if ((result = inbuf_poll((int)p_ut)) == kInputNone) {
|
if ((result = inbuf_poll((int)p_ut)) == kInputNone) {
|
||||||
if (read_stream.closed && silent_mode) {
|
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();
|
read_error_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -109,25 +109,16 @@ describe('startup', function()
|
|||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
it('input from pipe (implicit) + file args #7679', function()
|
it('input from pipe (implicit) + file args #7679', function()
|
||||||
if helpers.pending_win32(pending) then return end
|
eq('ohyeah\r\n0 0 bufs=3',
|
||||||
local screen = Screen.new(25, 3)
|
funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '--headless',
|
||||||
screen:attach()
|
'+.print',
|
||||||
if iswin() then
|
"+echo has('ttyin') has('ttyout') 'bufs='.bufnr('$')",
|
||||||
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
'+qall!',
|
||||||
end
|
'-',
|
||||||
command([[exe "terminal echo ohyeah | "]] -- Input from a pipe.
|
'test/functional/fixtures/tty-test.c',
|
||||||
..[[.shellescape(v:progpath)." -n -u NONE -i NONE --cmd \"]]
|
'test/functional/fixtures/shell-test.c',
|
||||||
..nvim_set..[[\"]]
|
},
|
||||||
..[[ --cmd \"set shortmess+=I\"]]
|
{ 'ohyeah', '' }))
|
||||||
..[[ -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)
|
||||||
|
|
||||||
it('stdin with -es, -Es #7679', function()
|
it('stdin with -es, -Es #7679', function()
|
||||||
@@ -137,15 +128,12 @@ describe('startup', function()
|
|||||||
--
|
--
|
||||||
-- -Es: read stdin as text
|
-- -Es: read stdin as text
|
||||||
--
|
--
|
||||||
if not iswin() then
|
|
||||||
eq('partylikeits1999\n',
|
eq('partylikeits1999\n',
|
||||||
funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '-Es', '+.print', 'test/functional/fixtures/tty-test.c' },
|
funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '-Es', '+.print', 'test/functional/fixtures/tty-test.c' },
|
||||||
{ 'partylikeits1999' }))
|
{ 'partylikeits1999', '' }))
|
||||||
eq(inputstr,
|
eq(inputstr,
|
||||||
funcs.system({nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' },
|
funcs.system({nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' },
|
||||||
input))
|
input))
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- -es: read stdin as ex-commands
|
-- -es: read stdin as ex-commands
|
||||||
|
Reference in New Issue
Block a user