@@ -92,6 +92,7 @@ def call(*args)
92
92
@@ReadConsoleInput = Win32API . new ( 'kernel32' , 'ReadConsoleInput' , [ 'L' , 'P' , 'L' , 'P' ] , 'L' )
93
93
@@GetFileType = Win32API . new ( 'kernel32' , 'GetFileType' , [ 'L' ] , 'L' )
94
94
@@GetFileInformationByHandleEx = Win32API . new ( 'kernel32' , 'GetFileInformationByHandleEx' , [ 'L' , 'I' , 'P' , 'L' ] , 'I' )
95
+ @@FillConsoleOutputAttribute = Win32API . new ( 'kernel32' , 'FillConsoleOutputAttribute' , [ 'L' , 'L' , 'L' , 'L' , 'P' ] , 'L' )
95
96
96
97
@@input_buf = [ ]
97
98
@@output_buf = [ ]
@@ -249,9 +250,15 @@ def self.scroll_down(val)
249
250
end
250
251
251
252
def self . clear_screen
252
- # TODO: Use FillConsoleOutputCharacter and FillConsoleOutputAttribute
253
- write "\e [2J"
254
- write "\e [1;1H"
253
+ coord_screen_top_left = 0
254
+ written = 0 . chr * 4
255
+ csbi = 0 . chr * 22
256
+ return if @@GetConsoleScreenBufferInfo . call ( @@hConsoleHandle , csbi ) == 0
257
+ con_size = csbi [ 0 , 4 ] . unpack ( 'SS' ) . inject ( :* )
258
+ attributes = csbi [ 8 , 2 ] . unpack ( 'S' ) . first
259
+ @@FillConsoleOutputCharacter . call ( @@hConsoleHandle , 0x20 , con_size , coord_screen_top_left , written )
260
+ @@FillConsoleOutputAttribute . call ( @@hConsoleHandle , attributes , con_size , coord_screen_top_left , written )
261
+ @@SetConsoleCursorPosition . call ( @@hConsoleHandle , coord_screen_top_left )
255
262
end
256
263
257
264
def self . set_screen_size ( rows , columns )
0 commit comments