mirror of
https://github.com/neovim/neovim.git
synced 2025-09-22 03:08:27 +00:00
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.
This commit is contained in:
@@ -580,10 +580,6 @@ EXTERN int sandbox INIT(= 0);
|
|||||||
/// Batch-mode: "-es" or "-Es" commandline argument was given.
|
/// Batch-mode: "-es" or "-Es" commandline argument was given.
|
||||||
EXTERN int silent_mode INIT(= false);
|
EXTERN int silent_mode INIT(= false);
|
||||||
|
|
||||||
/// Set to true when sourcing of startup scripts (init.vim) is done.
|
|
||||||
/// Used for options that cannot be changed after startup scripts.
|
|
||||||
EXTERN bool did_source_startup_scripts INIT(= false);
|
|
||||||
|
|
||||||
/// Start position of active Visual selection.
|
/// Start position of active Visual selection.
|
||||||
EXTERN pos_T VIsual;
|
EXTERN pos_T VIsual;
|
||||||
/// Whether Visual mode is active.
|
/// Whether Visual mode is active.
|
||||||
|
@@ -158,6 +158,7 @@ void event_init(void)
|
|||||||
bool event_teardown(void)
|
bool event_teardown(void)
|
||||||
{
|
{
|
||||||
if (!main_loop.events) {
|
if (!main_loop.events) {
|
||||||
|
input_stop();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,17 +299,18 @@ int main(int argc, char **argv)
|
|||||||
// Set the break level after the terminal is initialized.
|
// Set the break level after the terminal is initialized.
|
||||||
debug_break_level = params.use_debug_break_level;
|
debug_break_level = params.use_debug_break_level;
|
||||||
|
|
||||||
|
bool reading_excmds = exmode_active == EXMODE_NORMAL;
|
||||||
bool reading_input = !headless_mode
|
bool reading_input = !headless_mode
|
||||||
&& (params.input_isatty || params.output_isatty
|
&& (params.input_isatty || params.output_isatty
|
||||||
|| params.err_isatty);
|
|| params.err_isatty);
|
||||||
|
|
||||||
if (reading_input) {
|
if (reading_input || reading_excmds) {
|
||||||
// One of the startup commands (arguments, sourced scripts or plugins) may
|
// One of the startup commands (arguments, sourced scripts or plugins) may
|
||||||
// prompt the user, so start reading from a tty now.
|
// prompt the user, so start reading from a tty now.
|
||||||
int fd = fileno(stdin);
|
int fd = fileno(stdin);
|
||||||
if (!params.input_isatty || params.edit_type == EDIT_STDIN) {
|
if (!reading_excmds
|
||||||
// Use stderr or stdout since stdin is not a tty and/or could be used to
|
&& (!params.input_isatty || params.edit_type == EDIT_STDIN)) {
|
||||||
// read the "-" file (eg: cat file | nvim -)
|
// Use stderr or stdout since stdin is being used to read commands.
|
||||||
fd = params.err_isatty ? fileno(stderr) : fileno(stdout);
|
fd = params.err_isatty ? fileno(stderr) : fileno(stdout);
|
||||||
}
|
}
|
||||||
input_start(fd);
|
input_start(fd);
|
||||||
@@ -332,7 +334,9 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
// Reset 'loadplugins' for "-u NONE" before "--cmd" arguments.
|
// Reset 'loadplugins' for "-u NONE" before "--cmd" arguments.
|
||||||
// Allows for setting 'loadplugins' there.
|
// Allows for setting 'loadplugins' there.
|
||||||
if (params.use_vimrc != NULL && strequal(params.use_vimrc, "NONE")) {
|
if (params.use_vimrc != NULL && strequal(params.use_vimrc, "NONE")
|
||||||
|
// && !silent_mode // XXX: avoid hang with "nvim -es -u NONE".
|
||||||
|
) {
|
||||||
p_lpl = false;
|
p_lpl = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,17 +373,21 @@ int main(int argc, char **argv)
|
|||||||
mch_exit(0);
|
mch_exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a few option defaults after reading vimrc files:
|
// Set a few option defaults after reading vimrc files: 'title', 'icon',
|
||||||
// 'title' and 'icon', Unix: 'shellpipe' and 'shellredir'.
|
// 'shellpipe', 'shellredir'.
|
||||||
set_init_3();
|
set_init_3();
|
||||||
TIME_MSG("inits 3");
|
TIME_MSG("inits 3");
|
||||||
|
|
||||||
/*
|
// "-n" argument: Disable swap file by setting 'updatecount' to 0.
|
||||||
* "-n" argument: Disable swap file by setting 'updatecount' to 0.
|
// Note that this overrides anything from a vimrc file.
|
||||||
* Note that this overrides anything from a vimrc file.
|
if (params.no_swap_file) {
|
||||||
*/
|
|
||||||
if (params.no_swap_file)
|
|
||||||
p_uc = 0;
|
p_uc = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX: Minimize 'updatetime' for -es/-Es. #7679
|
||||||
|
if (silent_mode) {
|
||||||
|
p_ut = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (curwin->w_p_rl && p_altkeymap) {
|
if (curwin->w_p_rl && p_altkeymap) {
|
||||||
p_hkmap = FALSE; /* Reset the Hebrew keymap mode */
|
p_hkmap = FALSE; /* Reset the Hebrew keymap mode */
|
||||||
@@ -437,18 +445,17 @@ int main(int argc, char **argv)
|
|||||||
wait_return(true);
|
wait_return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!headless_mode) {
|
if (!headless_mode && !silent_mode) {
|
||||||
// Stop reading from input stream. UI (if any) will take over.
|
input_stop(); // Stop reading from input stream. UI will take over.
|
||||||
input_stop();
|
|
||||||
ui_builtin_start();
|
ui_builtin_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
setmouse(); // may start using the mouse
|
setmouse(); // may start using the mouse
|
||||||
ui_reset_scroll_region(); // In case Rows changed
|
ui_reset_scroll_region(); // In case Rows changed
|
||||||
|
|
||||||
if (exmode_active)
|
if (exmode_active) {
|
||||||
must_redraw = CLEAR; // Don't clear the screen when starting in Ex mode.
|
must_redraw = CLEAR; // Don't clear the screen when starting in Ex mode.
|
||||||
else {
|
} else {
|
||||||
screenclear(); // clear screen
|
screenclear(); // clear screen
|
||||||
TIME_MSG("clearing screen");
|
TIME_MSG("clearing screen");
|
||||||
}
|
}
|
||||||
@@ -1769,7 +1776,7 @@ static void source_startup_scripts(const mparm_T *const parmp)
|
|||||||
|| strequal(parmp->use_vimrc, "NORC")) {
|
|| strequal(parmp->use_vimrc, "NORC")) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
} else {
|
} else {
|
||||||
if (do_source((char_u *)parmp->use_vimrc, FALSE, DOSO_NONE) != OK) {
|
if (do_source((char_u *)parmp->use_vimrc, false, DOSO_NONE) != OK) {
|
||||||
EMSG2(_("E282: Cannot read from \"%s\""), parmp->use_vimrc);
|
EMSG2(_("E282: Cannot read from \"%s\""), parmp->use_vimrc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1810,7 +1817,6 @@ static void source_startup_scripts(const mparm_T *const parmp)
|
|||||||
}
|
}
|
||||||
secure = 0;
|
secure = 0;
|
||||||
}
|
}
|
||||||
did_source_startup_scripts = true;
|
|
||||||
TIME_MSG("sourcing vimrc file(s)");
|
TIME_MSG("sourcing vimrc file(s)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -64,7 +64,7 @@ void input_start(int fd)
|
|||||||
|
|
||||||
global_fd = fd;
|
global_fd = fd;
|
||||||
rstream_init_fd(&main_loop, &read_stream, fd, READ_BUFFER_SIZE);
|
rstream_init_fd(&main_loop, &read_stream, fd, READ_BUFFER_SIZE);
|
||||||
rstream_start(&read_stream, read_cb, NULL);
|
rstream_start(&read_stream, input_read_cb, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void input_stop(void)
|
void input_stop(void)
|
||||||
@@ -108,6 +108,11 @@ 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) {
|
||||||
|
// Input drained and eventloop drained: exit silent/batch-mode (-es).
|
||||||
|
read_error_exit();
|
||||||
|
}
|
||||||
|
|
||||||
if (trigger_cursorhold() && !typebuf_changed(tb_change_cnt)) {
|
if (trigger_cursorhold() && !typebuf_changed(tb_change_cnt)) {
|
||||||
create_cursorhold_event();
|
create_cursorhold_event();
|
||||||
} else {
|
} else {
|
||||||
@@ -376,11 +381,11 @@ static InbufPollResult inbuf_poll(int ms)
|
|||||||
return input_eof ? kInputEof : kInputNone;
|
return input_eof ? kInputEof : kInputNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void read_cb(Stream *stream, RBuffer *buf, size_t c, void *data,
|
static void input_read_cb(Stream *stream, RBuffer *buf, size_t c, void *data,
|
||||||
bool at_eof)
|
bool at_eof)
|
||||||
{
|
{
|
||||||
if (at_eof) {
|
if (at_eof) {
|
||||||
input_eof = true;
|
input_done();
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(rbuffer_space(input_buffer) >= rbuffer_size(buf));
|
assert(rbuffer_space(input_buffer) >= rbuffer_size(buf));
|
||||||
|
@@ -109,13 +109,14 @@ 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
|
||||||
local screen = Screen.new(25, 3)
|
local screen = Screen.new(25, 3)
|
||||||
screen:attach()
|
screen:attach()
|
||||||
if iswin() then
|
if iswin() then
|
||||||
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
||||||
end
|
end
|
||||||
command([[exe "terminal echo ohyeah | "]] -- Input from a pipe.
|
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..[[\"]]
|
..nvim_set..[[\"]]
|
||||||
..[[ --cmd \"set shortmess+=I\"]]
|
..[[ --cmd \"set shortmess+=I\"]]
|
||||||
..[[ -c \"echo has('ttyin') has('ttyout') 'bufs='.bufnr('$')\"]]
|
..[[ -c \"echo has('ttyin') has('ttyout') 'bufs='.bufnr('$')\"]]
|
||||||
@@ -128,5 +129,33 @@ describe('startup', function()
|
|||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
end)
|
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)
|
end)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user