ruby-changes:62895
From: Yoshinao <ko1@a...>
Date: Sat, 12 Sep 2020 08:38:47 +0900 (JST)
Subject: [ruby-changes:62895] 0862744010 (master): [ruby/reline] clear_screen use Windows API
https://git.ruby-lang.org/ruby.git/commit/?id=0862744010 From 0862744010907ecda8c8122557e97de9238d51a1 Mon Sep 17 00:00:00 2001 From: Yoshinao Muramatu <ysno@a...> Date: Mon, 10 Aug 2020 11:01:05 +0900 Subject: [ruby/reline] clear_screen use Windows API https://github.com/ruby/reline/commit/2c5ee54cb3 diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb index c229c85..6459daa 100644 --- a/lib/reline/windows.rb +++ b/lib/reline/windows.rb @@ -92,6 +92,7 @@ class Reline::Windows https://github.com/ruby/ruby/blob/trunk/lib/reline/windows.rb#L92 @@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 https://github.com/ruby/ruby/blob/trunk/lib/reline/windows.rb#L250 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) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/