aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/main.c')
-rw-r--r--src/nvim/main.c47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/nvim/main.c b/src/nvim/main.c
index a4f430e811..2f1e6e6d3b 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -268,6 +268,23 @@ int main(int argc, char **argv)
/* Set the break level after the terminal is initialized. */
debug_break_level = params.use_debug_break_level;
+ bool reading_input = !params.headless && (params.input_isatty
+ || params.output_isatty || params.err_isatty);
+
+ if (reading_input) {
+ // Its possible that one of the startup commands(arguments, sourced scripts
+ // or plugins) will prompt the user, so start reading from a tty stream
+ // now.
+ int fd = fileno(stdin);
+ if (!params.input_isatty || params.edit_type == EDIT_STDIN) {
+ // use stderr or stdout since stdin is not a tty and/or could be used to
+ // read the file we'll edit when the "-" argument is given(eg: cat file |
+ // nvim -)
+ fd = params.err_isatty ? fileno(stderr) : fileno(stdout);
+ }
+ input_start_stdin(fd);
+ }
+
/* Execute --cmd arguments. */
exe_pre_commands(&params);
@@ -351,19 +368,19 @@ int main(int argc, char **argv)
if (params.edit_type == EDIT_STDIN && !recoverymode)
read_stdin();
- if (!params.headless && (params.output_isatty || params.err_isatty)) {
- if (params.input_isatty && (need_wait_return || msg_didany)) {
- // Since at this point there's no UI instance running yet, error messages
- // would have been printed to stdout. Before starting (which can result
- // in a alternate screen buffer being shown) we need confirmation that
- // the user has seen the messages and that is done with a call to
- // wait_return. For that to work, stdin must be openend temporarily.
- input_start_stdin();
- wait_return(TRUE);
- TIME_MSG("waiting for return");
- input_stop_stdin();
- }
+ if (reading_input && (need_wait_return || msg_didany)) {
+ // Since at this point there's no UI instance running yet, error messages
+ // would have been printed to stdout. Before starting (which can result in
+ // a alternate screen buffer being shown) 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);
+ }
+
+ if (!params.headless) {
+ // Stop reading from stdin, the UI layer will take over now
+ input_stop_stdin();
ui_builtin_start();
}
@@ -641,7 +658,6 @@ main_loop (
curwin->w_valid &= ~VALID_CROW;
}
setcursor();
- ui_cursor_on();
do_redraw = FALSE;
@@ -1456,11 +1472,6 @@ static void check_tty(mparm_T *parmp)
TIME_MSG("Warning delay");
}
-
- if (parmp->edit_type != EDIT_STDIN && !parmp->input_isatty) {
- // read commands from directly from stdin
- input_start_stdin();
- }
}
/*