MCPcopy Index your code
hub / github.com/python/cpython / __write_changed_line

Method __write_changed_line

Lib/_pyrepl/windows_console.py:249–279  ·  view source on GitHub ↗
(
        self, y: int, oldline: str, newline: str, px_coord: int
    )

Source from the content-addressed store, hash-verified

247 return nt._inputhook
248
249 def __write_changed_line(
250 self, y: int, oldline: str, newline: str, px_coord: int
251 ) -> None:
252 minlen = min(wlen(oldline), wlen(newline))
253 x_pos = 0
254 x_coord = 0
255
256 # reuse the oldline as much as possible, but stop as soon as we
257 # encounter an ESCAPE, because it might be the start of an escape
258 # sequence
259 while (
260 x_coord < minlen
261 and oldline[x_pos] == newline[x_pos]
262 and newline[x_pos] != "\x1b"
263 ):
264 x_coord += wlen(newline[x_pos])
265 x_pos += 1
266
267 self._hide_cursor()
268 self._move_relative(x_coord, y)
269 if wlen(oldline) > wlen(newline):
270 self._erase_to_end()
271
272 self.__write(newline[x_pos:])
273 self.posxy = min(wlen(newline), self.width - 1), y
274
275 if "\x1b" in newline or y != self.posxy[1] or '\x1a' in newline:
276 # ANSI escape characters are present, so we can't assume
277 # anything about the position of the cursor. Moving the cursor
278 # to the left margin should work to get to a known position.
279 self.move_cursor(0, y)
280
281 def _scroll(
282 self, top: int, bottom: int, left: int | None = None, right: int | None = None

Callers 1

refreshMethod · 0.95

Calls 6

_hide_cursorMethod · 0.95
_move_relativeMethod · 0.95
_erase_to_endMethod · 0.95
__writeMethod · 0.95
move_cursorMethod · 0.95
wlenFunction · 0.85

Tested by

no test coverage detected