mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-124927: Fix conversion issue between coordinates and position in REPL (#125001)
This commit is contained in:
parent
a931a8b324
commit
6ab5c4aa05
4 changed files with 12 additions and 1 deletions
|
@ -62,7 +62,7 @@ def disp_str(buffer: str) -> tuple[str, list[int]]:
|
||||||
elif unicodedata.category(c).startswith("C"):
|
elif unicodedata.category(c).startswith("C"):
|
||||||
c = r"\u%04x" % ord(c)
|
c = r"\u%04x" % ord(c)
|
||||||
s.append(c)
|
s.append(c)
|
||||||
b.extend([0] * (len(c) - 1))
|
b.append(len(c))
|
||||||
else:
|
else:
|
||||||
s.append(c)
|
s.append(c)
|
||||||
b.append(str_width(c))
|
b.append(str_width(c))
|
||||||
|
@ -577,6 +577,7 @@ class Reader:
|
||||||
cur_x = self.screeninfo[i][0]
|
cur_x = self.screeninfo[i][0]
|
||||||
while cur_x < x:
|
while cur_x < x:
|
||||||
if self.screeninfo[i][1][j] == 0:
|
if self.screeninfo[i][1][j] == 0:
|
||||||
|
j += 1 # prevent potential future infinite loop
|
||||||
continue
|
continue
|
||||||
cur_x += self.screeninfo[i][1][j]
|
cur_x += self.screeninfo[i][1][j]
|
||||||
j += 1
|
j += 1
|
||||||
|
|
|
@ -319,3 +319,11 @@ class TestReader(TestCase):
|
||||||
# Simulate a resize to 0 columns
|
# Simulate a resize to 0 columns
|
||||||
reader.screeninfo = []
|
reader.screeninfo = []
|
||||||
self.assertEqual(reader.pos2xy(), (0, 0))
|
self.assertEqual(reader.pos2xy(), (0, 0))
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
|
@ -279,6 +279,7 @@ Laurent De Buyst
|
||||||
Zach Byrne
|
Zach Byrne
|
||||||
Vedran Čačić
|
Vedran Čačić
|
||||||
Nicolas Cadou
|
Nicolas Cadou
|
||||||
|
Zhikai Cai
|
||||||
Jp Calderone
|
Jp Calderone
|
||||||
Ben Caller
|
Ben Caller
|
||||||
Arnaud Calmettes
|
Arnaud Calmettes
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Non-printing characters are now properly handled in the new REPL.
|
Loading…
Add table
Add a link
Reference in a new issue