diff options
-rw-r--r-- | test/functional/fixtures/tty-test.c | 53 | ||||
-rw-r--r-- | test/functional/terminal/helpers.lua | 7 | ||||
-rw-r--r-- | test/functional/terminal/scrollback_spec.lua | 18 |
3 files changed, 44 insertions, 34 deletions
diff --git a/test/functional/fixtures/tty-test.c b/test/functional/fixtures/tty-test.c index dd94d1a256..3e71ca209b 100644 --- a/test/functional/fixtures/tty-test.c +++ b/test/functional/fixtures/tty-test.c @@ -15,11 +15,11 @@ uv_tty_t tty; #include <windows.h> bool owns_tty(void) { - /* XXX: We need to make proper detect owns tty */ - /* HWND consoleWnd = GetConsoleWindow(); */ - /* DWORD dwProcessId; */ - /* GetWindowThreadProcessId(consoleWnd, &dwProcessId); */ - /* return GetCurrentProcessId() == dwProcessId; */ + // XXX: We need to make proper detect owns tty + // HWND consoleWnd = GetConsoleWindow(); + // DWORD dwProcessId; + // GetWindowThreadProcessId(consoleWnd, &dwProcessId); + // return GetCurrentProcessId() == dwProcessId; return true; } #else @@ -57,15 +57,15 @@ static void sig_handler(int signum) } } #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); -} +// 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) @@ -82,10 +82,14 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) } int *interrupted = stream->data; + bool prsz = false; + int width, height; for (int i = 0; i < cnt; i++) { if (buf->base[i] == 3) { (*interrupted)++; + } else if (buf->base[i] == 17) { + prsz = true; } } @@ -93,10 +97,17 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf) uv_loop_init(&write_loop); uv_tty_t out; uv_tty_init(&write_loop, &out, fileno(stdout), 0); - 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); + + if (prsz) { + uv_tty_get_winsize(&out, &width, &height); + fprintf(stderr, "rows: %d, cols: %d\n", height, width); + } else { + 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); + } + uv_close(STRUCT_CAST(uv_handle_t, &out), NULL); uv_run(&write_loop, UV_RUN_DEFAULT); if (uv_loop_close(&write_loop)) { @@ -169,9 +180,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); diff --git a/test/functional/terminal/helpers.lua b/test/functional/terminal/helpers.lua index 29381ab4f0..c67640f048 100644 --- a/test/functional/terminal/helpers.lua +++ b/test/functional/terminal/helpers.lua @@ -30,10 +30,9 @@ local function clear_attrs() feed_termcode('[0;10m') end -- mouse local function enable_mouse() feed_termcode('[?1002h') end local function disable_mouse() feed_termcode('[?1002l') end -local function wait_sigwinch() +local function print_screen_size() helpers.sleep(1000) - hide_cursor() - show_cursor() + nvim('command', 'call jobsend(b:terminal_job_id, "\\<C-q>")') end local default_command = '["'..nvim_dir..'/tty-test'..'"]' @@ -116,6 +115,6 @@ return { clear_attrs = clear_attrs, enable_mouse = enable_mouse, disable_mouse = disable_mouse, - wait_sigwinch = wait_sigwinch, + print_screen_size = print_screen_size, screen_setup = screen_setup } diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index 649bb4373b..1333736376 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -3,7 +3,7 @@ local helpers = require('test.functional.helpers')(after_each) local thelpers = require('test.functional.terminal.helpers') local clear, eq, curbuf = helpers.clear, helpers.eq, helpers.curbuf local feed, nvim_dir, feed_command = helpers.feed, helpers.nvim_dir, helpers.feed_command -local iswin, wait_sigwinch = helpers.iswin, thelpers.wait_sigwinch +local iswin, print_screen_size = helpers.iswin, thelpers.print_screen_size local eval = helpers.eval local command = helpers.command local wait = helpers.wait @@ -142,7 +142,7 @@ describe('terminal scrollback', function() local function will_hide_top_line() screen:try_resize(screen._width, screen._height - 1) if iswin() then - wait_sigwinch() + print_screen_size() end screen:expect([[ line2 | @@ -161,7 +161,7 @@ describe('terminal scrollback', function() will_hide_top_line() screen:try_resize(screen._width, screen._height - 2) if iswin() then - wait_sigwinch() + print_screen_size() end end) @@ -190,7 +190,7 @@ describe('terminal scrollback', function() before_each(function() screen:try_resize(screen._width, screen._height - 2) if iswin() then - wait_sigwinch() + print_screen_size() end end) @@ -214,7 +214,7 @@ describe('terminal scrollback', function() will_delete_last_two_lines() screen:try_resize(screen._width, screen._height - 1) if iswin() then - wait_sigwinch() + print_screen_size() end end) @@ -259,7 +259,7 @@ describe('terminal scrollback', function() ]]) screen:try_resize(screen._width, screen._height - 3) if iswin() then - wait_sigwinch() + print_screen_size() end screen:expect([[ line4 | @@ -274,7 +274,7 @@ describe('terminal scrollback', function() local function pop_then_push() screen:try_resize(screen._width, screen._height + 1) if iswin() then - wait_sigwinch() + print_screen_size() end screen:expect([[ line4 | @@ -293,7 +293,7 @@ describe('terminal scrollback', function() eq(8, curbuf('line_count')) screen:try_resize(screen._width, screen._height + 3) if iswin() then - wait_sigwinch() + print_screen_size() end end) @@ -331,7 +331,7 @@ describe('terminal scrollback', function() feed('Gi') screen:try_resize(screen._width, screen._height + 4) if iswin() then - wait_sigwinch() + print_screen_size() end end) |