[pypy-svn] r39677 - pypy/dist/pypy/module/readline
arigo at codespeak.net
arigo at codespeak.net
Fri Mar 2 14:54:33 CET 2007
Author: arigo
Date: Fri Mar 2 14:54:30 2007
New Revision: 39677
Modified:
pypy/dist/pypy/module/readline/c_readline.py
Log:
(hpk, arigo)
Add history to the pypy-c prompt.
Modified: pypy/dist/pypy/module/readline/c_readline.py
==============================================================================
--- pypy/dist/pypy/module/readline/c_readline.py (original)
+++ pypy/dist/pypy/module/readline/c_readline.py Fri Mar 2 14:54:30 2007
@@ -9,7 +9,7 @@
#
class CConfig:
_header_ = ""
- _includes_ = ["readline/readline.h"]
+ _includes_ = ["readline/readline.h", "readline/history.h"]
readline = Library('readline')
cconfig = configure(CConfig)
@@ -27,11 +27,27 @@
c_rl_initialize.argtypes = []
c_rl_initialize.restype = None
+# void using_history(void)
+c_using_history = libreadline.using_history
+c_using_history.argtypes = []
+c_using_history.restype = None
+
+# void add_history(const char *)
+c_add_history = libreadline.add_history
+c_add_history.argtypes = [c_char_p]
+c_add_history.restype = None
+
#------------------------------------------------------------
# special initialization of readline
+class ReadlineState(object):
+ lastline = "" # XXX possibly temporary hack
+readlinestate = ReadlineState()
+
def setup_readline(space, w_module):
+ c_using_history()
+ # XXX CPython initializes more stuff here
c_rl_initialize()
# install sys.__raw_input__, a hook that will be used by raw_input()
space.setitem(space.sys.w_dict, space.wrap('__raw_input__'),
@@ -41,6 +57,10 @@
res = c_readline(prompt)
if res is None:
raise OperationError(space.w_EOFError, space.w_None)
+ if res and res != readlinestate.lastline:
+ readlinestate.lastline = res
+ c_add_history(res)
return space.wrap(res)
+
readline_func.unwrap_spec = [ObjSpace, str]
app_readline_func = interp2app(readline_func)
More information about the pypy-svn
mailing list