File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed 
Misc/NEWS.d/next/Core_and_Builtins Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -345,7 +345,10 @@ def calc_screen(self) -> list[str]:
345345        pos  =  self .pos 
346346        pos  -=  offset 
347347
348+         prompt_from_cache  =  (offset  and  self .buffer [offset  -  1 ] !=  "\n " )
349+ 
348350        lines  =  "" .join (self .buffer [offset :]).split ("\n " )
351+ 
349352        cursor_found  =  False 
350353        lines_beyond_cursor  =  0 
351354        for  ln , line  in  enumerate (lines , num_common_lines ):
@@ -359,7 +362,12 @@ def calc_screen(self) -> list[str]:
359362                    # No need to keep formatting lines. 
360363                    # The console can't show them. 
361364                    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 )
363371            while  "\n "  in  prompt :
364372                pre_prompt , _ , prompt  =  prompt .partition ("\n " )
365373                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):
3030        reader , _  =  handle_events_narrow_console (events )
3131        self .assert_screen_equals (reader , f"{ 9 * "a" } \\ \n { 9 * "a" } \\ \n aa" )
3232
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:\n some_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+ 
3364    def  test_calc_screen_wrap_three_lines_mixed_character (self ):
3465        # fmt: off 
3566        code  =  (
Original file line number Diff line number Diff line change 1+ Fix a bug causing stray prompts to appear in the middle of wrapped lines in
2+ the new REPL.
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments