History file support added.

Defaults to ~/.pythonhist but can be configured in rc (see sample-rc)
This commit is contained in:
Bob Farrell
2008-08-25 18:40:11 +01:00
parent 0c220f93de
commit 9b9e15423b
3 changed files with 29 additions and 2 deletions
+5
View File
@@ -1,3 +1,8 @@
v0.7.1
======
Added support for a history file, defaults to ~/.pythonhist and 100 lines but
is configurable from the rc file (see sample-rc).
v0.7.0
======
C-d behaviour changed so it no longer exits if the current line isn't empty.
+14 -2
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# bpython 0.7.0::fancy curses interface to the Python repl::Bob Farrell 2008
# bpython 0.7.1::fancy curses interface to the Python repl::Bob Farrell 2008
#
# The MIT License
#
@@ -101,6 +101,8 @@ OPTS.tab_length = 4
OPTS.auto_display_list = True
OPTS.syntax = True
OPTS.arg_spec = True
OPTS.hist_file = '~/.pythonhist'
OPTS.hist_length = 100
# TODO:
#
@@ -246,6 +248,10 @@ class Repl( object ):
if not OPTS.arg_spec:
return
pythonhist = os.path.expanduser('~/.pythonhist')
if os.path.exists(pythonhist):
self.rl_hist = open(pythonhist, 'r').readlines()
pexp = Forward()
chars = printables.replace('(', '')
chars = chars.replace(')', '')
@@ -829,7 +835,8 @@ class Repl( object ):
self.s_hist[-1] += self.f_string
self.stdout_hist += inp + '\n'
# Keep two copies so you can go up and down in the hist:
self.rl_hist.append( inp )
if inp:
self.rl_hist.append( inp + '\n' )
more = self.push( inp )
def size( self ):
@@ -1566,6 +1573,11 @@ def main( scr ):
repl.repl()
if OPTS.hist_length:
f = open(os.path.expanduser('~/.pythonhist'), 'w')
f.writelines(repl.rl_hist[-OPTS.hist_length:])
f.close()
return repl.getstdout()
if __name__ == '__main__':
+10
View File
@@ -13,3 +13,13 @@ syntax = on
# Display the arg spec (list of arguments) for callables,
# when possible (default: on).
arg_spec = true
# History file:
hist_file = ~/.pythonhist
# Number of lines to store in history (set to 0 to disable):
hist_len = 100
# Soft tab size:
tab_length = 4