diff options
author | Thiago de Arruda <tpadilha84@gmail.com> | 2015-10-29 07:46:39 -0300 |
---|---|---|
committer | Thiago de Arruda <tpadilha84@gmail.com> | 2015-10-29 08:13:45 -0300 |
commit | 7e8b431d3f67e5b167bc238899521715e1b324d8 (patch) | |
tree | 3e5bd9ec81abde9f993b6708fe63434590852a9e | |
parent | 7dae3ad24ddd4d36e6ebb6d873e285d06130da46 (diff) | |
download | rneovim-7e8b431d3f67e5b167bc238899521715e1b324d8.tar.gz rneovim-7e8b431d3f67e5b167bc238899521715e1b324d8.tar.bz2 rneovim-7e8b431d3f67e5b167bc238899521715e1b324d8.zip |
tui: Fix abort when stdout and stderr are not tty.
The abort came from using libuv tty handle on non-tty fd. Use uv_pipe_t in these
cases. Also add simple test for this case.
-rw-r--r-- | src/nvim/tui/tui.c | 19 | ||||
-rw-r--r-- | test/functional/terminal/tui_spec.lua | 24 |
2 files changed, 39 insertions, 4 deletions
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index c87f6d331b..18332409f5 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -43,7 +43,11 @@ typedef struct { TermInput input; uv_loop_t write_loop; unibi_term *ut; - uv_tty_t output_handle; + union { + uv_tty_t tty; + uv_pipe_t pipe; + } output_handle; + bool out_isatty; SignalWatcher winch_handle, cont_handle; bool cont_received; // Event scheduled by the ui bridge. Since the main thread suspends until @@ -118,6 +122,7 @@ static void terminfo_start(UI *ui) data->unibi_ext.exit_insert_mode = -1; // write output to stderr if stdout is not a tty data->out_fd = os_isatty(1) ? 1 : (os_isatty(2) ? 2 : 1); + data->out_isatty = os_isatty(data->out_fd); // setup unibilium data->ut = unibi_from_env(); if (!data->ut) { @@ -132,8 +137,13 @@ static void terminfo_start(UI *ui) // Enable bracketed paste unibi_out(ui, data->unibi_ext.enable_bracketed_paste); uv_loop_init(&data->write_loop); - uv_tty_init(&data->write_loop, &data->output_handle, data->out_fd, 0); - uv_tty_set_mode(&data->output_handle, UV_TTY_MODE_RAW); + if (data->out_isatty) { + uv_tty_init(&data->write_loop, &data->output_handle.tty, data->out_fd, 0); + uv_tty_set_mode(&data->output_handle.tty, UV_TTY_MODE_RAW); + } else { + uv_pipe_init(&data->write_loop, &data->output_handle.pipe, 0); + uv_pipe_open(&data->output_handle.pipe, data->out_fd); + } } static void terminfo_stop(UI *ui) @@ -677,7 +687,8 @@ static void update_size(UI *ui) } // 2 - try from a system call(ioctl/TIOCGWINSZ on unix) - if (!uv_tty_get_winsize(&data->output_handle, &width, &height)) { + if (data->out_isatty && + !uv_tty_get_winsize(&data->output_handle.tty, &width, &height)) { goto end; } diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index d38bedcd4a..0c4b80fdd2 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -149,3 +149,27 @@ describe('tui', function() ]]) end) end) + +describe('tui with non-tty file descriptors', function() + before_each(helpers.clear) + + after_each(function() + os.remove('testF') -- ensure test file is removed + end) + + it('can handle pipes as stdout and stderr', function() + local screen = thelpers.screen_setup(0, '"'..helpers.nvim_prog..' -u NONE -i NONE --cmd \'set noswapfile\' --cmd \'normal iabc\' > /dev/null 2>&1 && cat testF && rm testF"') + screen:set_default_attr_ids({}) + screen:set_default_attr_ignore(true) + feed(':w testF\n:q\n') + screen:expect([[ + :w testF | + :q | + abc | + | + [Program exited, press any key to close] | + | + -- TERMINAL -- | + ]]) + end) +end) |