@@ -165,19 +165,16 @@ def __init__(
165165 trace ('console supports virtual terminal' )
166166
167167 # Save original console modes so we can recover on cleanup.
168- original_input_mode = DWORD ()
169- if not GetConsoleMode (InHandle , original_input_mode ):
170- raise WinError (get_last_error ())
171- trace (f'saved original input mode 0x{ original_input_mode .value :x} ' )
172- self .__original_input_mode = original_input_mode .value
168+ assert _winapi is not None # to make mypy happy
169+ self .__original_input_mode = _winapi .GetConsoleMode (InHandle )
170+ trace (f'saved original input mode 0x{ self .__original_input_mode :x} ' )
173171
174- if not SetConsoleMode (
172+ _winapi . SetConsoleMode (
175173 OutHandle ,
176174 ENABLE_WRAP_AT_EOL_OUTPUT
177175 | ENABLE_PROCESSED_OUTPUT
178176 | ENABLE_VIRTUAL_TERMINAL_PROCESSING ,
179- ):
180- raise WinError (get_last_error ())
177+ )
181178
182179 self .width = 80
183180 self .height = 25
@@ -474,8 +471,8 @@ def prepare(self) -> None:
474471 self .sync_rendered_screen (RenderedScreen .empty (), self .posxy )
475472
476473 if self .__vt_support :
477- if not SetConsoleMode ( InHandle , self . __original_input_mode | ENABLE_VIRTUAL_TERMINAL_INPUT ):
478- raise WinError ( get_last_error () )
474+ assert _winapi is not None # to make mypy happy
475+ _winapi . SetConsoleMode ( InHandle , self . __original_input_mode | ENABLE_VIRTUAL_TERMINAL_INPUT )
479476 self ._enable_bracketed_paste ()
480477
481478 def restore (self ) -> None :
@@ -484,8 +481,8 @@ def restore(self) -> None:
484481 self .__write (ANSIColors .RESET )
485482 # Recover to original mode before running REPL
486483 self ._disable_bracketed_paste ()
487- if not SetConsoleMode ( InHandle , self . __original_input_mode ):
488- raise WinError ( get_last_error () )
484+ assert _winapi is not None # to make mypy happy
485+ _winapi . SetConsoleMode ( InHandle , self . __original_input_mode )
489486
490487 def _move_relative (self , x : int , y : int ) -> None :
491488 """Moves relative to the current posxy"""
@@ -661,8 +658,8 @@ def flushoutput(self) -> None:
661658
662659 def forgetinput (self ) -> None :
663660 """Forget all pending, but not yet processed input."""
664- if not FlushConsoleInputBuffer ( InHandle ):
665- raise WinError ( get_last_error () )
661+ assert _winapi is not None # to make mypy happy
662+ _winapi . FlushConsoleInputBuffer ( InHandle )
666663
667664 def getpending (self ) -> Event :
668665 """Return the characters that have been typed but not yet
@@ -815,23 +812,10 @@ class INPUT_RECORD(Structure):
815812 ]
816813 ScrollConsoleScreenBuffer .restype = BOOL
817814
818- GetConsoleMode = _KERNEL32 .GetConsoleMode
819- GetConsoleMode .argtypes = [HANDLE , POINTER (DWORD )]
820- GetConsoleMode .restype = BOOL
821-
822- SetConsoleMode = _KERNEL32 .SetConsoleMode
823- SetConsoleMode .argtypes = [HANDLE , DWORD ]
824- SetConsoleMode .restype = BOOL
825-
826815 ReadConsoleInput = _KERNEL32 .ReadConsoleInputW
827816 ReadConsoleInput .argtypes = [HANDLE , POINTER (INPUT_RECORD ), DWORD , POINTER (DWORD )]
828817 ReadConsoleInput .restype = BOOL
829818
830-
831- FlushConsoleInputBuffer = _KERNEL32 .FlushConsoleInputBuffer
832- FlushConsoleInputBuffer .argtypes = [HANDLE ]
833- FlushConsoleInputBuffer .restype = BOOL
834-
835819 OutHandle = _winapi .GetStdHandle (_winapi .STD_OUTPUT_HANDLE )
836820 InHandle = _winapi .GetStdHandle (_winapi .STD_INPUT_HANDLE )
837821else :
@@ -841,9 +825,6 @@ def _win_only(*args, **kwargs):
841825
842826 GetConsoleScreenBufferInfo = _win_only
843827 ScrollConsoleScreenBuffer = _win_only
844- GetConsoleMode = _win_only
845- SetConsoleMode = _win_only
846828 ReadConsoleInput = _win_only
847- FlushConsoleInputBuffer = _win_only
848829 OutHandle = 0
849830 InHandle = 0
0 commit comments