From 837ea6da9f65ac4ec85421c6e4af15194cc222d0 Mon Sep 17 00:00:00 2001 From: Kevin Sicong Jiang Date: Sun, 19 Jun 2022 20:22:39 +0500 Subject: fix(tui): piping nodejs to nvim breaks input handling #18932 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Piping NodeJS output into Neovim makes the editor unusable. This happens because NodeJS changes the tty state on exit after Nvim calls uv_tty_set_mode(). (May not always happen due to race condition.) This should have been fixed by 4ba5b4a86461 #13084. But some commands and functions (:sleep, system(), …) call ui_flush() internally, in particular the first tui_mode_change() is called before the end of startup. Steps to reproduce: 1. node -e "setTimeout(()=>{console.log('test')}, 1000)" | nvim -u NORC +"sleep 500m" - 2. The cursor key letters just overwrite the editor screen, and CTRL+C exits. Solution: Skip pending_mode_update during startup. Note: Delaying ui_flush() entirely could be a more general solution (emit a new UI event on VimEnter?). But "remote/coprocess TUI" #18375 could make all of this moot anyway. Fixes #18470 --- src/nvim/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index bdcb7af7e9..3e715793e6 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -514,7 +514,7 @@ void ui_flush(void) api_free_array(style); pending_mode_info_update = false; } - if (pending_mode_update) { + if (pending_mode_update && !starting) { char *full_name = shape_table[ui_mode_idx].full_name; ui_call_mode_change(cstr_as_string(full_name), ui_mode_idx); pending_mode_update = false; -- cgit