diff options
author | erw7 <erw7.github@gmail.com> | 2019-11-09 15:46:12 +0900 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2020-01-17 11:36:28 +0100 |
commit | 5355cee77d7b3b62917036281406726832b6d7dc (patch) | |
tree | 17ce6d9f2a96613d2c6d12ec86475f40bf05b6f8 /src/nvim/channel.c | |
parent | 8fe0635e7338e32e8aedeb8f2e2c0f246876375c (diff) | |
download | rneovim-5355cee77d7b3b62917036281406726832b6d7dc.tar.gz rneovim-5355cee77d7b3b62917036281406726832b6d7dc.tar.bz2 rneovim-5355cee77d7b3b62917036281406726832b6d7dc.zip |
Change to use ConPTY, if available
Diffstat (limited to 'src/nvim/channel.c')
-rw-r--r-- | src/nvim/channel.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/nvim/channel.c b/src/nvim/channel.c index 2bb568f025..b9ea36d397 100644 --- a/src/nvim/channel.c +++ b/src/nvim/channel.c @@ -11,6 +11,9 @@ #include "nvim/msgpack_rpc/channel.h" #include "nvim/msgpack_rpc/server.h" #include "nvim/os/shell.h" +#ifdef WIN32 +# include "nvim/os/os_win_conpty.h" +#endif #include "nvim/path.h" #include "nvim/ascii.h" @@ -469,8 +472,34 @@ uint64_t channel_from_stdio(bool rpc, CallbackReader on_output, Channel *channel = channel_alloc(kChannelStreamStdio); - rstream_init_fd(&main_loop, &channel->stream.stdio.in, 0, 0); - wstream_init_fd(&main_loop, &channel->stream.stdio.out, 1, 0); + int stdin_dup_fd = STDIN_FILENO; + int stdout_dup_fd = STDOUT_FILENO; +#ifdef WIN32 + // Strangely, ConPTY doesn't work if stdin and stdout are pipes. So replace + // stdin and stdout with CONIN$ and CONOUT$, respectively. + if (embedded_mode && os_has_conpty_working()) { + stdin_dup_fd = os_dup(STDIN_FILENO); + close(STDIN_FILENO); + const HANDLE conin_handle = + CreateFile("CONIN$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, 0, (HANDLE)NULL); + assert(conin_handle != INVALID_HANDLE_VALUE); + const int conin_fd = _open_osfhandle((intptr_t)conin_handle, _O_RDONLY); + assert(conin_fd == STDIN_FILENO); + stdout_dup_fd = os_dup(STDOUT_FILENO); + close(STDOUT_FILENO); + const HANDLE conout_handle = + CreateFile("CONOUT$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL, + OPEN_EXISTING, 0, (HANDLE)NULL); + assert(conout_handle != INVALID_HANDLE_VALUE); + const int conout_fd = _open_osfhandle((intptr_t)conout_handle, 0); + assert(conout_fd == STDOUT_FILENO); + } +#endif + rstream_init_fd(&main_loop, &channel->stream.stdio.in, stdin_dup_fd, 0); + wstream_init_fd(&main_loop, &channel->stream.stdio.out, stdout_dup_fd, 0); if (rpc) { rpc_start(channel); |