MCPcopy Index your code
hub / github.com/RustPython/RustPython / __write_changed_line

Method __write_changed_line

Lib/_pyrepl/unix_console.py:618–703  ·  view source on GitHub ↗
(self, y, oldline, newline, px_coord)

Source from the content-addressed store, hash-verified

616 self.__move = self.__move_short
617
618 def __write_changed_line(self, y, oldline, newline, px_coord):
619 # this is frustrating; there's no reason to test (say)
620 # self.dch1 inside the loop -- but alternative ways of
621 # structuring this function are equally painful (I'm trying to
622 # avoid writing code generators these days...)
623 minlen = min(wlen(oldline), wlen(newline))
624 x_pos = 0
625 x_coord = 0
626
627 px_pos = 0
628 j = 0
629 for c in oldline:
630 if j >= px_coord:
631 break
632 j += wlen(c)
633 px_pos += 1
634
635 # reuse the oldline as much as possible, but stop as soon as we
636 # encounter an ESCAPE, because it might be the start of an escape
637 # sequene
638 while (
639 x_coord < minlen
640 and oldline[x_pos] == newline[x_pos]
641 and newline[x_pos] != "\x1b"
642 ):
643 x_coord += wlen(newline[x_pos])
644 x_pos += 1
645
646 # if we need to insert a single character right after the first detected change
647 if oldline[x_pos:] == newline[x_pos + 1 :] and self.ich1:
648 if (
649 y == self.posxy[1]
650 and x_coord > self.posxy[0]
651 and oldline[px_pos:x_pos] == newline[px_pos + 1 : x_pos + 1]
652 ):
653 x_pos = px_pos
654 x_coord = px_coord
655 character_width = wlen(newline[x_pos])
656 self.__move(x_coord, y)
657 self.__write_code(self.ich1)
658 self.__write(newline[x_pos])
659 self.posxy = x_coord + character_width, y
660
661 # if it's a single character change in the middle of the line
662 elif (
663 x_coord < minlen
664 and oldline[x_pos + 1 :] == newline[x_pos + 1 :]
665 and wlen(oldline[x_pos]) == wlen(newline[x_pos])
666 ):
667 character_width = wlen(newline[x_pos])
668 self.__move(x_coord, y)
669 self.__write(newline[x_pos])
670 self.posxy = x_coord + character_width, y
671
672 # if this is the last character to fit in the line and we edit in the middle of the line
673 elif (
674 self.dch1
675 and self.ich1

Callers 1

refreshMethod · 0.95

Calls 6

__write_codeMethod · 0.95
__writeMethod · 0.95
__hide_cursorMethod · 0.95
move_cursorMethod · 0.95
minFunction · 0.85
wlenFunction · 0.85

Tested by

no test coverage detected