@@ -832,15 +832,31 @@ def get_session_formatted_for_file(self):
832
832
i.e. without >>> and ... at input lines and with "# OUT: " prepended to
833
833
output lines and "### " prepended to current line"""
834
834
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 ())
844
860
845
861
def write2file (self ):
846
862
"""Prompt for a filename and write the current contents of the stdout
@@ -952,6 +968,7 @@ def do_pastebin(self, s):
952
968
def push (self , s , insert_into_history = True ):
953
969
"""Push a line of code onto the buffer so it can process it all
954
970
at once when a code block ends"""
971
+ # This push method is used by cli and urwid, but not curtsies
955
972
s = s .rstrip ("\n " )
956
973
self .buffer .append (s )
957
974
0 commit comments