diff options
author | aycabta <aycabta@gmail.com> | 2019-08-29 21:11:53 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2019-08-29 21:11:53 +0900 |
commit | a39b26b5947f19c4ec1d410e0d0869b5ab839c65 (patch) | |
tree | 8879ab340c78d301170846e6022d3834e612630a /lib/reline | |
parent | 3a425c7623d2062ae931dc83050c00a12873217b (diff) | |
download | ruby-a39b26b5947f19c4ec1d410e0d0869b5ab839c65.tar.gz |
Check events that console window size changed on Windows
Diffstat (limited to 'lib/reline')
-rw-r--r-- | lib/reline/windows.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb index 7d112e7632..e59f4ee3a9 100644 --- a/lib/reline/windows.rb +++ b/lib/reline/windows.rb @@ -51,7 +51,9 @@ class Reline::Windows VK_MENU = 0x12 VK_SHIFT = 0x10 + STD_INPUT_HANDLE = -10 STD_OUTPUT_HANDLE = -11 + WINDOW_BUFFER_SIZE_EVENT = 0x04 @@getwch = Win32API.new('msvcrt', '_getwch', [], 'I') @@kbhit = Win32API.new('msvcrt', '_kbhit', [], 'I') @@GetKeyState = Win32API.new('user32', 'GetKeyState', ['L'], 'L') @@ -61,6 +63,9 @@ class Reline::Windows @@FillConsoleOutputCharacter = Win32API.new('kernel32', 'FillConsoleOutputCharacter', ['L', 'L', 'L', 'L', 'P'], 'L') @@ScrollConsoleScreenBuffer = Win32API.new('kernel32', 'ScrollConsoleScreenBuffer', ['L', 'P', 'P', 'L', 'P'], 'L') @@hConsoleHandle = @@GetStdHandle.call(STD_OUTPUT_HANDLE) + @@hConsoleInputHandle = @@GetStdHandle.call(STD_INPUT_HANDLE) + @@GetNumberOfConsoleInputEvents = Win32API.new('kernel32', 'GetNumberOfConsoleInputEvents', ['L', 'P'], 'L') + @@ReadConsoleInput = Win32API.new('kernel32', 'ReadConsoleInput', ['L', 'P', 'L', 'P'], 'L') @@buf = [] def self.getwch @@ -81,6 +86,17 @@ class Reline::Windows end def self.getc + num_of_events = 0.chr * 8 + while @@GetNumberOfConsoleInputEvents.(@@hConsoleInputHandle, num_of_events) != 0 and num_of_events.unpack('L').first > 0 + input_record = 0.chr * 18 + read_event = 0.chr * 4 + if @@ReadConsoleInput.(@@hConsoleInputHandle, input_record, 1, read_event) != 0 + event = input_record[0, 2].unpack('s*').first + if event == WINDOW_BUFFER_SIZE_EVENT + @@winch_handler.() + end + end + end unless @@buf.empty? return @@buf.shift end @@ -182,6 +198,7 @@ class Reline::Windows end def self.set_winch_handler(&handler) + @@winch_handler = handler end def self.prep |