Format the stdout buffer to something suitable for writing to disk, i.e. without >>> and ... at input lines and with "# OUT: " prepended to output lines and "### " prepended to current line
(self)
| 866 | raise NotImplementedError() |
| 867 | |
| 868 | def get_session_formatted_for_file(self) -> str: |
| 869 | """Format the stdout buffer to something suitable for writing to disk, |
| 870 | i.e. without >>> and ... at input lines and with "# OUT: " prepended to |
| 871 | output lines and "### " prepended to current line""" |
| 872 | |
| 873 | session_output = self.getstdout() |
| 874 | |
| 875 | def process(): |
| 876 | for line in session_output.split("\n"): |
| 877 | if line.startswith(self.ps1): |
| 878 | yield line[len(self.ps1) :] |
| 879 | elif line.startswith(self.ps2): |
| 880 | yield line[len(self.ps2) :] |
| 881 | elif line.rstrip(): |
| 882 | yield f"# OUT: {line}" |
| 883 | |
| 884 | return "\n".join(process()) |
| 885 | |
| 886 | def write2file(self) -> None: |
| 887 | """Prompt for a filename and write the current contents of the stdout |
no test coverage detected