ruby-changes:70339
From: YO4 <ko1@a...>
Date: Mon, 20 Dec 2021 14:52:05 +0900 (JST)
Subject: [ruby-changes:70339] 2c415cda85 (master): [ruby/reline] windows improve scrolling
https://git.ruby-lang.org/ruby.git/commit/?id=2c415cda85 From 2c415cda854ab02f8341428b5346a115d3648a48 Mon Sep 17 00:00:00 2001 From: YO4 <ysno@a...> Date: Sat, 11 Dec 2021 23:04:38 +0900 Subject: [ruby/reline] windows improve scrolling ScrollConsoleScreenBuffer can't scroll window of Windows Terminal. Use LF to sctoll. Microsoft says ```In the virtual terminal sequences world, the size of the window and the size of the screen buffer are fixed to the same value. ``` https://docs.microsoft.com/en-us/windows/console/window-and-screen-buffer-size https://github.com/ruby/reline/commit/9ff3c70732 --- lib/reline/windows.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb index 15bc88aec3d..23bbd087a45 100644 --- a/lib/reline/windows.rb +++ b/lib/reline/windows.rb @@ -168,6 +168,8 @@ class Reline::Windows https://github.com/ruby/ruby/blob/trunk/lib/reline/windows.rb#L168 @@input_buf = [] @@output_buf = [] + @@output = STDOUT + def self.msys_tty?(io=@@hConsoleInputHandle) # check if fd is a pipe if @@GetFileType.call(io) != FILE_TYPE_PIPE @@ -370,13 +372,21 @@ class Reline::Windows https://github.com/ruby/ruby/blob/trunk/lib/reline/windows.rb#L372 end 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') - @@ScrollConsoleScreenBuffer.call(@@hConsoleHandle, scroll_rectangle, nil, destination_origin, fill) + return if val < 0 + + csbi = 0.chr * 22 + @@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi) + x, y, left, top, screen_height = csbi.unpack 'x4ssx2ssx2s' + + origin_x = x - left + 1 + origin_y = y - top + 1 + screen_height += 1 + val = screen_height if val > screen_height + @@output.write [ + (origin_y != screen_height) ? "\e[#{screen_height};H" : nil, + "\n" * val, + (origin_y != screen_height or !origin_x.zero?) ? "\e[#{origin_y};#{origin_x}H" : nil + ].join end def self.clear_screen -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/