[pypy-commit] pyrepl default: (hpaulj) Fix startup_hook in readline to work like CPython. Fixes issue950
dripton
noreply at buildbot.pypy.org
Sat Apr 28 16:55:04 CEST 2012
Author: David Ripton <dripton at ripton.net>
Branch:
Changeset: r168:d92286eb65ec
Date: 2012-01-28 19:17 -0500
http://bitbucket.org/pypy/pyrepl/changeset/d92286eb65ec/
Log: (hpaulj) Fix startup_hook in readline to work like CPython. Fixes
issue950
diff --git a/pyrepl/reader.py b/pyrepl/reader.py
--- a/pyrepl/reader.py
+++ b/pyrepl/reader.py
@@ -37,16 +37,16 @@
for i in range(256):
c = unichr(i)
if not uc_map.has_key(c):
- uc_map[c] = u'\\%03o'%i
+ uc_map[c] = u'\\%03o'%i
return uc_map
# disp_str proved to be a bottleneck for large inputs, so it's been
# rewritten in C; it's not required though.
try:
raise ImportError # currently it's borked by the unicode support
-
+
from _pyrepl_utils import disp_str, init_unctrl_map
-
+
init_unctrl_map(_make_unctrl_map())
del init_unctrl_map
@@ -118,7 +118,7 @@
(r'\C-x\C-u', 'upcase-region'),
(r'\C-y', 'yank'),
(r'\C-z', 'suspend'),
-
+
(r'\M-b', 'backward-word'),
(r'\M-c', 'capitalize-word'),
(r'\M-d', 'kill-word'),
@@ -303,7 +303,7 @@
def process_prompt(self, prompt):
""" Process the prompt.
-
+
This means calculate the length of the prompt. The character \x01
and \x02 are used to bracket ANSI control sequences and need to be
excluded from the length calculation. So also a copy of the prompt
@@ -372,7 +372,7 @@
while p >= 0 and b[p] <> '\n':
p -= 1
return p + 1
-
+
def eol(self, p=None):
"""Return the 0-based index of the line break following p most
immediately.
@@ -463,7 +463,7 @@
"""This function is called to allow post command cleanup."""
if getattr(cmd, "kills_digit_arg", 1):
if self.arg is not None:
- self.dirty = 1
+ self.dirty = 1
self.arg = None
def prepare(self):
@@ -575,13 +575,15 @@
def push_char(self, char):
self.console.push_char(char)
self.handle1(0)
-
- def readline(self, returns_unicode=False):
+
+ def readline(self, returns_unicode=False, startup_hook=None):
"""Read a line. The implementation of this method also shows
how to drive Reader if you want more control over the event
loop."""
self.prepare()
try:
+ if startup_hook is not None:
+ startup_hook()
self.refresh()
while not self.finished:
self.handle1()
diff --git a/pyrepl/readline.py b/pyrepl/readline.py
--- a/pyrepl/readline.py
+++ b/pyrepl/readline.py
@@ -193,10 +193,8 @@
reader = self.get_reader()
except _error:
return _old_raw_input(prompt)
- if self.startup_hook is not None:
- self.startup_hook()
reader.ps1 = prompt
- return reader.readline()
+ return reader.readline(reader, startup_hook=self.startup_hook)
def multiline_input(self, more_lines, ps1, ps2, returns_unicode=False):
"""Read an input on possibly multiple lines, asking for more
@@ -390,7 +388,7 @@
global _old_raw_input
if _old_raw_input is not None:
return # don't run _setup twice
-
+
try:
f_in = sys.stdin.fileno()
f_out = sys.stdout.fileno()
More information about the pypy-commit
mailing list