diff options
author | erw7 <erw7.github@gmail.com> | 2019-04-10 20:59:39 +0900 |
---|---|---|
committer | erw7 <erw7.github@gmail.com> | 2019-06-04 08:47:51 +0900 |
commit | 5fced444bb1af5dec3284f2f3e0f8f10a9852a4a (patch) | |
tree | c71d7d265310e99912bc71b87e90c1585a947df5 | |
parent | fcf6bfd3601acc28ae3d116670928f82db949b30 (diff) | |
download | rneovim-5fced444bb1af5dec3284f2f3e0f8f10a9852a4a.tar.gz rneovim-5fced444bb1af5dec3284f2f3e0f8f10a9852a4a.tar.bz2 rneovim-5fced444bb1af5dec3284f2f3e0f8f10a9852a4a.zip |
tui/input.c: Fix problem when stdin is not TTY
-rw-r--r-- | src/nvim/tui/input.c | 40 |
1 files changed, 15 insertions, 25 deletions
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); -} |