pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/pull/123324/files

="https://github.githubassets.com/assets/primer-primitives-10bf9dd67e3d70bd.css" /> gh-123177: Fix prompt for wrapped lines in pyrepl by godlygeek · Pull Request #123324 · python/cpython · GitHub
Skip to content
Merged
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
10 changes: 9 additions & 1 deletion Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ def calc_screen(self) -> list[str]:
pos = self.pos
pos -= offset

prompt_from_cache = (offset and self.buffer[offset - 1] != "\n")

lines = "".join(self.buffer[offset:]).split("\n")

cursor_found = False
lines_beyond_cursor = 0
for ln, line in enumerate(lines, num_common_lines):
Expand All @@ -359,7 +362,12 @@ def calc_screen(self) -> list[str]:
# No need to keep formatting lines.
# The console can't show them.
break
prompt = self.get_prompt(ln, ll >= pos >= 0)
if prompt_from_cache:
# Only the first line's prompt can come from the cache
prompt_from_cache = False
prompt = ""
else:
prompt = self.get_prompt(ln, ll >= pos >= 0)
while "\n" in prompt:
pre_prompt, _, prompt = prompt.partition("\n")
last_refresh_line_end_offsets.append(offset)
Expand Down
31 changes: 31 additions & 0 deletions Lib/test/test_pyrepl/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,37 @@ def test_calc_screen_wrap_three_lines(self):
reader, _ = handle_events_narrow_console(events)
self.assert_screen_equals(reader, f"{9*"a"}\\\n{9*"a"}\\\naa")

def test_calc_screen_prompt_handling(self):
def prepare_reader_keep_prompts(*args, **kwargs):
reader = prepare_reader(*args, **kwargs)
del reader.get_prompt
reader.ps1 = ">>> "
reader.ps2 = ">>> "
reader.ps3 = "... "
reader.ps4 = ""
reader.can_colorize = False
reader.paste_mode = False
return reader

events = code_to_events("if some_condition:\nsome_function()")
reader, _ = handle_events_narrow_console(
events,
prepare_reader=prepare_reader_keep_prompts,
)
# fmt: off
self.assert_screen_equals(
reader,
(
">>> if so\\\n"
"me_condit\\\n"
"ion:\n"
"... s\\\n"
"ome_funct\\\n"
"ion()"
)
)
# fmt: on

def test_calc_screen_wrap_three_lines_mixed_character(self):
# fmt: off
code = (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a bug causing stray prompts to appear in the middle of wrapped lines in
the new REPL.
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy