@@ -321,7 +321,10 @@ def on_enter(self, insert_into_history=True):
321321 self .rl_history .append (self ._current_line )
322322 self .rl_history .last ()
323323 self .history .append (self ._current_line )
324- self .push (self ._current_line , insert_into_history = insert_into_history )
324+ line = self ._current_line
325+ self ._current_line = ''
326+ self .cursor_offset_in_line = 0
327+ self .push (line , insert_into_history = insert_into_history )
325328
326329 def send_to_stdout (self , output ):
327330 lines = output .split ('\n ' )
@@ -438,7 +441,7 @@ def push(self, line, insert_into_history=True):
438441
439442 if line .endswith (':' ):
440443 indent = max (0 , indent + self .config .tab_length )
441- elif line and line .count (' ' ) == len (self . _current_line ):
444+ elif line and line .count (' ' ) == len (line ):
442445 indent = max (0 , indent - self .config .tab_length )
443446 elif line and ':' not in line and line .strip ().startswith (('return' , 'pass' , 'raise' , 'yield' )):
444447 indent = max (0 , indent - self .config .tab_length )
@@ -578,7 +581,7 @@ def display_line_with_prompt(self):
578581 @property
579582 def current_cursor_line (self ):
580583 value = (self .current_output_line +
581- '' if self .coderunner .running else self .display_line_with_prompt )
584+ ( '' if self .coderunner .running else self .display_line_with_prompt ) )
582585 logging .debug ('current cursor line: %r' , value )
583586 return value
584587
@@ -648,11 +651,12 @@ def paint(self, about_to_exit=False):
648651 lines = paint .display_linize (self .current_cursor_line + 'X' , width )
649652 # extra character for space for the cursor
650653 cursor_row = current_line_start_row + len (lines ) - 1
651- if self .stdin .has_focus or self .current_stdouterr_line : #self.stdin.has_focus:
652- cursor_column = len (self .current_stdouterr_line ) + self .stdin .cursor_offset_in_line
654+ if self .stdin .has_focus :
655+ cursor_column = len (self .current_stdouterr_line ) - self .stdin .cursor_offset_in_line
656+ assert cursor_column >= 0 , cursor_column
653657 else :
654658 cursor_column = len (self .current_cursor_line ) - len (self ._current_line ) + self .cursor_offset_in_line
655- assert cursor_column >= 0 , cursor_column
659+ assert cursor_column >= 0 , ( cursor_column , len ( self . current_cursor_line ), len ( self . _current_line ), self . cursor_offset_in_line )
656660
657661 if self .list_win_visible :
658662 #infobox not properly expanding window! try reduce( docs about halfway down a 80x24 terminal
0 commit comments