(self, y, oldline, newline, px_coord)
| 635 | self.__move = self.__move_short |
| 636 | |
| 637 | def __write_changed_line(self, y, oldline, newline, px_coord): |
| 638 | # this is frustrating; there's no reason to test (say) |
| 639 | # self.dch1 inside the loop -- but alternative ways of |
| 640 | # structuring this function are equally painful (I'm trying to |
| 641 | # avoid writing code generators these days...) |
| 642 | minlen = min(wlen(oldline), wlen(newline)) |
| 643 | x_pos = 0 |
| 644 | x_coord = 0 |
| 645 | |
| 646 | px_pos = 0 |
| 647 | j = 0 |
| 648 | for c in oldline: |
| 649 | if j >= px_coord: |
| 650 | break |
| 651 | j += wlen(c) |
| 652 | px_pos += 1 |
| 653 | |
| 654 | # reuse the oldline as much as possible, but stop as soon as we |
| 655 | # encounter an ESCAPE, because it might be the start of an escape |
| 656 | # sequence |
| 657 | while ( |
| 658 | x_coord < minlen |
| 659 | and oldline[x_pos] == newline[x_pos] |
| 660 | and newline[x_pos] != "\x1b" |
| 661 | ): |
| 662 | x_coord += wlen(newline[x_pos]) |
| 663 | x_pos += 1 |
| 664 | |
| 665 | # if we need to insert a single character right after the first detected change |
| 666 | if oldline[x_pos:] == newline[x_pos + 1 :] and self.ich1: |
| 667 | if ( |
| 668 | y == self.posxy[1] |
| 669 | and x_coord > self.posxy[0] |
| 670 | and oldline[px_pos:x_pos] == newline[px_pos + 1 : x_pos + 1] |
| 671 | ): |
| 672 | x_pos = px_pos |
| 673 | x_coord = px_coord |
| 674 | character_width = wlen(newline[x_pos]) |
| 675 | self.__move(x_coord, y) |
| 676 | self.__write_code(self.ich1) |
| 677 | self.__write(newline[x_pos]) |
| 678 | self.posxy = x_coord + character_width, y |
| 679 | |
| 680 | # if it's a single character change in the middle of the line |
| 681 | elif ( |
| 682 | x_coord < minlen |
| 683 | and oldline[x_pos + 1 :] == newline[x_pos + 1 :] |
| 684 | and wlen(oldline[x_pos]) == wlen(newline[x_pos]) |
| 685 | ): |
| 686 | character_width = wlen(newline[x_pos]) |
| 687 | self.__move(x_coord, y) |
| 688 | self.__write(newline[x_pos]) |
| 689 | self.posxy = x_coord + character_width, y |
| 690 | |
| 691 | # if this is the last character to fit in the line and we edit in the middle of the line |
| 692 | elif ( |
| 693 | self.dch1 |
| 694 | and self.ich1 |
no test coverage detected