diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | contrib/local.mk.example | 4 | ||||
-rw-r--r-- | src/nvim/main.c | 4 | ||||
-rw-r--r-- | src/nvim/os/input.c | 8 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 22 | ||||
-rw-r--r-- | test/functional/terminal/tui_spec.lua | 24 |
6 files changed, 54 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 53e387307c..3db32f1966 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -260,7 +260,7 @@ if((CLANG_ASAN_UBSAN OR CLANG_MSAN OR CLANG_TSAN) AND NOT CMAKE_C_COMPILER_ID MA message(FATAL_ERROR "Sanitizers are only supported for Clang.") endif() -option(ENABLE_JEMALLOC "enable jemalloc" OFF) +option(ENABLE_JEMALLOC "enable jemalloc" ON) if (ENABLE_JEMALLOC) if(CLANG_ASAN_UBSAN OR CLANG_MSAN OR CLANG_TSAN) diff --git a/contrib/local.mk.example b/contrib/local.mk.example index 1c3ea4ab40..4e7b01a39f 100644 --- a/contrib/local.mk.example +++ b/contrib/local.mk.example @@ -7,6 +7,10 @@ # These CFLAGS can be used in addition to those specified in CMakeLists.txt: # CMAKE_EXTRA_FLAGS="-DCMAKE_C_FLAGS=-ftrapv -Wlogical-op" +# By default, the jemalloc family of memory allocation functions are used. +# Uncomment the following to instead use libc memory allocation functions. +# CMAKE_EXTRA_FLAGS += -DENABLE_JEMALLOC=OFF + # Sets the build type; defaults to Debug. Valid values: # # - Debug: Disables optimizations (-O0), enables debug information. diff --git a/src/nvim/main.c b/src/nvim/main.c index eb2a1567e7..43723ff363 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -1601,10 +1601,12 @@ static bool do_user_initialization(void) { bool do_exrc = p_exrc; if (process_env("VIMINIT", true) == OK) { + do_exrc = p_exrc; return do_exrc; } char_u *user_vimrc = (char_u *)stdpaths_user_conf_subpath("init.vim"); if (do_source(user_vimrc, true, DOSO_VIMRC) != FAIL) { + do_exrc = p_exrc; if (do_exrc) { do_exrc = (path_full_compare((char_u *)VIMRC_FILE, user_vimrc, false) != kEqualFiles); @@ -1630,6 +1632,7 @@ static bool do_user_initialization(void) vimrc[dir_len] = PATHSEP; memmove(vimrc + dir_len + 1, path_tail, sizeof(path_tail)); if (do_source((char_u *) vimrc, true, DOSO_VIMRC) != FAIL) { + do_exrc = p_exrc; if (do_exrc) { do_exrc = (path_full_compare((char_u *)VIMRC_FILE, (char_u *)vimrc, false) != kEqualFiles); @@ -1643,6 +1646,7 @@ static bool do_user_initialization(void) xfree(config_dirs); } if (process_env("EXINIT", false) == OK) { + do_exrc = p_exrc; return do_exrc; } return do_exrc; diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index df803609ae..ef6b5ff6f5 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -82,9 +82,11 @@ static void cursorhold_event(void **argv) static void create_cursorhold_event(void) { - // If the queue had any items, this function should not have been - // called(inbuf_poll would return kInputAvail) - assert(queue_empty(loop.events)); + // If events are enabled and the queue has any items, this function should not + // have been called(inbuf_poll would return kInputAvail) + // TODO(tarruda): Cursorhold should be implemented as a timer set during the + // `state_check` callback for the states where it can be triggered. + assert(!events_enabled || queue_empty(loop.events)); queue_put(loop.events, cursorhold_event, 0); } diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index c87f6d331b..c5f2950e62 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 @@ -116,8 +120,8 @@ static void terminfo_start(UI *ui) data->unibi_ext.enter_insert_mode = -1; data->unibi_ext.enter_replace_mode = -1; 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_fd = 1; + data->out_isatty = os_isatty(data->out_fd); // setup unibilium data->ut = unibi_from_env(); if (!data->ut) { @@ -132,8 +136,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 +686,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) |