test: tty-test.c: keep tty_out handle around

Now the window_split_tab_spec.lua test seems to work.
Also do some cleanup.
This commit is contained in:
Justin M. Keyes 2017-08-13 15:24:25 +02:00
parent d2d76882f7
commit 91c85a6378
2 changed files with 11 additions and 54 deletions

View File

@ -16,17 +16,9 @@
#define is_terminal(stream) (uv_guess_handle(fileno(stream)) == UV_TTY) #define is_terminal(stream) (uv_guess_handle(fileno(stream)) == UV_TTY)
#define BUF_SIZE 0xfff #define BUF_SIZE 0xfff
#define CTRL_C 0x03 #define CTRL_C 0x03
#define CTRL_Q 0x11
uv_tty_t tty; uv_tty_t tty;
uv_tty_t tty_out;
#ifdef _WIN32
typedef struct screen_size {
int width;
int height;
} ScreenSize;
ScreenSize screen_rect;
#endif
bool owns_tty(void) bool owns_tty(void)
{ {
@ -49,7 +41,6 @@ static void walk_cb(uv_handle_t *handle, void *arg)
} }
} }
#ifndef WIN32
static void sig_handler(int signum) static void sig_handler(int signum)
{ {
switch (signum) { switch (signum) {
@ -66,15 +57,13 @@ static void sig_handler(int signum)
return; return;
} }
} }
#else
#ifdef WIN32
static void sigwinch_cb(uv_signal_t *handle, int signum) static void sigwinch_cb(uv_signal_t *handle, int signum)
{ {
int width, height; int width, height;
uv_tty_t out; uv_tty_get_winsize(&tty_out, &width, &height);
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); fprintf(stderr, "rows: %d, cols: %d\n", height, width);
uv_close((uv_handle_t *)&out, NULL);
} }
#endif #endif
@ -92,19 +81,10 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf)
} }
int *interrupted = stream->data; int *interrupted = stream->data;
#ifdef _WIN32
// HACK: Special-case to avoid relying on SIGWINCH on Windows.
// See note at Screen:try_resize().
bool invoke_sigwinch_handler = false;
#endif
for (int i = 0; i < cnt; i++) { for (int i = 0; i < cnt; i++) {
if (buf->base[i] == CTRL_C) { if (buf->base[i] == CTRL_C) {
(*interrupted)++; (*interrupted)++;
#ifdef _WIN32
} else if (buf->base[i] == CTRL_Q) {
invoke_sigwinch_handler = true;
#endif
} }
} }
@ -113,26 +93,10 @@ static void read_cb(uv_stream_t *stream, ssize_t cnt, const uv_buf_t *buf)
uv_tty_t out; uv_tty_t out;
uv_tty_init(&write_loop, &out, fileno(stdout), 0); uv_tty_init(&write_loop, &out, fileno(stdout), 0);
// #ifdef _WIN32 uv_write_t req;
// if (invoke_sigwinch_handler) { uv_buf_t b = {.base = buf->base, .len = (size_t)cnt};
// int width, height; uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL);
// uv_tty_get_winsize(&out, &width, &height); uv_run(&write_loop, UV_RUN_DEFAULT);
// 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
uv_close(STRUCT_CAST(uv_handle_t, &out), NULL); uv_close(STRUCT_CAST(uv_handle_t, &out), NULL);
uv_run(&write_loop, UV_RUN_DEFAULT); uv_run(&write_loop, UV_RUN_DEFAULT);
@ -189,19 +153,13 @@ int main(int argc, char **argv)
uv_prepare_t prepare; uv_prepare_t prepare;
uv_prepare_init(uv_default_loop(), &prepare); uv_prepare_init(uv_default_loop(), &prepare);
uv_prepare_start(&prepare, prepare_cb); uv_prepare_start(&prepare, prepare_cb);
// uv_tty_t tty;
#ifndef WIN32 #ifndef WIN32
uv_tty_init(uv_default_loop(), &tty, fileno(stderr), 1); uv_tty_init(uv_default_loop(), &tty, fileno(stderr), 1);
#else #else
uv_tty_init(uv_default_loop(), &tty, fileno(stdin), 1); uv_tty_init(uv_default_loop(), &tty, fileno(stdin), 1);
uv_tty_t out; uv_tty_init(uv_default_loop(), &tty_out, fileno(stdout), 0);
uv_tty_init(uv_default_loop(), &out, fileno(stdout), 0); int width, height;
int width; uv_tty_get_winsize(&tty_out, &width, &height);
int height;
uv_tty_get_winsize(&out, &width, &height);
screen_rect.width = width;
screen_rect.height = height;
uv_close((uv_handle_t *)&out, NULL);
#endif #endif
uv_tty_set_mode(&tty, UV_TTY_MODE_RAW); uv_tty_set_mode(&tty, UV_TTY_MODE_RAW);
tty.data = &interrupted; tty.data = &interrupted;

View File

@ -68,7 +68,6 @@ describe('terminal', function()
describe('when the screen is resized', function() describe('when the screen is resized', function()
it('will forward a resize request to the program', function() it('will forward a resize request to the program', function()
if helpers.pending_win32(pending) then return end
feed([[<C-\><C-N>:]]) -- Go to cmdline-mode, so cursor is at bottom. feed([[<C-\><C-N>:]]) -- Go to cmdline-mode, so cursor is at bottom.
screen:try_resize(screen._width - 3, screen._height - 2) screen:try_resize(screen._width - 3, screen._height - 2)
screen:expect([[ screen:expect([[