summaryrefslogtreecommitdiff
path: root/lib/reline
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-12-17 19:57:44 +0900
committeraycabta <aycabta@gmail.com>2020-12-17 20:17:22 +0900
commitcdf2790aa089c5ff608dd97407b5ce684cc9f415 (patch)
treee341e6c00abd160041ee09cadf209c4958eaecbb /lib/reline
parent0158ba7e51cb3fc5a204cb65d1be1618802e08d2 (diff)
[ruby/reline] Support longer than screen height on Windows
https://github.com/ruby/reline/commit/2a97ca9362
Diffstat (limited to 'lib/reline')
-rw-r--r--lib/reline/windows.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb
index b09290bcf3..937941b960 100644
--- a/lib/reline/windows.rb
+++ b/lib/reline/windows.rb
@@ -233,7 +233,9 @@ class Reline::Windows
def self.move_cursor_up(val)
if val > 0
- @@SetConsoleCursorPosition.call(@@hConsoleHandle, (cursor_pos.y - val) * 65536 + cursor_pos.x)
+ y = cursor_pos.y - val
+ y = 0 if y < 0
+ @@SetConsoleCursorPosition.call(@@hConsoleHandle, y * 65536 + cursor_pos.x)
elsif val < 0
move_cursor_down(-val)
end
@@ -241,6 +243,9 @@ class Reline::Windows
def self.move_cursor_down(val)
if val > 0
+ screen_height = get_screen_size.first
+ y = cursor_pos.y + val
+ y = screen_height - 1 if y > (screen_height - 1)
@@SetConsoleCursorPosition.call(@@hConsoleHandle, (cursor_pos.y + val) * 65536 + cursor_pos.x)
elsif val < 0
move_cursor_up(-val)
@@ -257,6 +262,8 @@ class Reline::Windows
def self.scroll_down(val)
return if val.zero?
+ screen_height = get_screen_size.first
+ val = screen_height - 1 if val > (screen_height - 1)
scroll_rectangle = [0, val, get_screen_size.last, get_screen_size.first].pack('s4')
destination_origin = 0 # y * 65536 + x
fill = [' '.ord, 0].pack('SS')