| 130 | return False |
| 131 | |
| 132 | class WindowsConsole(Console): |
| 133 | def __init__( |
| 134 | self, |
| 135 | f_in: IO[bytes] | int = 0, |
| 136 | f_out: IO[bytes] | int = 1, |
| 137 | term: str = "", |
| 138 | encoding: str = "", |
| 139 | ): |
| 140 | super().__init__(f_in, f_out, term, encoding) |
| 141 | |
| 142 | self.__vt_support = _supports_vt() |
| 143 | |
| 144 | if self.__vt_support: |
| 145 | trace('console supports virtual terminal') |
| 146 | |
| 147 | # Save original console modes so we can recover on cleanup. |
| 148 | original_input_mode = DWORD() |
| 149 | if not GetConsoleMode(InHandle, original_input_mode): |
| 150 | raise WinError(get_last_error()) |
| 151 | trace(f'saved original input mode 0x{original_input_mode.value:x}') |
| 152 | self.__original_input_mode = original_input_mode.value |
| 153 | |
| 154 | if not SetConsoleMode( |
| 155 | OutHandle, |
| 156 | ENABLE_WRAP_AT_EOL_OUTPUT |
| 157 | | ENABLE_PROCESSED_OUTPUT |
| 158 | | ENABLE_VIRTUAL_TERMINAL_PROCESSING, |
| 159 | ): |
| 160 | raise WinError(get_last_error()) |
| 161 | |
| 162 | self.screen: list[str] = [] |
| 163 | self.width = 80 |
| 164 | self.height = 25 |
| 165 | self.__offset = 0 |
| 166 | self.event_queue = EventQueue(encoding) |
| 167 | try: |
| 168 | self.out = io._WindowsConsoleIO(self.output_fd, "w") # type: ignore[attr-defined] |
| 169 | except ValueError: |
| 170 | # Console I/O is redirected, fallback... |
| 171 | self.out = None |
| 172 | |
| 173 | def refresh(self, screen: list[str], c_xy: tuple[int, int]) -> None: |
| 174 | """ |
| 175 | Refresh the console screen. |
| 176 | |
| 177 | Parameters: |
| 178 | - screen (list): List of strings representing the screen contents. |
| 179 | - c_xy (tuple): Cursor position (x, y) on the screen. |
| 180 | """ |
| 181 | cx, cy = c_xy |
| 182 | |
| 183 | while len(self.screen) < min(len(screen), self.height): |
| 184 | self._hide_cursor() |
| 185 | if self.screen: |
| 186 | self._move_relative(0, len(self.screen) - 1) |
| 187 | self.__write("\n") |
| 188 | self.posxy = 0, len(self.screen) |
| 189 | self.screen.append("") |
no outgoing calls
searching dependent graphs…