Refresh the console screen. Parameters: - screen (list): List of strings representing the screen contents. - c_xy (tuple): Cursor position (x, y) on the screen.
(self, screen: list[str], c_xy: tuple[int, int])
| 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("") |
| 190 | |
| 191 | px, py = self.posxy |
| 192 | old_offset = offset = self.__offset |
| 193 | height = self.height |
| 194 | |
| 195 | # we make sure the cursor is on the screen, and that we're |
| 196 | # using all of the screen if we can |
| 197 | if cy < offset: |
| 198 | offset = cy |
| 199 | elif cy >= offset + height: |
| 200 | offset = cy - height + 1 |
| 201 | scroll_lines = offset - old_offset |
| 202 | |
| 203 | # Scrolling the buffer as the current input is greater than the visible |
| 204 | # portion of the window. We need to scroll the visible portion and the |
| 205 | # entire history |
| 206 | self._scroll(scroll_lines, self._getscrollbacksize()) |
| 207 | self.posxy = self.posxy[0], self.posxy[1] + scroll_lines |
| 208 | self.__offset += scroll_lines |
| 209 | |
| 210 | for i in range(scroll_lines): |
| 211 | self.screen.append("") |
| 212 | elif offset > 0 and len(screen) < offset + height: |
| 213 | offset = max(len(screen) - height, 0) |
| 214 | screen.append("") |
| 215 | |
| 216 | oldscr = self.screen[old_offset : old_offset + height] |
| 217 | newscr = screen[offset : offset + height] |
| 218 | |
| 219 | self.__offset = offset |
| 220 | |
| 221 | self._hide_cursor() |
| 222 | for ( |
| 223 | y, |
| 224 | oldline, |
| 225 | newline, |
| 226 | ) in zip(range(offset, offset + height), oldscr, newscr): |
| 227 | if oldline != newline: |
| 228 | self.__write_changed_line(y, oldline, newline, px) |
| 229 | |
| 230 | y = len(newscr) |
nothing calls this directly
no test coverage detected