@@ -832,15 +832,31 @@ def get_session_formatted_for_file(self):
832832 i.e. without >>> and ... at input lines and with "# OUT: " prepended to
833833 output lines and "### " prepended to current line"""
834834
835- def process ():
836- for line , lineType in self .all_logical_lines :
837- if lineType == LineTypeTranslator .INPUT :
838- yield line
839- elif line .rstrip ():
840- yield "# OUT: %s" % line
841- yield "### %s" % self .current_line
842-
843- return "\n " .join (process ())
835+ if hasattr (self , 'all_logical_lines' ):
836+ # Curtsies
837+
838+ def process ():
839+ for line , lineType in self .all_logical_lines :
840+ if lineType == LineTypeTranslator .INPUT :
841+ yield line
842+ elif line .rstrip ():
843+ yield "# OUT: %s" % line
844+ yield "### %s" % self .current_line
845+
846+ return "\n " .join (process ())
847+
848+ else : # cli and Urwid
849+ session_output = self .getstdout ()
850+
851+ def process ():
852+ for line in session_output .split ("\n " ):
853+ if line .startswith (self .ps1 ):
854+ yield line [len (self .ps1 ) :]
855+ elif line .startswith (self .ps2 ):
856+ yield line [len (self .ps2 ) :]
857+ elif line .rstrip ():
858+ yield "# OUT: %s" % (line ,)
859+ return '\n ' .join (process ())
844860
845861 def write2file (self ):
846862 """Prompt for a filename and write the current contents of the stdout
@@ -952,6 +968,7 @@ def do_pastebin(self, s):
952968 def push (self , s , insert_into_history = True ):
953969 """Push a line of code onto the buffer so it can process it all
954970 at once when a code block ends"""
971+ # This push method is used by cli and urwid, but not curtsies
955972 s = s .rstrip ("\n " )
956973 self .buffer .append (s )
957974
0 commit comments