diff options
| -rw-r--r-- | src/nvim/os/input.c | 7 | ||||
| -rw-r--r-- | src/nvim/tui/input.c | 35 | ||||
| -rw-r--r-- | test/functional/terminal/tui_spec.lua | 25 | 
3 files changed, 44 insertions, 23 deletions
| diff --git a/src/nvim/os/input.c b/src/nvim/os/input.c index 8070f4c420..5d43dff5c1 100644 --- a/src/nvim/os/input.c +++ b/src/nvim/os/input.c @@ -50,6 +50,11 @@ void input_init(void)    input_buffer = rbuffer_new(INPUT_BUFFER_SIZE + MAX_KEY_CODE_LEN);  } +void input_global_fd_init(int fd) +{ +  global_fd = fd; +} +  /// Global TTY (or pipe for "-es") input stream, before UI starts.  int input_global_fd(void)  { @@ -62,7 +67,7 @@ void input_start(int fd)      return;    } -  global_fd = fd; +  input_global_fd_init(fd);    rstream_init_fd(&main_loop, &read_stream, fd, READ_BUFFER_SIZE);    rstream_start(&read_stream, input_read_cb, NULL);  } diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 7a725df0a1..b7072768ec 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -32,23 +32,6 @@ void tinput_init(TermInput *input, Loop *loop)    uv_mutex_init(&input->key_buffer_mutex);    uv_cond_init(&input->key_buffer_cond); -  const char *term = os_getenv("TERM"); -  if (!term) { -    term = "";  // termkey_new_abstract assumes non-null (#2745) -  } - -#if TERMKEY_VERSION_MAJOR > 0 || TERMKEY_VERSION_MINOR > 18 -  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_start(input->tk); -#else -  input->tk = termkey_new_abstract(term, TERMKEY_FLAG_UTF8); -#endif - -  int curflags = termkey_get_canonflags(input->tk); -  termkey_set_canonflags(input->tk, curflags | TERMKEY_CANON_DELBS); -    // If stdin is not a pty, switch to stderr. For cases like:    //    echo q | nvim -es    //    ls *.md | xargs nvim @@ -67,6 +50,24 @@ void tinput_init(TermInput *input, Loop *loop)      input->in_fd = 2;    }  #endif +  input_global_fd_init(input->in_fd); + +  const char *term = os_getenv("TERM"); +  if (!term) { +    term = "";  // termkey_new_abstract assumes non-null (#2745) +  } + +#if TERMKEY_VERSION_MAJOR > 0 || TERMKEY_VERSION_MINOR > 18 +  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_start(input->tk); +#else +  input->tk = termkey_new_abstract(term, TERMKEY_FLAG_UTF8); +#endif + +  int curflags = termkey_get_canonflags(input->tk); +  termkey_set_canonflags(input->tk, curflags | TERMKEY_CANON_DELBS);    // setup input handle    rstream_init_fd(loop, &input->read_stream, input->in_fd, 0xfff); diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index 56d6f68b7a..defa700f3b 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -268,14 +268,13 @@ describe('TUI', function()    end)  end) -describe('TUI with non-tty file descriptors', function() -  before_each(helpers.clear) - +describe('TUI', function() +  before_each(clear)    after_each(function() -    os.remove('testF') -- ensure test file is removed +    os.remove('testF')    end) -  it('can handle pipes as stdout and stderr', function() +  it('with non-tty (pipe) stdout/stderr', function()      local screen = thelpers.screen_setup(0, '"'..nvim_prog        ..' -u NONE -i NONE --cmd \'set noswapfile noshowcmd noruler\' --cmd \'normal iabc\' > /dev/null 2>&1 && cat testF && rm testF"')      feed_data(':w testF\n:q\n') @@ -289,6 +288,22 @@ describe('TUI with non-tty file descriptors', function()        {3:-- TERMINAL --}                                    |      ]])    end) + +  it('<C-h> #10134', function() +    local screen = thelpers.screen_setup(0, '["'..nvim_prog +      ..[[", "-u", "NONE", "-i", "NONE", "--cmd", "set noruler", "--cmd", ':nnoremap <C-h> :echomsg "\<C-h\>"<CR>']]..']') + +    command([[call chansend(b:terminal_job_id, "\<C-h>")]]) +    screen:expect([[ +      {1: }                                                 | +      {4:~                                                 }| +      {4:~                                                 }| +      {4:~                                                 }| +      {5:[No Name]                                         }| +      <C-h>                                             | +      {3:-- TERMINAL --}                                    | +    ]]) +  end)  end)  describe('TUI FocusGained/FocusLost', function() | 
