summaryrefslogtreecommitdiff
path: root/lib/reline/windows.rb
diff options
context:
space:
mode:
authorYoshinao Muramatu <ysno@ac.auone-net.jp>2020-08-10 11:01:05 +0900
committeraycabta <aycabta@gmail.com>2020-09-12 08:35:51 +0900
commit0862744010907ecda8c8122557e97de9238d51a1 (patch)
treeec3fe3dcbcc537c83b440fbb24e4250fda411075 /lib/reline/windows.rb
parent770e66030a43967a7aae1050da364ed842f1f544 (diff)
[ruby/reline] clear_screen use Windows API
https://github.com/ruby/reline/commit/2c5ee54cb3
Diffstat (limited to 'lib/reline/windows.rb')
-rw-r--r--lib/reline/windows.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb
index c229c8536f..6459daa37f 100644
--- a/lib/reline/windows.rb
+++ b/lib/reline/windows.rb
@@ -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)