ruby-changes:57700
From: Nobuyoshi <ko1@a...>
Date: Tue, 10 Sep 2019 08:35:44 +0900 (JST)
Subject: [ruby-changes:57700] 3678c37119 (master): [ruby/io-console] Added IO#check_winsize_changed on Windows
https://git.ruby-lang.org/ruby.git/commit/?id=3678c37119 From 3678c371199d9a048589bf3da37f06223912dea5 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 10 Sep 2019 01:04:47 +0900 Subject: [ruby/io-console] Added IO#check_winsize_changed on Windows https://github.com/ruby/io-console/commit/ee648fa8bb diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 8145e59..5c834f6 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -671,6 +671,30 @@ console_set_winsize(VALUE io, VALUE size) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L671 } #endif +#ifdef _WIN32 +static VALUE +console_check_winsize_changed(VALUE io) +{ + rb_io_t *fptr; + HANDLE h; + DWORD num; + + GetOpenFile(io, fptr); + h = (HANDLE)rb_w32_get_osfhandle(GetReadFD(fptr)); + while (GetNumberOfConsoleInputEvents(h, &num) && num > 0) { + INPUT_RECORD rec; + if (ReadConsoleInput(h, &rec, 1, &num)) { + if (rec.EventType == WINDOW_BUFFER_SIZE_EVENT) { + rb_yield(Qnil); + } + } + } + return io; +} +#else +#define console_check_winsize_changed rb_f_notimplement +#endif + /* * call-seq: * io.iflush @@ -1394,6 +1418,7 @@ InitVM_console(void) https://github.com/ruby/ruby/blob/trunk/ext/io/console/console.c#L1418 rb_define_method(rb_cIO, "scroll_backward", console_scroll_backward, 1); rb_define_method(rb_cIO, "clear_screen", console_clear_screen, 0); rb_define_method(rb_cIO, "pressed?", console_key_pressed_p, 1); + rb_define_method(rb_cIO, "check_winsize_changed", console_check_winsize_changed, 0); #if ENABLE_IO_GETPASS rb_define_method(rb_cIO, "getpass", console_getpass, -1); #endif -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/