TUI: set os/input.c:global_fd to input->in_fd #10174

Problem: When we changed startup to wait for the TUI (like a remote UI),
         we forgot to set os/input.c:global_fd.  That used to be done by
         input_start().

Solution: Initialize os/input.c:global_fd before initializing libtermkey
          (termkey_new_abstract) so that tui_get_stty_erase() and
          friends can inspect the correct fd.

fixes #10134
close #10174
This commit is contained in:
erw7 2019-06-10 11:22:07 +09:00 committed by Justin M. Keyes
parent 04e2ba85b1
commit ce90a19abd
3 changed files with 44 additions and 23 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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()