Skip to content

Commit

Permalink
[ruby/reline] windows clear screen with \e 2 J
Browse files Browse the repository at this point in the history
Windows Terminal does smart screen clearing when \e 2 J (not clear entire screen but scrolls down just needed)

On consoles not support sequences, ruby still converts it to API call.

ruby/reline@c00930dab9
  • Loading branch information
YO4 authored and matzbot committed Dec 20, 2021
1 parent 2c415cd commit 65cb250
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions lib/reline/windows.rb
Expand Up @@ -390,16 +390,7 @@ def self.scroll_down(val)
end

def self.clear_screen
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*')
fill_length = buffer_width * (window_bottom - window_top + 1)
screen_topleft = window_top * 65536
written = 0.chr * 4
@@FillConsoleOutputCharacter.call(@@hConsoleHandle, 0x20, fill_length, screen_topleft, written)
@@FillConsoleOutputAttribute.call(@@hConsoleHandle, attributes, fill_length, screen_topleft, written)
@@SetConsoleCursorPosition.call(@@hConsoleHandle, screen_topleft)
@@output.write "\e[2J" "\e[H"
end

def self.set_screen_size(rows, columns)
Expand Down

0 comments on commit 65cb250

Please sign in to comment.