Set pos according to coordinates x, y
(self, x: int, y: int)
| 560 | self.input_trans = self.input_trans_stack.pop() |
| 561 | |
| 562 | def setpos_from_xy(self, x: int, y: int) -> None: |
| 563 | """Set pos according to coordinates x, y""" |
| 564 | pos = 0 |
| 565 | i = 0 |
| 566 | while i < y: |
| 567 | prompt_len, character_widths = self.screeninfo[i] |
| 568 | offset = len(character_widths) - character_widths.count(0) |
| 569 | in_wrapped_line = prompt_len + sum(character_widths) >= self.console.width |
| 570 | if in_wrapped_line: |
| 571 | pos += offset - 1 # -1 cause backslash is not in buffer |
| 572 | else: |
| 573 | pos += offset + 1 # +1 cause newline is in buffer |
| 574 | i += 1 |
| 575 | |
| 576 | j = 0 |
| 577 | cur_x = self.screeninfo[i][0] |
| 578 | while cur_x < x: |
| 579 | if self.screeninfo[i][1][j] == 0: |
| 580 | continue |
| 581 | cur_x += self.screeninfo[i][1][j] |
| 582 | j += 1 |
| 583 | pos += 1 |
| 584 | |
| 585 | self.pos = pos |
| 586 | |
| 587 | def pos2xy(self) -> tuple[int, int]: |
| 588 | """Return the x, y coordinates of position 'pos'.""" |