@@ -86,6 +86,11 @@ class CHAR_INFO(Structure):
86
86
FillConsoleOutputCharacter .argtypes = [HANDLE , CHAR , DWORD , _COORD , POINTER (DWORD )]
87
87
FillConsoleOutputCharacter .restype = BOOL
88
88
89
+ FillConsoleOutputAttribute = windll .kernel32 .FillConsoleOutputAttribute
90
+ FillConsoleOutputAttribute .use_last_error = True
91
+ FillConsoleOutputAttribute .argtypes = [HANDLE , WORD , DWORD , _COORD , POINTER (DWORD )]
92
+ FillConsoleOutputAttribute .restype = BOOL
93
+
89
94
ScrollConsoleScreenBuffer = windll .kernel32 .ScrollConsoleScreenBufferW
90
95
ScrollConsoleScreenBuffer .use_last_error = True
91
96
ScrollConsoleScreenBuffer .argtypes = [HANDLE , POINTER (SMALL_RECT ), POINTER (SMALL_RECT ), _COORD , POINTER (CHAR_INFO )]
@@ -99,7 +104,7 @@ class CHAR_INFO(Structure):
99
104
class Char (Union ):
100
105
_fields_ = [
101
106
("UnicodeChar" ,WCHAR ),
102
- ("Char" , CHAR ),
107
+ ("Char" , CHAR ),
103
108
]
104
109
105
110
class KeyEvent (ctypes .Structure ):
@@ -191,7 +196,7 @@ def __init__(
191
196
term : str = "" ,
192
197
encoding : str = "" ,
193
198
):
194
-
199
+
195
200
SetConsoleMode (OutHandle , ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING )
196
201
self .encoding = encoding or sys .getdefaultencoding ()
197
202
@@ -466,12 +471,13 @@ def move_cursor(self, x: int, y: int) -> None:
466
471
trace (f'move_cursor { x } { y } ' )
467
472
468
473
if x < 0 or y < 0 :
469
- raise ValueError (f"Bad cussor position { x } , { y } " )
474
+ raise ValueError (f"Bad cursor position { x } , { y } " )
470
475
471
476
self .__move_relative (x , y )
472
477
self .__posxy = x , y
473
478
474
- def set_cursor_vis (self , visible : bool ) -> None :
479
+
480
+ def set_cursor_vis (self , visible : bool ) -> None :
475
481
if visible :
476
482
self .__show_cursor ()
477
483
else :
@@ -483,9 +489,9 @@ def getheightwidth(self) -> tuple[int, int]:
483
489
info = CONSOLE_SCREEN_BUFFER_INFO ()
484
490
if not GetConsoleScreenBufferInfo (OutHandle , info ):
485
491
raise ctypes .WinError (ctypes .GetLastError ())
486
- return (info .srWindow .Bottom - info .srWindow .Top + 1 ,
492
+ return (info .srWindow .Bottom - info .srWindow .Top + 1 ,
487
493
info .srWindow .Right - info .srWindow .Left + 1 )
488
-
494
+
489
495
def get_event (self , block : bool = True ) -> Event | None :
490
496
"""Return an Event instance. Returns None if |block| is false
491
497
and there is no event pending, otherwise waits for the
@@ -546,6 +552,13 @@ def clear(self) -> None:
546
552
size = info .dwSize .X * info .dwSize .Y
547
553
if not FillConsoleOutputCharacter (OutHandle , b' ' , size , _COORD (), DWORD ()):
548
554
raise ctypes .WinError (ctypes .GetLastError ())
555
+ if not FillConsoleOutputAttribute (OutHandle , 0 , size , _COORD (), DWORD ()):
556
+ raise ctypes .WinError (ctypes .GetLastError ())
557
+ y = info .srWindow .Bottom - info .srWindow .Top + 1
558
+ self .__move_absolute (0 , y - info .dwSize .Y )
559
+ self .__posxy = 0 , 0
560
+ self .screen = ["" ]
561
+
549
562
550
563
def finish (self ) -> None :
551
564
"""Move the cursor to the end of the display and otherwise get
0 commit comments