mirror of
https://github.com/kennethreitz-archive/bpython-gist.git
synced 2026-06-05 23:50:18 +00:00
Save format changed to be executable code
Save to file now outputs executable code (i.e. without the >>> and ... and with "# OUT: " prepended to all output lines). I never used this feature much but someone asked for this behaviour.
This commit is contained in:
+14
-1
@@ -688,6 +688,19 @@ class Repl(object):
|
||||
|
||||
return self.stdout_hist + '\n'
|
||||
|
||||
def formatforfile(self, s):
|
||||
"""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."""
|
||||
|
||||
def process():
|
||||
for line in s.split('\n'):
|
||||
if line.startswith('>>>') or line.startswith('...'):
|
||||
yield line[4:]
|
||||
elif line.rstrip():
|
||||
yield "# OUT: %s" % (line,)
|
||||
return "\n".join(process())
|
||||
|
||||
def write2file(self):
|
||||
"""Prompt for a filename and write the current contents of the stdout
|
||||
buffer to disk."""
|
||||
@@ -697,7 +710,7 @@ class Repl(object):
|
||||
if fn.startswith('~'):
|
||||
fn = os.path.expanduser(fn)
|
||||
|
||||
s = self.getstdout()
|
||||
s = self.formatforfile(self.getstdout())
|
||||
|
||||
try:
|
||||
f = open(fn, 'w')
|
||||
|
||||
Reference in New Issue
Block a user