diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2019-06-04 09:14:45 +0200 |
|---|---|---|
| committer | Justin M. Keyes <justinkz@gmail.com> | 2019-06-04 09:14:45 +0200 |
| commit | 58f505dc7432cad76269ee447029eb1ad94b5aeb (patch) | |
| tree | 2f4e2176d828c8caeacef2b3bb5db187564a8bf5 /src/nvim/tui | |
| parent | 16b1e8f9c070ad853c6c63b43591e297bf512662 (diff) | |
| parent | 4719fdb3a44677cc1127624478f67a5316452aa0 (diff) | |
| download | rneovim-58f505dc7432cad76269ee447029eb1ad94b5aeb.tar.gz rneovim-58f505dc7432cad76269ee447029eb1ad94b5aeb.tar.bz2 rneovim-58f505dc7432cad76269ee447029eb1ad94b5aeb.zip | |
Merge #9829 'startup: remove TUI init special-case'
fixes #7967
fixes #9959
Historically Vim/Nvim does backflips to handle input and show messages
before a UI is available. This logical contradiction was already fixed
for remote UIs (#9024 c236e80cf3df). Fixing it also for the TUI avoids
problems on Windows, simplifies the logic, and avoids races like #9959.
- Move ui_builtin_start() to the same position as embedded_mode
remote_ui_wait_for_attach().
- If stdin is redirected, save the original `stdin` and replace fd
0 with tty before calling `ui_builtin_start()`.
Diffstat (limited to 'src/nvim/tui')
| -rw-r--r-- | src/nvim/tui/input.c | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 6d9023bd79..7a725df0a1 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -48,6 +48,26 @@ void tinput_init(TermInput *input, Loop *loop) int curflags = termkey_get_canonflags(input->tk); termkey_set_canonflags(input->tk, curflags | TERMKEY_CANON_DELBS); + + // If stdin is not a pty, switch to stderr. For cases like: + // echo q | nvim -es + // ls *.md | xargs nvim +#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 +455,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 +499,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); -} |