mirror of
https://github.com/kennethreitz-archive/bpython-gist.git
synced 2026-06-05 15:40:17 +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:
@@ -19,6 +19,10 @@ encoding.
|
||||
Bohdan Vlasyuk sent me a patch that fixes a problem with the above patch from
|
||||
Mark if sys.__stdout__.encoding didn't exist.
|
||||
|
||||
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.
|
||||
|
||||
v0.7.1
|
||||
======
|
||||
Added support for a history file, defaults to ~/.pythonhist and 100 lines but
|
||||
|
||||
+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