@@ -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
@@ -487,14 +492,14 @@ def move_cursor(self, x: int, y: int) -> None:
487
492
trace (f'move to { x } { y } ' )
488
493
489
494
if x < 0 or y < 0 :
490
- raise ValueError (f"Bad cussor position { x } , { y } " )
495
+ raise ValueError (f"Bad cursor position { x } , { y } " )
491
496
492
497
self .__move (x , y )
493
498
self .__posxy = x , y
494
499
self .flushoutput ()
495
-
496
500
497
- def set_cursor_vis (self , visible : bool ) -> None :
501
+
502
+ def set_cursor_vis (self , visible : bool ) -> None :
498
503
if visible :
499
504
self .__show_cursor ()
500
505
else :
@@ -506,9 +511,9 @@ def getheightwidth(self) -> tuple[int, int]:
506
511
info = CONSOLE_SCREEN_BUFFER_INFO ()
507
512
if not GetConsoleScreenBufferInfo (OutHandle , info ):
508
513
raise ctypes .WinError (ctypes .GetLastError ())
509
- return (info .srWindow .Bottom - info .srWindow .Top + 1 ,
514
+ return (info .srWindow .Bottom - info .srWindow .Top + 1 ,
510
515
info .srWindow .Right - info .srWindow .Left + 1 )
511
-
516
+
512
517
def get_event (self , block : bool = True ) -> Event | None :
513
518
"""Return an Event instance. Returns None if |block| is false
514
519
and there is no event pending, otherwise waits for the
@@ -527,7 +532,7 @@ def get_event(self, block: bool = True) -> Event | None:
527
532
key = chr (rec .Event .KeyEvent .uChar .Char [0 ])
528
533
# self.push_char(key)
529
534
if rec .Event .KeyEvent .uChar .Char == b'\r ' :
530
- return Event (evt = "key" , data = "\n " , raw = "\n " )
535
+ return Event (evt = "key" , data = "\n " , raw = "\n " )
531
536
trace ('virtual key code' , rec .Event .KeyEvent .wVirtualKeyCode , rec .Event .KeyEvent .uChar .Char )
532
537
if rec .Event .KeyEvent .wVirtualKeyCode == 8 :
533
538
return Event (evt = "key" , data = "backspace" , raw = rec .Event .KeyEvent .uChar .Char )
@@ -536,7 +541,7 @@ def get_event(self, block: bool = True) -> Event | None:
536
541
if rec .Event .KeyEvent .uChar .Char == b'\x00 ' :
537
542
code = VK_MAP .get (rec .Event .KeyEvent .wVirtualKeyCode )
538
543
if code :
539
- return Event (evt = "key" , data = code , raw = rec .Event .KeyEvent .uChar .Char )
544
+ return Event (evt = "key" , data = code , raw = rec .Event .KeyEvent .uChar .Char )
540
545
continue
541
546
#print(key, rec.Event.KeyEvent.wVirtualKeyCode)
542
547
return Event (evt = "key" , data = key , raw = rec .Event .KeyEvent .uChar .Char )
@@ -557,6 +562,13 @@ def clear(self) -> None:
557
562
size = info .dwSize .X * info .dwSize .Y
558
563
if not FillConsoleOutputCharacter (OutHandle , b' ' , size , _COORD (), DWORD ()):
559
564
raise ctypes .WinError (ctypes .GetLastError ())
565
+ if not FillConsoleOutputAttribute (OutHandle , 0 , size , _COORD (), DWORD ()):
566
+ raise ctypes .WinError (ctypes .GetLastError ())
567
+ y = info .srWindow .Bottom - info .srWindow .Top + 1
568
+ self .__move_absolute (0 , y - info .dwSize .Y )
569
+ self .__posxy = 0 , 0
570
+ self .screen = ["" ]
571
+
560
572
561
573
def finish (self ) -> None :
562
574
"""Move the cursor to the end of the display and otherwise get
0 commit comments