diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-10 01:04:47 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-09-10 08:18:03 +0900 |
commit | 3678c371199d9a048589bf3da37f06223912dea5 (patch) | |
tree | f6772994c6fddbec41eb97522ec099c5541fbeae | |
parent | 74790e2dc429daddc6996bc46cb2a0aae2a176e9 (diff) | |
download | ruby-3678c371199d9a048589bf3da37f06223912dea5.tar.gz |
[ruby/io-console] Added IO#check_winsize_changed on Windows
https://github.com/ruby/io-console/commit/ee648fa8bb
-rw-r--r-- | ext/io/console/console.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ext/io/console/console.c b/ext/io/console/console.c index 8145e59ab8..5c834f6e72 100644 --- a/ext/io/console/console.c +++ b/ext/io/console/console.c @@ -671,6 +671,30 @@ console_set_winsize(VALUE io, VALUE size) } #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) 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 |