@@ -457,22 +457,30 @@ def __init__(self, event_loop, palette, interpreter, config):
457457
458458 self .edits = []
459459 self .edit = None
460+ self .current_output = None
460461 self ._completion_update_suppressed = False
461462
462463 load_urwid_command_map (config )
463464
464465 # Subclasses of Repl need to implement echo, current_line, cw
465- def echo (self , s ):
466- s = s .rstrip ('\n ' )
466+ def echo (self , orig_s ):
467+ s = orig_s .rstrip ('\n ' )
467468 if s :
468- text = urwid .Text (('output' , s ))
469- if self .edit is None :
470- self .listbox .body .append (text )
469+ if self .current_output is None :
470+ self .current_output = urwid .Text (('output' , s ))
471+ if self .edit is None :
472+ self .listbox .body .append (self .current_output )
473+ else :
474+ self .listbox .body .insert (- 1 , self .current_output )
475+ # The edit widget should be focused and *stay* focused.
476+ # XXX TODO: make sure the cursor stays in the same spot.
477+ self .listbox .set_focus (len (self .listbox .body ) - 1 )
471478 else :
472- self .listbox .body .insert (- 1 , text )
473- # The edit widget should be focused and *stay* focused.
474- # XXX TODO: make sure the cursor stays in the same spot.
475- self .listbox .set_focus (len (self .listbox .body ) - 1 )
479+ # XXX this assumes this all has "output" markup applied.
480+ self .current_output .set_text (
481+ ('output' , self .current_output .text + s ))
482+ if orig_s .endswith ('\n ' ):
483+ self .current_output = None
476484 # TODO: maybe do the redraw after a short delay
477485 # (for performance)
478486 self .main_loop .draw_screen ()
@@ -728,6 +736,10 @@ def keyboard_interrupt(self):
728736 self .echo ('KeyboardInterrupt' )
729737
730738 def prompt (self , more ):
739+ # Clear current output here, or output resulting from the
740+ # current prompt run will end up appended to the edit widget
741+ # sitting above this prompt:
742+ self .current_output = None
731743 # XXX is this the right place?
732744 self .rl_history .reset ()
733745 # XXX what is s_hist?
0 commit comments