mirror of
https://github.com/neovim/neovim.git
synced 2025-10-19 08:11:50 +00:00
tui: fix handling of bg response after suspend (#11145)
`tui_terminal_after_startup` gets called right after resuming from
suspending (via `Ctrl-z`) already (not delayed as with the startup
itself), and would set `waiting_for_bg_response` to false then directly.
This results in the terminal response not being processed then anymore,
and leaking into Neovim itself.
This changes it to try 5 times always, which means that it typically
would stop after a few characters of input from the user typically, e.g.
with tmux, which does not send a reply.
While it might be better to have something based on the time (e.g. only
wait for max 1s), this appears to be easier to do.
Fixes regression in 8a4ae3d
.
This commit is contained in:
@@ -27,7 +27,7 @@ void tinput_init(TermInput *input, Loop *loop)
|
|||||||
input->loop = loop;
|
input->loop = loop;
|
||||||
input->paste = 0;
|
input->paste = 0;
|
||||||
input->in_fd = 0;
|
input->in_fd = 0;
|
||||||
input->waiting_for_bg_response = false;
|
input->waiting_for_bg_response = 0;
|
||||||
input->key_buffer = rbuffer_new(KEY_BUFFER_SIZE);
|
input->key_buffer = rbuffer_new(KEY_BUFFER_SIZE);
|
||||||
uv_mutex_init(&input->key_buffer_mutex);
|
uv_mutex_init(&input->key_buffer_mutex);
|
||||||
uv_cond_init(&input->key_buffer_cond);
|
uv_cond_init(&input->key_buffer_cond);
|
||||||
@@ -444,7 +444,7 @@ static void set_bg_deferred(void **argv)
|
|||||||
// [1] https://en.wikipedia.org/wiki/Luma_%28video%29
|
// [1] https://en.wikipedia.org/wiki/Luma_%28video%29
|
||||||
static bool handle_background_color(TermInput *input)
|
static bool handle_background_color(TermInput *input)
|
||||||
{
|
{
|
||||||
if (!input->waiting_for_bg_response) {
|
if (input->waiting_for_bg_response <= 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
@@ -465,9 +465,13 @@ static bool handle_background_color(TermInput *input)
|
|||||||
header_size = 10;
|
header_size = 10;
|
||||||
num_components = 4;
|
num_components = 4;
|
||||||
} else {
|
} else {
|
||||||
|
input->waiting_for_bg_response--;
|
||||||
|
if (input->waiting_for_bg_response == 0) {
|
||||||
|
DLOG("did not get a response for terminal background query");
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
input->waiting_for_bg_response = false;
|
input->waiting_for_bg_response = 0;
|
||||||
rbuffer_consumed(input->read_stream.buffer, header_size);
|
rbuffer_consumed(input->read_stream.buffer, header_size);
|
||||||
RBUFFER_EACH(input->read_stream.buffer, c, i) {
|
RBUFFER_EACH(input->read_stream.buffer, c, i) {
|
||||||
count = i + 1;
|
count = i + 1;
|
||||||
|
@@ -12,7 +12,7 @@ typedef struct term_input {
|
|||||||
// Phases: -1=all 0=disabled 1=first-chunk 2=continue 3=last-chunk
|
// Phases: -1=all 0=disabled 1=first-chunk 2=continue 3=last-chunk
|
||||||
int8_t paste;
|
int8_t paste;
|
||||||
bool waiting;
|
bool waiting;
|
||||||
bool waiting_for_bg_response;
|
int8_t waiting_for_bg_response;
|
||||||
TermKey *tk;
|
TermKey *tk;
|
||||||
#if TERMKEY_VERSION_MAJOR > 0 || TERMKEY_VERSION_MINOR > 18
|
#if TERMKEY_VERSION_MAJOR > 0 || TERMKEY_VERSION_MINOR > 18
|
||||||
TermKey_Terminfo_Getstr_Hook *tk_ti_hook_fn; ///< libtermkey terminfo hook
|
TermKey_Terminfo_Getstr_Hook *tk_ti_hook_fn; ///< libtermkey terminfo hook
|
||||||
|
@@ -296,7 +296,7 @@ static void terminfo_start(UI *ui)
|
|||||||
unibi_out(ui, unibi_keypad_xmit);
|
unibi_out(ui, unibi_keypad_xmit);
|
||||||
unibi_out(ui, unibi_clear_screen);
|
unibi_out(ui, unibi_clear_screen);
|
||||||
// Ask the terminal to send us the background color.
|
// Ask the terminal to send us the background color.
|
||||||
data->input.waiting_for_bg_response = true;
|
data->input.waiting_for_bg_response = 5;
|
||||||
unibi_out_ext(ui, data->unibi_ext.get_bg);
|
unibi_out_ext(ui, data->unibi_ext.get_bg);
|
||||||
// Enable bracketed paste
|
// Enable bracketed paste
|
||||||
unibi_out_ext(ui, data->unibi_ext.enable_bracketed_paste);
|
unibi_out_ext(ui, data->unibi_ext.enable_bracketed_paste);
|
||||||
@@ -366,11 +366,6 @@ static void tui_terminal_after_startup(UI *ui)
|
|||||||
// 2.3 bug(?) which caused slow drawing during startup. #7649
|
// 2.3 bug(?) which caused slow drawing during startup. #7649
|
||||||
unibi_out_ext(ui, data->unibi_ext.enable_focus_reporting);
|
unibi_out_ext(ui, data->unibi_ext.enable_focus_reporting);
|
||||||
flush_buf(ui);
|
flush_buf(ui);
|
||||||
|
|
||||||
if (data->input.waiting_for_bg_response) {
|
|
||||||
DLOG("did not get a response for terminal background query");
|
|
||||||
data->input.waiting_for_bg_response = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tui_terminal_stop(UI *ui)
|
static void tui_terminal_stop(UI *ui)
|
||||||
|
@@ -16,7 +16,7 @@ itp('handle_background_color', function()
|
|||||||
local events = globals.main_loop.thread_events
|
local events = globals.main_loop.thread_events
|
||||||
|
|
||||||
-- Short-circuit when not waiting for response.
|
-- Short-circuit when not waiting for response.
|
||||||
term_input.waiting_for_bg_response = false
|
term_input.waiting_for_bg_response = 0
|
||||||
eq(false, handle_background_color(term_input))
|
eq(false, handle_background_color(term_input))
|
||||||
|
|
||||||
local capacity = 100
|
local capacity = 100
|
||||||
@@ -27,9 +27,9 @@ itp('handle_background_color', function()
|
|||||||
local term_response = '\027]11;'..colorspace..':'..color..'\007'
|
local term_response = '\027]11;'..colorspace..':'..color..'\007'
|
||||||
rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response)
|
rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response)
|
||||||
|
|
||||||
term_input.waiting_for_bg_response = true
|
term_input.waiting_for_bg_response = 1
|
||||||
eq(true, handle_background_color(term_input))
|
eq(true, handle_background_color(term_input))
|
||||||
eq(false, term_input.waiting_for_bg_response)
|
eq(0, term_input.waiting_for_bg_response)
|
||||||
eq(1, multiqueue.multiqueue_size(events))
|
eq(1, multiqueue.multiqueue_size(events))
|
||||||
|
|
||||||
local event = multiqueue.multiqueue_get(events)
|
local event = multiqueue.multiqueue_get(events)
|
||||||
@@ -101,10 +101,9 @@ itp('handle_background_color', function()
|
|||||||
local term_response = '\027]11;rgba:f/f/f/f' -- missing '\007
|
local term_response = '\027]11;rgba:f/f/f/f' -- missing '\007
|
||||||
rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response)
|
rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response)
|
||||||
|
|
||||||
term_input.waiting_for_bg_response = true
|
term_input.waiting_for_bg_response = 1
|
||||||
eq(true, term_input.waiting_for_bg_response)
|
|
||||||
eq(false, handle_background_color(term_input))
|
eq(false, handle_background_color(term_input))
|
||||||
eq(false, term_input.waiting_for_bg_response)
|
eq(0, term_input.waiting_for_bg_response)
|
||||||
|
|
||||||
eq(0, multiqueue.multiqueue_size(events))
|
eq(0, multiqueue.multiqueue_size(events))
|
||||||
eq(0, rbuf.size)
|
eq(0, rbuf.size)
|
||||||
@@ -114,10 +113,9 @@ itp('handle_background_color', function()
|
|||||||
term_response = '123\027]11;rgba:f/f/f/f\007456'
|
term_response = '123\027]11;rgba:f/f/f/f\007456'
|
||||||
rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response)
|
rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response)
|
||||||
|
|
||||||
term_input.waiting_for_bg_response = true
|
term_input.waiting_for_bg_response = 3
|
||||||
eq(true, term_input.waiting_for_bg_response)
|
|
||||||
eq(false, handle_background_color(term_input))
|
eq(false, handle_background_color(term_input))
|
||||||
eq(true, term_input.waiting_for_bg_response)
|
eq(2, term_input.waiting_for_bg_response)
|
||||||
|
|
||||||
eq(0, multiqueue.multiqueue_size(events))
|
eq(0, multiqueue.multiqueue_size(events))
|
||||||
eq(#term_response, rbuf.size)
|
eq(#term_response, rbuf.size)
|
||||||
@@ -128,10 +126,9 @@ itp('handle_background_color', function()
|
|||||||
term_response = '\027]11;rgba:f/f/f/f\007456'
|
term_response = '\027]11;rgba:f/f/f/f\007456'
|
||||||
rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response)
|
rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response)
|
||||||
|
|
||||||
term_input.waiting_for_bg_response = true
|
term_input.waiting_for_bg_response = 1
|
||||||
eq(true, term_input.waiting_for_bg_response)
|
|
||||||
eq(true, handle_background_color(term_input))
|
eq(true, handle_background_color(term_input))
|
||||||
eq(false, term_input.waiting_for_bg_response)
|
eq(0, term_input.waiting_for_bg_response)
|
||||||
|
|
||||||
eq(1, multiqueue.multiqueue_size(events))
|
eq(1, multiqueue.multiqueue_size(events))
|
||||||
eq(3, rbuf.size)
|
eq(3, rbuf.size)
|
||||||
|
Reference in New Issue
Block a user