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

Method setpos_from_xy

Lib/_pyrepl/reader.py:562–585  ·  view source on GitHub ↗

Set pos according to coordinates x, y

(self, x: int, y: int)

Source from the content-addressed store, hash-verified

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'."""

Callers 2

doMethod · 0.80
doMethod · 0.80

Calls 3

lenFunction · 0.85
sumFunction · 0.50
countMethod · 0.45

Tested by

no test coverage detected