From fe4b3a8d69e27f83d7a5ccd2ad47035dbea370d9 Mon Sep 17 00:00:00 2001 From: Zhikai Cai Date: Sat, 5 Oct 2024 21:21:17 +0800 Subject: [PATCH 1/6] gh-124927: Fix conversion issue between coordinates and position in REPL --- Lib/_pyrepl/reader.py | 3 ++- Lib/test/test_pyrepl/test_reader.py | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py index 1252847e02b2ea..5a144dc6b5f8f4 100644 --- a/Lib/_pyrepl/reader.py +++ b/Lib/_pyrepl/reader.py @@ -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)) @@ -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 diff --git a/Lib/test/test_pyrepl/test_reader.py b/Lib/test/test_pyrepl/test_reader.py index f3b243d3c279e5..04bca9afe7f82d 100644 --- a/Lib/test/test_pyrepl/test_reader.py +++ b/Lib/test/test_pyrepl/test_reader.py @@ -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) From d4048e75853c6ac4696a2870ea4a252dcf5e83b9 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 5 Oct 2024 13:25:08 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst diff --git a/Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst b/Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst new file mode 100644 index 00000000000000..618d0d3e4cbc94 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst @@ -0,0 +1 @@ +Non-printing characters are now properly handled. From c578f198b266ab415fd9019786b87e83a7336538 Mon Sep 17 00:00:00 2001 From: Zhikai Cai Date: Sat, 5 Oct 2024 21:40:31 +0800 Subject: [PATCH 3/6] gh-124927: Fix conversion issue between coordinates and position in REPL --- Misc/ACKS | 1 + 1 file changed, 1 insertion(+) diff --git a/Misc/ACKS b/Misc/ACKS index 2a68b69f161041..5d4bac2670a928 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -279,6 +279,7 @@ Laurent De Buyst Zach Byrne Vedran Čačić Nicolas Cadou +Zhikai Cai Jp Calderone Ben Caller Arnaud Calmettes From fca5a91dbec04a2778718d9c640cff3e7c8b4cd1 Mon Sep 17 00:00:00 2001 From: FeH2 Date: Wed, 9 Oct 2024 09:04:07 +0800 Subject: [PATCH 4/6] Update Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Miro Hrončok --- .../next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst b/Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst index 618d0d3e4cbc94..1fc485cd0527f0 100644 --- a/Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst +++ b/Misc/NEWS.d/next/Library/2024-10-05-13-25-07.gh-issue-124927.uzNA32.rst @@ -1 +1 @@ -Non-printing characters are now properly handled. +Non-printing characters are now properly handled in the new REPL. From 77596c2ee80c992181167b38897fae9429148126 Mon Sep 17 00:00:00 2001 From: Zhikai Cai Date: Thu, 30 Jan 2025 10:15:58 +0800 Subject: [PATCH 5/6] gh-124927: Fix conversion issue between coordinates and position in REPL --- Lib/_pyrepl/reader.py | 4 ++-- Lib/test/test_pyrepl/test_reader.py | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py index 5a144dc6b5f8f4..6d1ae7d5f91e45 100644 --- a/Lib/_pyrepl/reader.py +++ b/Lib/_pyrepl/reader.py @@ -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.append(len(c) - 1) + b.append(len(c)) else: s.append(c) b.append(str_width(c)) @@ -577,7 +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 + j += 1 # prevent infinite loop continue cur_x += self.screeninfo[i][1][j] j += 1 diff --git a/Lib/test/test_pyrepl/test_reader.py b/Lib/test/test_pyrepl/test_reader.py index 04bca9afe7f82d..468c0c5e68d165 100644 --- a/Lib/test/test_pyrepl/test_reader.py +++ b/Lib/test/test_pyrepl/test_reader.py @@ -313,18 +313,17 @@ def test_key_press_on_tab_press_once(self): self.assert_screen_equals(reader, f"{code}a") + def test_pos2xy_with_no_columns(self): + console = prepare_console([]) + reader = prepare_reader(console) + # Simulate a resize to 0 columns + reader.screeninfo = [] + 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) - - def test_pos2xy_with_no_columns(self): - console = prepare_console([]) - reader = prepare_reader(console) - # Simulate a resize to 0 columns - reader.screeninfo = [] - self.assertEqual(reader.pos2xy(), (0, 0)) From 233c798954dee780551c102b9e87a2e2b7e9b71c Mon Sep 17 00:00:00 2001 From: Zhikai Cai Date: Sat, 15 Feb 2025 16:20:57 +0800 Subject: [PATCH 6/6] gh-124927: Fix conversion issue between coordinates and position in REPL --- Lib/_pyrepl/reader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py index 6d1ae7d5f91e45..4795c51296a500 100644 --- a/Lib/_pyrepl/reader.py +++ b/Lib/_pyrepl/reader.py @@ -577,7 +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 # prevent infinite loop + j += 1 # prevent potential future infinite loop continue cur_x += self.screeninfo[i][1][j] j += 1