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

Method setpos_from_xy

Lib/_pyrepl/reader.py:513–537  ·  view source on GitHub ↗

Set pos according to coordinates x, y

(self, x: int, y: int)

Source from the content-addressed store, hash-verified

511 self.input_trans = self.input_trans_stack.pop()
512
513 def setpos_from_xy(self, x: int, y: int) -> None:
514 """Set pos according to coordinates x, y"""
515 pos = 0
516 i = 0
517 while i < y:
518 prompt_len, char_widths = self.screeninfo[i]
519 offset = len(char_widths)
520 in_wrapped_line = prompt_len + sum(char_widths) >= self.console.width
521 if in_wrapped_line:
522 pos += offset - 1 # -1 cause backslash is not in buffer
523 else:
524 pos += offset + 1 # +1 cause newline is in buffer
525 i += 1
526
527 j = 0
528 cur_x = self.screeninfo[i][0]
529 while cur_x < x:
530 if self.screeninfo[i][1][j] == 0:
531 j += 1 # prevent potential future infinite loop
532 continue
533 cur_x += self.screeninfo[i][1][j]
534 j += 1
535 pos += 1
536
537 self.pos = pos
538
539 def pos2xy(self) -> tuple[int, int]:
540 """Return the x, y coordinates of position 'pos'."""

Calls

no outgoing calls