[ruby/reline] clear_screen use Windows API

https://github.com/ruby/reline/commit/2c5ee54cb3
This commit is contained in:
Yoshinao Muramatu 2020-08-10 11:01:05 +09:00 коммит произвёл aycabta
Родитель 770e66030a
Коммит 0862744010
1 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

@ -92,6 +92,7 @@ class Reline::Windows
@@ReadConsoleInput = Win32API.new('kernel32', 'ReadConsoleInput', ['L', 'P', 'L', 'P'], 'L')
@@GetFileType = Win32API.new('kernel32', 'GetFileType', ['L'], 'L')
@@GetFileInformationByHandleEx = Win32API.new('kernel32', 'GetFileInformationByHandleEx', ['L', 'I', 'P', 'L'], 'I')
@@FillConsoleOutputAttribute = Win32API.new('kernel32', 'FillConsoleOutputAttribute', ['L', 'L', 'L', 'L', 'P'], 'L')
@@input_buf = []
@@output_buf = []
@ -249,9 +250,15 @@ class Reline::Windows
end
def self.clear_screen
# TODO: Use FillConsoleOutputCharacter and FillConsoleOutputAttribute
write "\e[2J"
write "\e[1;1H"
coord_screen_top_left = 0
written = 0.chr * 4
csbi = 0.chr * 22
return if @@GetConsoleScreenBufferInfo.call(@@hConsoleHandle, csbi) == 0
con_size = csbi[0, 4].unpack('SS').inject(:*)
attributes = csbi[8, 2].unpack('S').first
@@FillConsoleOutputCharacter.call(@@hConsoleHandle, 0x20, con_size, coord_screen_top_left, written)
@@FillConsoleOutputAttribute.call(@@hConsoleHandle, attributes, con_size, coord_screen_top_left, written)
@@SetConsoleCursorPosition.call(@@hConsoleHandle, coord_screen_top_left)
end
def self.set_screen_size(rows, columns)