(
self, y: int, oldline: str, newline: str, px_coord: int
)
| 212 | return nt._inputhook |
| 213 | |
| 214 | def __write_changed_line( |
| 215 | self, y: int, oldline: str, newline: str, px_coord: int |
| 216 | ) -> None: |
| 217 | # this is frustrating; there's no reason to test (say) |
| 218 | # self.dch1 inside the loop -- but alternative ways of |
| 219 | # structuring this function are equally painful (I'm trying to |
| 220 | # avoid writing code generators these days...) |
| 221 | minlen = min(wlen(oldline), wlen(newline)) |
| 222 | x_pos = 0 |
| 223 | x_coord = 0 |
| 224 | |
| 225 | px_pos = 0 |
| 226 | j = 0 |
| 227 | for c in oldline: |
| 228 | if j >= px_coord: |
| 229 | break |
| 230 | j += wlen(c) |
| 231 | px_pos += 1 |
| 232 | |
| 233 | # reuse the oldline as much as possible, but stop as soon as we |
| 234 | # encounter an ESCAPE, because it might be the start of an escape |
| 235 | # sequene |
| 236 | while ( |
| 237 | x_coord < minlen |
| 238 | and oldline[x_pos] == newline[x_pos] |
| 239 | and newline[x_pos] != "\x1b" |
| 240 | ): |
| 241 | x_coord += wlen(newline[x_pos]) |
| 242 | x_pos += 1 |
| 243 | |
| 244 | self._hide_cursor() |
| 245 | self._move_relative(x_coord, y) |
| 246 | if wlen(oldline) > wlen(newline): |
| 247 | self._erase_to_end() |
| 248 | |
| 249 | self.__write(newline[x_pos:]) |
| 250 | if wlen(newline) == self.width: |
| 251 | # If we wrapped we want to start at the next line |
| 252 | self._move_relative(0, y + 1) |
| 253 | self.posxy = 0, y + 1 |
| 254 | else: |
| 255 | self.posxy = wlen(newline), y |
| 256 | |
| 257 | if "\x1b" in newline or y != self.posxy[1] or '\x1a' in newline: |
| 258 | # ANSI escape characters are present, so we can't assume |
| 259 | # anything about the position of the cursor. Moving the cursor |
| 260 | # to the left margin should work to get to a known position. |
| 261 | self.move_cursor(0, y) |
| 262 | |
| 263 | def _scroll( |
| 264 | self, top: int, bottom: int, left: int | None = None, right: int | None = None |
no test coverage detected