Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 5 additions & 1 deletion Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,16 @@ def calc_screen(self) -> list[str]:
else:
pre = prompt
prelen = prompt_len
for wrap in range(wrapcount + 1):
while True:
index_to_wrap_before = 0
column = 0
for char_width in char_widths:
if column + char_width + prelen >= self.console.width:
break
index_to_wrap_before += 1
column += char_width
if index_to_wrap_before == 0 and not prelen:
index_to_wrap_before = 1 # force progress
if len(chars) > index_to_wrap_before:
offset += index_to_wrap_before
post = "\\"
Expand All @@ -378,6 +380,8 @@ def calc_screen(self) -> list[str]:
char_widths = char_widths[index_to_wrap_before:]
pre = ""
prelen = 0
if not post:
break
self.screeninfo = screeninfo
self.cxy = self.pos2xy()
if self.msg:
Expand Down
5 changes: 5 additions & 0 deletions Lib/test/test_pyrepl/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def test_calc_screen_wrap_three_lines(self):
reader, _ = handle_events_narrow_console(events)
self.assert_screen_equal(reader, f"{9*"a"}\\\n{9*"a"}\\\naa")

def test_calc_screen_wrap_three_lines_last_char(self):
events = code_to_events(19 * "a")
reader, _ = handle_events_narrow_console(events)
self.assert_screen_equal(reader, f"{9*"a"}\\\n{9*"a"}\\\na")

def test_calc_screen_prompt_handling(self):
def prepare_reader_keep_prompts(*args, **kwargs):
reader = prepare_reader(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix the :term:`REPL` dropping the last characters of a long line that wraps
across several rows, which could raise :exc:`IndexError` when moving the
cursor with the arrow keys.
Loading