test: tty-test.c: restore win32 SIGWINCH handler

This commit is contained in:
Justin M. Keyes 2017-08-07 00:26:43 +02:00
parent 6a90f53862
commit e0763e94ad
3 changed files with 38 additions and 38 deletions

View File

@ -49,6 +49,7 @@ static void walk_cb(uv_handle_t *handle, void *arg)
}
}
#ifndef WIN32
static void sig_handler(int signum)
{
switch (signum) {
@ -65,6 +66,17 @@ static void sig_handler(int signum)
return;
}
}
#else
static void sigwinch_cb(uv_signal_t *handle, int signum)
{
int width, height;
uv_tty_t out;
uv_tty_init(uv_default_loop(), &out, fileno(stdout), 0);
uv_tty_get_winsize(&out, &width, &height);
fprintf(stderr, "rows: %d, cols: %d\n", height, width);
uv_close((uv_handle_t *)&out, NULL);
}
#endif
static void alloc_cb(uv_handle_t *handle, size_t suggested, uv_buf_t *buf)
{
@ -101,26 +113,26 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf)
uv_tty_t out;
uv_tty_init(&write_loop, &out, fileno(stdout), 0);
#ifdef _WIN32
if (invoke_sigwinch_handler) {
int width, height;
uv_tty_get_winsize(&out, &width, &height);
if (screen_rect.width != width || screen_rect.height != height) {
screen_rect.width = width;
screen_rect.height = height;
// HACK: Invoke directly. See note at Screen:try_resize().
sig_handler(SIGWINCH);
uv_run(&write_loop, UV_RUN_NOWAIT);
}
} else {
#endif
// #ifdef _WIN32
// if (invoke_sigwinch_handler) {
// int width, height;
// uv_tty_get_winsize(&out, &width, &height);
// if (screen_rect.width != width || screen_rect.height != height) {
// screen_rect.width = width;
// screen_rect.height = height;
// // HACK: Invoke directly. See note at Screen:try_resize().
// sig_handler(SIGWINCH);
// uv_run(&write_loop, UV_RUN_NOWAIT);
// }
// } else {
// #endif
uv_write_t req;
uv_buf_t b = {.base = buf->base, .len = (size_t)cnt};
uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL);
uv_run(&write_loop, UV_RUN_DEFAULT);
#ifdef _WIN32
}
#endif
// #ifdef _WIN32
// }
// #endif
uv_close(STRUCT_CAST(uv_handle_t, &out), NULL);
uv_run(&write_loop, UV_RUN_DEFAULT);
@ -202,9 +214,9 @@ int main(int argc, char **argv)
sigaction(SIGHUP, &sa, NULL);
sigaction(SIGWINCH, &sa, NULL);
#else
// uv_signal_t sigwinch_watcher;
// uv_signal_init(uv_default_loop(), &sigwinch_watcher);
// uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH);
uv_signal_t sigwinch_watcher;
uv_signal_init(uv_default_loop(), &sigwinch_watcher);
uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH);
#endif
uv_run(uv_default_loop(), UV_RUN_DEFAULT);

View File

@ -141,7 +141,6 @@ describe('terminal scrollback', function()
describe('and the height is decreased by 1', function()
local function will_hide_top_line()
screen:try_resize(screen._width, screen._height - 1)
retry(nil, 100000, function()
screen:expect([[
line2 |
line3 |
@ -150,7 +149,6 @@ describe('terminal scrollback', function()
{1: } |
{3:-- TERMINAL --} |
]])
end)
end
it('will hide top line', will_hide_top_line)
@ -162,7 +160,6 @@ describe('terminal scrollback', function()
end)
it('will hide the top 3 lines', function()
retry(nil, 100000, function()
screen:expect([[
rows: 5, cols: 30 |
rows: 3, cols: 30 |
@ -177,13 +174,15 @@ describe('terminal scrollback', function()
rows: 3, cols: 30 |
|
]])
end)
end)
end)
end)
end)
describe('with empty lines after the cursor', function()
-- XXX: Can't test this reliably on Windows unless the cursor is _moved_
-- by the resize. http://docs.libuv.org/en/v1.x/signal.html
-- See also: https://github.com/rprichard/winpty/issues/110
if helpers.pending_win32(pending) then return end
describe('and the height is decreased by 2', function()
@ -250,7 +249,6 @@ describe('terminal scrollback', function()
{3:-- TERMINAL --} |
]])
screen:try_resize(screen._width, screen._height - 3)
retry(nil, 100000, function()
screen:expect([[
line4 |
rows: 3, cols: 30 |
@ -258,10 +256,13 @@ describe('terminal scrollback', function()
{3:-- TERMINAL --} |
]])
eq(7, curbuf('line_count'))
end)
end)
describe('and the height is increased by 1', function()
-- XXX: Can't test this reliably on Windows unless the cursor is _moved_
-- by the resize. http://docs.libuv.org/en/v1.x/signal.html
-- See also: https://github.com/rprichard/winpty/issues/110
if helpers.pending_win32(pending) then return end
local function pop_then_push()
screen:try_resize(screen._width, screen._height + 1)
screen:expect([[
@ -310,7 +311,6 @@ describe('terminal scrollback', function()
it('will pop 3 lines and then push one back', pop3_then_push1)
describe('and then by 4', function()
if helpers.pending_win32(pending) then return end
before_each(function()
pop3_then_push1()
feed('Gi')

View File

@ -73,8 +73,6 @@
local helpers = require('test.functional.helpers')(nil)
local request, run, uimeths = helpers.request, helpers.run, helpers.uimeths
local iswin, nvim, retry = helpers.iswin, helpers.nvim, helpers.retry
local dedent = helpers.dedent
local Screen = {}
@ -176,16 +174,6 @@ function Screen:try_resize(columns, rows)
-- Give ourselves a chance to _handle_resize, which requires using
-- self.sleep() (for the resize notification) rather than run()
self:sleep(0.1)
-- XXX: On Windows we don't bother to handle SIGWINCH.
-- CTRL-Q invokes the handler in tty-test.c directly.
-- uv_tty_update_virtual_window() _does_ emit SIGWINCH, but:
-- "SIGWINCH may not always be delivered in a timely manner; libuv
-- will only detect size changes when the cursor is being moved."
-- http://docs.libuv.org/en/v1.x/signal.html
if iswin() and 0 ~= nvim('eval', "exists('b:terminal_job_id')") then
nvim('command', [[call jobsend(b:terminal_job_id, "\<C-Q>")]])
end
end
-- Asserts that `expected` eventually matches the screen state.