mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/reline] clear_screen use Windows API
https://github.com/ruby/reline/commit/2c5ee54cb3
This commit is contained in:
parent
770e66030a
commit
0862744010
1 changed files with 10 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue