diff options
author | YO4 <ysno@ac.auone-net.jp> | 2021-12-11 23:04:38 +0900 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2021-12-20 14:51:51 +0900 |
commit | 2c415cda854ab02f8341428b5346a115d3648a48 (patch) | |
tree | 2f9a23a0adcdb02fe1617edc54b1920db30fd9f1 /lib | |
parent | a856489be63f78b137cb2517c9d812a911d58fbe (diff) |
[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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/reline/windows.rb | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb index 15bc88aec3..23bbd087a4 100644 --- a/lib/reline/windows.rb +++ b/lib/reline/windows.rb @@ -168,6 +168,8 @@ class Reline::Windows @@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 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 |