Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-124927: Fix conversion issue between coordinates and position in REPL #125001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-124927: Fix conversion issue between coordinates and position in REPL
  • Loading branch information
ImFeH2 committed Feb 21, 2025
commit fe4b3a8d69e27f83d7a5ccd2ad47035dbea370d9
3 changes: 2 additions & 1 deletion Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def disp_str(buffer: str) -> tuple[str, list[int]]:
elif unicodedata.category(c).startswith("C"):
c = r"\u%04x" % ord(c)
s.append(c)
b.extend([0] * (len(c) - 1))
b.append(len(c) - 1)
else:
s.append(c)
b.append(str_width(c))
Expand Down Expand Up @@ -577,6 +577,7 @@ def setpos_from_xy(self, x: int, y: int) -> None:
cur_x = self.screeninfo[i][0]
while cur_x < x:
if self.screeninfo[i][1][j] == 0:
j += 1
continue
cur_x += self.screeninfo[i][1][j]
j += 1
Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_pyrepl/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,15 @@ def test_key_press_on_tab_press_once(self):

self.assert_screen_equals(reader, f"{code}a")

def test_setpos_from_xy_for_non_printing_char(self):
code = "# non \u200c printing character"
events = code_to_events(code)

reader, _ = handle_all_events(events)
reader.setpos_from_xy(8, 0)

self.assertEqual(reader.pos, 7)

def test_pos2xy_with_no_columns(self):
console = prepare_console([])
reader = prepare_reader(console)
Expand Down