Skip to content

Commit ab39fbd

Browse files
committed
gh-124927: Fix conversion issue between coordinates and position in REPL
1 parent 20af4e2 commit ab39fbd

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

Lib/_pyrepl/reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def disp_str(buffer: str) -> tuple[str, list[int]]:
6262
elif unicodedata.category(c).startswith("C"):
6363
c = r"\u%04x" % ord(c)
6464
s.append(c)
65-
b.append(len(c) - 1)
65+
b.append(len(c))
6666
else:
6767
s.append(c)
6868
b.append(str_width(c))
@@ -577,7 +577,7 @@ def setpos_from_xy(self, x: int, y: int) -> None:
577577
cur_x = self.screeninfo[i][0]
578578
while cur_x < x:
579579
if self.screeninfo[i][1][j] == 0:
580-
j += 1
580+
j += 1 # prevent infinite loop
581581
continue
582582
cur_x += self.screeninfo[i][1][j]
583583
j += 1

Lib/test/test_pyrepl/test_reader.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,18 +313,17 @@ def test_key_press_on_tab_press_once(self):
313313

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

316+
def test_pos2xy_with_no_columns(self):
317+
console = prepare_console([])
318+
reader = prepare_reader(console)
319+
# Simulate a resize to 0 columns
320+
reader.screeninfo = []
321+
self.assertEqual(reader.pos2xy(), (0, 0))
322+
316323
def test_setpos_from_xy_for_non_printing_char(self):
317324
code = "# non \u200c printing character"
318325
events = code_to_events(code)
319326

320327
reader, _ = handle_all_events(events)
321328
reader.setpos_from_xy(8, 0)
322-
323329
self.assertEqual(reader.pos, 7)
324-
325-
def test_pos2xy_with_no_columns(self):
326-
console = prepare_console([])
327-
reader = prepare_reader(console)
328-
# Simulate a resize to 0 columns
329-
reader.screeninfo = []
330-
self.assertEqual(reader.pos2xy(), (0, 0))

0 commit comments

Comments
 (0)