| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 70bfef5 commit 602fcf9
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -345,7 +345,10 @@ def calc_screen(self) -> list[str]: | |||
| 345 | 345 | pos = self.pos | |
| 346 | 346 | pos -= offset | |
| 347 | 347 | ||
| 348 | + prompt_from_cache = (offset and self.buffer[offset - 1] != "\n") | ||
| 349 | + | ||
| 348 | 350 | lines = "".join(self.buffer[offset:]).split("\n") | |
| 351 | + | ||
| 349 | 352 | cursor_found = False | |
| 350 | 353 | lines_beyond_cursor = 0 | |
| 351 | 354 | for ln, line in enumerate(lines, num_common_lines): | |
@@ -359,7 +362,12 @@ def calc_screen(self) -> list[str]: | |||
| 359 | 362 | # No need to keep formatting lines. | |
| 360 | 363 | # The console can't show them. | |
| 361 | 364 | break | |
| 362 | - prompt = self.get_prompt(ln, ll >= pos >= 0) | ||
| 365 | + if prompt_from_cache: | ||
| 366 | + # Only the first line's prompt can come from the cache | ||
| 367 | + prompt_from_cache = False | ||
| 368 | + prompt = "" | ||
| 369 | + else: | ||
| 370 | + prompt = self.get_prompt(ln, ll >= pos >= 0) | ||
| 363 | 371 | while "\n" in prompt: | |
| 364 | 372 | pre_prompt, _, prompt = prompt.partition("\n") | |
| 365 | 373 | last_refresh_line_end_offsets.append(offset) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,6 +30,37 @@ def test_calc_screen_wrap_three_lines(self): | |||
| 30 | 30 | reader, _ = handle_events_narrow_console(events) | |
| 31 | 31 | self.assert_screen_equals(reader, f"{9*"a"}\\\n{9*"a"}\\\naa") | |
| 32 | 32 | ||
| 33 | + def test_calc_screen_prompt_handling(self): | ||
| 34 | + def prepare_reader_keep_prompts(*args, **kwargs): | ||
| 35 | + reader = prepare_reader(*args, **kwargs) | ||
| 36 | + del reader.get_prompt | ||
| 37 | + reader.ps1 = ">>> " | ||
| 38 | + reader.ps2 = ">>> " | ||
| 39 | + reader.ps3 = "... " | ||
| 40 | + reader.ps4 = "" | ||
| 41 | + reader.can_colorize = False | ||
| 42 | + reader.paste_mode = False | ||
| 43 | + return reader | ||
| 44 | + | ||
| 45 | + events = code_to_events("if some_condition:\nsome_function()") | ||
| 46 | + reader, _ = handle_events_narrow_console( | ||
| 47 | + events, | ||
| 48 | + prepare_reader=prepare_reader_keep_prompts, | ||
| 49 | + ) | ||
| 50 | + # fmt: off | ||
| 51 | + self.assert_screen_equals( | ||
| 52 | + reader, | ||
| 53 | + ( | ||
| 54 | + ">>> if so\\\n" | ||
| 55 | + "me_condit\\\n" | ||
| 56 | + "ion:\n" | ||
| 57 | + "... s\\\n" | ||
| 58 | + "ome_funct\\\n" | ||
| 59 | + "ion()" | ||
| 60 | + ) | ||
| 61 | + ) | ||
| 62 | + # fmt: on | ||
| 63 | + | ||
| 33 | 64 | def test_calc_screen_wrap_three_lines_mixed_character(self): | |
| 34 | 65 | # fmt: off | |
| 35 | 66 | code = ( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fix a bug causing stray prompts to appear in the middle of wrapped lines in | ||
| 2 | + the new REPL. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments