mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	test: tty-test.c: restore win32 SIGWINCH handler
This commit is contained in:
		@@ -49,6 +49,7 @@ 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) {
 | 
				
			||||||
@@ -65,6 +66,17 @@ static void sig_handler(int signum)
 | 
				
			|||||||
    return;
 | 
					    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)
 | 
					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_t out;
 | 
				
			||||||
  uv_tty_init(&write_loop, &out, fileno(stdout), 0);
 | 
					  uv_tty_init(&write_loop, &out, fileno(stdout), 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef _WIN32
 | 
					// #ifdef _WIN32
 | 
				
			||||||
  if (invoke_sigwinch_handler) {
 | 
					//   if (invoke_sigwinch_handler) {
 | 
				
			||||||
    int width, height;
 | 
					//     int width, height;
 | 
				
			||||||
    uv_tty_get_winsize(&out, &width, &height);
 | 
					//     uv_tty_get_winsize(&out, &width, &height);
 | 
				
			||||||
    if (screen_rect.width != width || screen_rect.height != height) {
 | 
					//     if (screen_rect.width != width || screen_rect.height != height) {
 | 
				
			||||||
      screen_rect.width = width;
 | 
					//       screen_rect.width = width;
 | 
				
			||||||
      screen_rect.height = height;
 | 
					//       screen_rect.height = height;
 | 
				
			||||||
      // HACK: Invoke directly. See note at Screen:try_resize().
 | 
					//       // HACK: Invoke directly. See note at Screen:try_resize().
 | 
				
			||||||
      sig_handler(SIGWINCH);
 | 
					//       sig_handler(SIGWINCH);
 | 
				
			||||||
      uv_run(&write_loop, UV_RUN_NOWAIT);
 | 
					//       uv_run(&write_loop, UV_RUN_NOWAIT);
 | 
				
			||||||
    }
 | 
					//     }
 | 
				
			||||||
  } else {
 | 
					//   } else {
 | 
				
			||||||
#endif
 | 
					// #endif
 | 
				
			||||||
    uv_write_t req;
 | 
					    uv_write_t req;
 | 
				
			||||||
    uv_buf_t b = {.base = buf->base, .len = (size_t)cnt};
 | 
					    uv_buf_t b = {.base = buf->base, .len = (size_t)cnt};
 | 
				
			||||||
    uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL);
 | 
					    uv_write(&req, STRUCT_CAST(uv_stream_t, &out), &b, 1, NULL);
 | 
				
			||||||
    uv_run(&write_loop, UV_RUN_DEFAULT);
 | 
					    uv_run(&write_loop, UV_RUN_DEFAULT);
 | 
				
			||||||
#ifdef _WIN32
 | 
					// #ifdef _WIN32
 | 
				
			||||||
  }
 | 
					//   }
 | 
				
			||||||
#endif
 | 
					// #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);
 | 
				
			||||||
@@ -202,9 +214,9 @@ int main(int argc, char **argv)
 | 
				
			|||||||
  sigaction(SIGHUP, &sa, NULL);
 | 
					  sigaction(SIGHUP, &sa, NULL);
 | 
				
			||||||
  sigaction(SIGWINCH, &sa, NULL);
 | 
					  sigaction(SIGWINCH, &sa, NULL);
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
  // uv_signal_t sigwinch_watcher;
 | 
					  uv_signal_t sigwinch_watcher;
 | 
				
			||||||
  // uv_signal_init(uv_default_loop(), &sigwinch_watcher);
 | 
					  uv_signal_init(uv_default_loop(), &sigwinch_watcher);
 | 
				
			||||||
  // uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH);
 | 
					  uv_signal_start(&sigwinch_watcher, sigwinch_cb, SIGWINCH);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
  uv_run(uv_default_loop(), UV_RUN_DEFAULT);
 | 
					  uv_run(uv_default_loop(), UV_RUN_DEFAULT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -141,7 +141,6 @@ describe('terminal scrollback', function()
 | 
				
			|||||||
    describe('and the height is decreased by 1', function()
 | 
					    describe('and the height is decreased by 1', function()
 | 
				
			||||||
      local function will_hide_top_line()
 | 
					      local function will_hide_top_line()
 | 
				
			||||||
        screen:try_resize(screen._width, screen._height - 1)
 | 
					        screen:try_resize(screen._width, screen._height - 1)
 | 
				
			||||||
        retry(nil, 100000, function()
 | 
					 | 
				
			||||||
        screen:expect([[
 | 
					        screen:expect([[
 | 
				
			||||||
          line2                         |
 | 
					          line2                         |
 | 
				
			||||||
          line3                         |
 | 
					          line3                         |
 | 
				
			||||||
@@ -150,7 +149,6 @@ describe('terminal scrollback', function()
 | 
				
			|||||||
          {1: }                             |
 | 
					          {1: }                             |
 | 
				
			||||||
          {3:-- TERMINAL --}                |
 | 
					          {3:-- TERMINAL --}                |
 | 
				
			||||||
        ]])
 | 
					        ]])
 | 
				
			||||||
        end)
 | 
					 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      it('will hide top line', will_hide_top_line)
 | 
					      it('will hide top line', will_hide_top_line)
 | 
				
			||||||
@@ -162,7 +160,6 @@ describe('terminal scrollback', function()
 | 
				
			|||||||
        end)
 | 
					        end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        it('will hide the top 3 lines', function()
 | 
					        it('will hide the top 3 lines', function()
 | 
				
			||||||
          retry(nil, 100000, function()
 | 
					 | 
				
			||||||
          screen:expect([[
 | 
					          screen:expect([[
 | 
				
			||||||
            rows: 5, cols: 30             |
 | 
					            rows: 5, cols: 30             |
 | 
				
			||||||
            rows: 3, cols: 30             |
 | 
					            rows: 3, cols: 30             |
 | 
				
			||||||
@@ -181,9 +178,11 @@ describe('terminal scrollback', function()
 | 
				
			|||||||
      end)
 | 
					      end)
 | 
				
			||||||
    end)
 | 
					    end)
 | 
				
			||||||
  end)
 | 
					  end)
 | 
				
			||||||
  end)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe('with empty lines after the cursor', function()
 | 
					  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
 | 
					    if helpers.pending_win32(pending) then return end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    describe('and the height is decreased by 2', function()
 | 
					    describe('and the height is decreased by 2', function()
 | 
				
			||||||
@@ -250,7 +249,6 @@ describe('terminal scrollback', function()
 | 
				
			|||||||
        {3:-- TERMINAL --}                |
 | 
					        {3:-- TERMINAL --}                |
 | 
				
			||||||
      ]])
 | 
					      ]])
 | 
				
			||||||
      screen:try_resize(screen._width, screen._height - 3)
 | 
					      screen:try_resize(screen._width, screen._height - 3)
 | 
				
			||||||
      retry(nil, 100000, function()
 | 
					 | 
				
			||||||
      screen:expect([[
 | 
					      screen:expect([[
 | 
				
			||||||
        line4                         |
 | 
					        line4                         |
 | 
				
			||||||
        rows: 3, cols: 30             |
 | 
					        rows: 3, cols: 30             |
 | 
				
			||||||
@@ -259,9 +257,12 @@ describe('terminal scrollback', function()
 | 
				
			|||||||
      ]])
 | 
					      ]])
 | 
				
			||||||
      eq(7, curbuf('line_count'))
 | 
					      eq(7, curbuf('line_count'))
 | 
				
			||||||
    end)
 | 
					    end)
 | 
				
			||||||
    end)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    describe('and the height is increased by 1', function()
 | 
					    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()
 | 
					      local function pop_then_push()
 | 
				
			||||||
        screen:try_resize(screen._width, screen._height + 1)
 | 
					        screen:try_resize(screen._width, screen._height + 1)
 | 
				
			||||||
        screen:expect([[
 | 
					        screen:expect([[
 | 
				
			||||||
@@ -310,7 +311,6 @@ describe('terminal scrollback', function()
 | 
				
			|||||||
        it('will pop 3 lines and then push one back', pop3_then_push1)
 | 
					        it('will pop 3 lines and then push one back', pop3_then_push1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        describe('and then by 4', function()
 | 
					        describe('and then by 4', function()
 | 
				
			||||||
          if helpers.pending_win32(pending) then return end
 | 
					 | 
				
			||||||
          before_each(function()
 | 
					          before_each(function()
 | 
				
			||||||
            pop3_then_push1()
 | 
					            pop3_then_push1()
 | 
				
			||||||
            feed('Gi')
 | 
					            feed('Gi')
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,8 +73,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
local helpers = require('test.functional.helpers')(nil)
 | 
					local helpers = require('test.functional.helpers')(nil)
 | 
				
			||||||
local request, run, uimeths = helpers.request, helpers.run, helpers.uimeths
 | 
					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 dedent = helpers.dedent
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local Screen = {}
 | 
					local Screen = {}
 | 
				
			||||||
@@ -176,16 +174,6 @@ function Screen:try_resize(columns, rows)
 | 
				
			|||||||
  -- Give ourselves a chance to _handle_resize, which requires using
 | 
					  -- Give ourselves a chance to _handle_resize, which requires using
 | 
				
			||||||
  -- self.sleep() (for the resize notification) rather than run()
 | 
					  -- self.sleep() (for the resize notification) rather than run()
 | 
				
			||||||
  self:sleep(0.1)
 | 
					  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
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Asserts that `expected` eventually matches the screen state.
 | 
					-- Asserts that `expected` eventually matches the screen state.
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user