Return the x, y coordinates of position 'pos'.
(self)
| 585 | self.pos = pos |
| 586 | |
| 587 | def pos2xy(self) -> tuple[int, int]: |
| 588 | """Return the x, y coordinates of position 'pos'.""" |
| 589 | # this *is* incomprehensible, yes. |
| 590 | p, y = 0, 0 |
| 591 | l2: list[int] = [] |
| 592 | pos = self.pos |
| 593 | assert 0 <= pos <= len(self.buffer) |
| 594 | if pos == len(self.buffer) and len(self.screeninfo) > 0: |
| 595 | y = len(self.screeninfo) - 1 |
| 596 | p, l2 = self.screeninfo[y] |
| 597 | return p + sum(l2) + l2.count(0), y |
| 598 | |
| 599 | for p, l2 in self.screeninfo: |
| 600 | l = len(l2) - l2.count(0) |
| 601 | in_wrapped_line = p + sum(l2) >= self.console.width |
| 602 | offset = l - 1 if in_wrapped_line else l # need to remove backslash |
| 603 | if offset >= pos: |
| 604 | break |
| 605 | |
| 606 | if p + sum(l2) >= self.console.width: |
| 607 | pos -= l - 1 # -1 cause backslash is not in buffer |
| 608 | else: |
| 609 | pos -= l + 1 # +1 cause newline is in buffer |
| 610 | y += 1 |
| 611 | return p + sum(l2[:pos]), y |
| 612 | |
| 613 | def insert(self, text: str | list[str]) -> None: |
| 614 | """Insert 'text' at the insertion point.""" |
no test coverage detected