diff options
author | bfredl <bjorn.linse@gmail.com> | 2023-01-10 14:03:15 +0100 |
---|---|---|
committer | bfredl <bjorn.linse@gmail.com> | 2023-01-16 11:26:49 +0100 |
commit | 160c69b655ce2e47fbedcc87fcb4949c2bc04dce (patch) | |
tree | cdbce0fdd0318b8103d1d0278d517072f5bd4d4b /src/nvim/tui | |
parent | 43feb973e30ed40b8eb7bc97b0f41eef0b51194b (diff) | |
download | rneovim-160c69b655ce2e47fbedcc87fcb4949c2bc04dce.tar.gz rneovim-160c69b655ce2e47fbedcc87fcb4949c2bc04dce.tar.bz2 rneovim-160c69b655ce2e47fbedcc87fcb4949c2bc04dce.zip |
fix(ui): re-organize tty fd handling and fix issues
- Use the correct fd to replace stdin on windows (CONIN)
- Don't start the TUI if there are no tty fd (not a regression,
but makes sense regardless)
- De-mythologize "global input fd". it is just STDIN.
Diffstat (limited to 'src/nvim/tui')
-rw-r--r-- | src/nvim/tui/input.c | 16 | ||||
-rw-r--r-- | src/nvim/tui/tui.c | 11 |
2 files changed, 8 insertions, 19 deletions
diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index b837a380d5..91fbdf7886 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -153,19 +153,7 @@ void tinput_init(TermInput *input, Loop *loop) kitty_key_map_entry[i].name); } - // If stdin is not a pty, switch to stderr. For cases like: - // echo q | nvim -es - // ls *.md | xargs nvim -#ifdef MSWIN - if (!os_isatty(input->in_fd)) { - input->in_fd = os_get_conin_fd(); - } -#else - if (!os_isatty(input->in_fd) && os_isatty(STDERR_FILENO)) { - input->in_fd = STDERR_FILENO; - } -#endif - input_global_fd_init(input->in_fd); + input->in_fd = STDIN_FILENO; const char *term = os_getenv("TERM"); if (!term) { @@ -174,7 +162,7 @@ void tinput_init(TermInput *input, Loop *loop) input->tk = termkey_new_abstract(term, TERMKEY_FLAG_UTF8 | TERMKEY_FLAG_NOSTART); - termkey_hook_terminfo_getstr(input->tk, input->tk_ti_hook_fn, NULL); + termkey_hook_terminfo_getstr(input->tk, input->tk_ti_hook_fn, input); termkey_start(input->tk); int curflags = termkey_get_canonflags(input->tk); diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 44f6718039..e46dc892ea 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -1342,7 +1342,7 @@ static void suspend_event(void **argv) TUIData *tui = argv[0]; bool enable_mouse = tui->mouse_enabled; tui_terminal_stop(tui); - stream_set_blocking(input_global_fd(), true); // normalize stream (#2598) + stream_set_blocking(tui->input.in_fd, true); // normalize stream (#2598) kill(0, SIGTSTP); @@ -1351,7 +1351,7 @@ static void suspend_event(void **argv) if (enable_mouse) { tui_mouse_on(tui); } - stream_set_blocking(input_global_fd(), false); // libuv expects this + stream_set_blocking(tui->input.in_fd, false); // libuv expects this } #endif @@ -2238,12 +2238,12 @@ static void flush_buf(TUIData *tui) /// /// @see tmux/tty-keys.c fe4e9470bb504357d073320f5d305b22663ee3fd /// @see https://bugzilla.redhat.com/show_bug.cgi?id=142659 -static const char *tui_get_stty_erase(void) +static const char *tui_get_stty_erase(int fd) { static char stty_erase[2] = { 0 }; #if defined(HAVE_TERMIOS_H) struct termios t; - if (tcgetattr(input_global_fd(), &t) != -1) { + if (tcgetattr(fd, &t) != -1) { stty_erase[0] = (char)t.c_cc[VERASE]; stty_erase[1] = '\0'; DLOG("stty/termios:erase=%s", stty_erase); @@ -2256,9 +2256,10 @@ static const char *tui_get_stty_erase(void) /// @see TermInput.tk_ti_hook_fn static const char *tui_tk_ti_getstr(const char *name, const char *value, void *data) { + TermInput *input = data; static const char *stty_erase = NULL; if (stty_erase == NULL) { - stty_erase = tui_get_stty_erase(); + stty_erase = tui_get_stty_erase(input->in_fd); } if (strequal(name, "key_backspace")) { |