ruby-changes:68398
From: Nobuyoshi <ko1@a...>
Date: Tue, 12 Oct 2021 13:19:38 +0900 (JST)
Subject: [ruby-changes:68398] a48dc89547 (master): [ruby/reline] Check the result of GetConsoleScreenBufferInfo
https://git.ruby-lang.org/ruby.git/commit/?id=a48dc89547 From a48dc89547e3c235350394b4a735c9d50892c152 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Tue, 12 Oct 2021 10:42:53 +0900 Subject: [ruby/reline] Check the result of GetConsoleScreenBufferInfo https://github.com/ruby/reline/commit/42edf7b3aa --- lib/reline/windows.rb | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb index e72e571a13..73653b2de2 100644 --- a/lib/reline/windows.rb +++ b/lib/reline/windows.rb @@ -283,15 +283,23 @@ class Reline::Windows https://github.com/ruby/ruby/blob/trunk/lib/reline/windows.rb#L283 end end - def self.get_screen_size + def self.get_console_screen_buffer_info csbi = 0.chr * 22 - @@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi) + return if @@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi) == 0 + csbi + end + + def self.get_screen_size + unless csbi = get_console_screen_buffer_info + return [1, 1] + end csbi[0, 4].unpack('SS').reverse end def self.cursor_pos - csbi = 0.chr * 22 - @@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi) + unless csbi = get_console_screen_buffer_info + return Reline::CursorPos.new(0, 0) + end x = csbi[4, 2].unpack1('s*') y = csbi[6, 2].unpack1('s*') Reline::CursorPos.new(x, y) @@ -313,6 +321,7 @@ class Reline::Windows https://github.com/ruby/ruby/blob/trunk/lib/reline/windows.rb#L321 def self.move_cursor_down(val) if val > 0 + return unless csbi = get_console_screen_buffer_info screen_height = get_screen_size.first y = cursor_pos.y + val y = screen_height - 1 if y > (screen_height - 1) @@ -323,8 +332,7 @@ class Reline::Windows https://github.com/ruby/ruby/blob/trunk/lib/reline/windows.rb#L332 end def self.erase_after_cursor - csbi = 0.chr * 22 - @@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi) + return unless csbi = get_console_screen_buffer_info attributes = csbi[8, 2].unpack1('S') cursor = csbi[4, 4].unpack1('L') written = 0.chr * 4 @@ -343,8 +351,7 @@ class Reline::Windows https://github.com/ruby/ruby/blob/trunk/lib/reline/windows.rb#L351 end def self.clear_screen - csbi = 0.chr * 22 - return if @@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi) == 0 + return unless csbi = get_console_screen_buffer_info buffer_width = csbi[0, 2].unpack1('S') attributes = csbi[8, 2].unpack1('S') _window_left, window_top, _window_right, window_bottom = *csbi[10,8].unpack('S*') -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/