From fcf6bfd3601acc28ae3d116670928f82db949b30 Mon Sep 17 00:00:00 2001 From: erw7 Date: Tue, 2 Apr 2019 04:08:09 +0900 Subject: main.c: fixes #7967 --- src/nvim/main.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/nvim/main.c b/src/nvim/main.c index ed8788af60..ef424e08a8 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -378,6 +378,14 @@ int main(int argc, char **argv) TIME_MSG("initialized screen early for embedder"); } + if (!headless_mode && !embedded_mode && !silent_mode) { + input_stop(); // Stop reading input, let the UI take over. + ui_builtin_start(); + starting = NO_BUFFERS; + screenclear(); + early_ui = true; + } + // Execute --cmd arguments. exe_pre_commands(¶ms); @@ -477,11 +485,6 @@ int main(int argc, char **argv) wait_return(true); } - if (!headless_mode && !embedded_mode && !silent_mode) { - input_stop(); // Stop reading input, let the UI take over. - ui_builtin_start(); - } - setmouse(); // may start using the mouse if (exmode_active || early_ui) { -- cgit From 5fced444bb1af5dec3284f2f3e0f8f10a9852a4a Mon Sep 17 00:00:00 2001 From: erw7 Date: Wed, 10 Apr 2019 20:59:39 +0900 Subject: tui/input.c: Fix problem when stdin is not TTY --- src/nvim/tui/input.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 6d9023bd79..a09f4e0f93 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -48,6 +48,20 @@ void tinput_init(TermInput *input, Loop *loop) int curflags = termkey_get_canonflags(input->tk); termkey_set_canonflags(input->tk, curflags | TERMKEY_CANON_DELBS); +#ifdef WIN32 + if (!os_isatty(0)) { + const HANDLE conin_handle = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, + (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, 0, (HANDLE)NULL); + input->in_fd = _open_osfhandle(conin_handle, _O_RDONLY); + assert(input->in_fd != -1); + } +#else + if (!os_isatty(0) && os_isatty(2)) { + input->in_fd = 2; + } +#endif // setup input handle rstream_init_fd(loop, &input->read_stream, input->in_fd, 0xfff); // initialize a timer handle for handling ESC with libtermkey @@ -435,24 +449,7 @@ static void tinput_read_cb(Stream *stream, RBuffer *buf, size_t count_, TermInput *input = data; if (eof) { - if (input->in_fd == 0 && !os_isatty(0) && os_isatty(2)) { - // Started reading from stdin which is not a pty but failed. Switch to - // stderr since it is a pty. - // - // This is how we support commands like: - // - // echo q | nvim -es - // - // and - // - // ls *.md | xargs nvim - input->in_fd = 2; - stream_close(&input->read_stream, NULL, NULL); - multiqueue_put(input->loop->fast_events, tinput_restart_reading, 1, - input); - } else { - loop_schedule(&main_loop, event_create(tinput_done_event, 0)); - } + loop_schedule(&main_loop, event_create(tinput_done_event, 0)); return; } @@ -496,10 +493,3 @@ static void tinput_read_cb(Stream *stream, RBuffer *buf, size_t count_, // without wrap around, otherwise it could be misinterpreted. rbuffer_reset(input->read_stream.buffer); } - -static void tinput_restart_reading(void **argv) -{ - TermInput *input = argv[0]; - rstream_init_fd(input->loop, &input->read_stream, input->in_fd, 0xfff); - rstream_start(&input->read_stream, tinput_read_cb, input); -} -- cgit From 402b4e8fbe32c2ee1de0c39ab84c43b600db0495 Mon Sep 17 00:00:00 2001 From: erw7 Date: Wed, 10 Apr 2019 21:02:21 +0900 Subject: main.c: Change TUI to initialize like GUI --- src/nvim/main.c | 48 +++++++++++++----------------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/nvim/main.c b/src/nvim/main.c index ef424e08a8..059b8762e5 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -317,26 +317,13 @@ int main(int argc, char **argv) debug_break_level = params.use_debug_break_level; // - // Read user-input if any TTY is connected. // Read ex-commands if invoked with "-es". // - bool reading_tty = !headless_mode - && !embedded_mode - && !silent_mode - && (params.input_isatty || params.output_isatty - || params.err_isatty); bool reading_excmds = !params.input_isatty && silent_mode && exmode_active == EXMODE_NORMAL; - if (reading_tty || reading_excmds) { - // One of the startup commands (arguments, sourced scripts or plugins) may - // prompt the user, so start reading from a tty now. + if (reading_excmds) { int fd = STDIN_FILENO; - if (!silent_mode - && (!params.input_isatty || params.edit_type == EDIT_STDIN)) { - // Use stderr or stdout since stdin is being used to read commands. - fd = params.err_isatty ? fileno(stderr) : fileno(stdout); - } input_start(fd); } @@ -366,24 +353,23 @@ int main(int argc, char **argv) // startup. This allows an external UI to show messages and prompts from // --cmd and buffer loading (e.g. swap files) bool early_ui = false; - if (embedded_mode && !headless_mode) { - TIME_MSG("waiting for embedder to make request"); - remote_ui_wait_for_attach(); - TIME_MSG("done waiting for embedder"); + bool use_remote_ui = (embedded_mode && !headless_mode); + bool use_builtin_ui = (!headless_mode && !embedded_mode && !silent_mode); + if (use_remote_ui || use_builtin_ui) { + TIME_MSG("waiting for user interface to make request"); + if (use_remote_ui) + { + remote_ui_wait_for_attach(); + } else { + ui_builtin_start(); + } + TIME_MSG("done waiting for user interface"); // prepare screen now, so external UIs can display messages starting = NO_BUFFERS; screenclear(); early_ui = true; - TIME_MSG("initialized screen early for embedder"); - } - - if (!headless_mode && !embedded_mode && !silent_mode) { - input_stop(); // Stop reading input, let the UI take over. - ui_builtin_start(); - starting = NO_BUFFERS; - screenclear(); - early_ui = true; + TIME_MSG("initialized screen early for user interface"); } // Execute --cmd arguments. @@ -477,14 +463,6 @@ int main(int argc, char **argv) read_stdin(); } - if (reading_tty && (need_wait_return || msg_didany)) { - // Because there's no UI yet, error messages would have been printed to - // stdout. Before starting we need confirmation that the user has seen the - // messages and that is done with a call to wait_return. - TIME_MSG("waiting for return"); - wait_return(true); - } - setmouse(); // may start using the mouse if (exmode_active || early_ui) { -- cgit From e4c85c362d1b25847dfa92a28197c5d4472a4c17 Mon Sep 17 00:00:00 2001 From: erw7 Date: Sat, 13 Apr 2019 03:39:47 +0900 Subject: [skip appveyor] Fix clint issue --- src/nvim/main.c | 3 +-- src/nvim/tui/input.c | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/nvim/main.c b/src/nvim/main.c index 059b8762e5..e7a6d42251 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -357,8 +357,7 @@ int main(int argc, char **argv) bool use_builtin_ui = (!headless_mode && !embedded_mode && !silent_mode); if (use_remote_ui || use_builtin_ui) { TIME_MSG("waiting for user interface to make request"); - if (use_remote_ui) - { + if (use_remote_ui) { remote_ui_wait_for_attach(); } else { ui_builtin_start(); diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index a09f4e0f93..f08f659d12 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -50,7 +50,8 @@ void tinput_init(TermInput *input, Loop *loop) termkey_set_canonflags(input->tk, curflags | TERMKEY_CANON_DELBS); #ifdef WIN32 if (!os_isatty(0)) { - const HANDLE conin_handle = CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, + const HANDLE conin_handle = CreateFile("CONIN$", + GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, 0, (HANDLE)NULL); -- cgit From 89c2747eed48d69fa75315e2db8c682f2b027471 Mon Sep 17 00:00:00 2001 From: erw7 Date: Sun, 14 Apr 2019 00:45:20 +0900 Subject: Fix issue where test fails --- src/nvim/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/main.c b/src/nvim/main.c index e7a6d42251..e3e7949e79 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -467,7 +467,7 @@ int main(int argc, char **argv) if (exmode_active || early_ui) { // Don't clear the screen when starting in Ex mode, or when an // embedding UI might have displayed messages - must_redraw = CLEAR; + must_redraw = VALID; } else { screenclear(); // clear screen TIME_MSG("clearing screen"); -- cgit From 4719fdb3a44677cc1127624478f67a5316452aa0 Mon Sep 17 00:00:00 2001 From: erw7 Date: Sun, 14 Apr 2019 21:06:53 +0900 Subject: main.c: Change to use redraw_later(VALID) --- src/nvim/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/main.c b/src/nvim/main.c index e3e7949e79..b19dc9ca09 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -467,7 +467,7 @@ int main(int argc, char **argv) if (exmode_active || early_ui) { // Don't clear the screen when starting in Ex mode, or when an // embedding UI might have displayed messages - must_redraw = VALID; + redraw_later(VALID); } else { screenclear(); // clear screen TIME_MSG("clearing screen"); -- cgit