aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonio Cuni <anto.cuni@gmail.com>2011-03-31 18:18:37 +0200
committerAntonio Cuni <anto.cuni@gmail.com>2011-03-31 18:18:37 +0200
commitd0309f182a8f436285ecf522ef5728dd1818ed0b (patch)
tree4c18fbc19b01e02af7972ec76e10994396604607 /lib_pypy/pyrepl
parentmake sure not to run _setup twice, else we might get infinite recursion betwe... (diff)
downloadpypy-d0309f182a8f436285ecf522ef5728dd1818ed0b.tar.gz
pypy-d0309f182a8f436285ecf522ef5728dd1818ed0b.tar.bz2
pypy-d0309f182a8f436285ecf522ef5728dd1818ed0b.zip
update the inlined pyrepl to revision 4d9968d3e7da
Diffstat (limited to 'lib_pypy/pyrepl')
-rw-r--r--lib_pypy/pyrepl/reader.py31
-rw-r--r--lib_pypy/pyrepl/unix_console.py6
2 files changed, 36 insertions, 1 deletions
diff --git a/lib_pypy/pyrepl/reader.py b/lib_pypy/pyrepl/reader.py
index 653a6f1801..637cd38892 100644
--- a/lib_pypy/pyrepl/reader.py
+++ b/lib_pypy/pyrepl/reader.py
@@ -274,8 +274,12 @@ feeling more loquacious than I am now."""
screeninfo.append((0, []))
self.lxy = p, ln
prompt = self.get_prompt(ln, ll >= p >= 0)
+ while '\n' in prompt:
+ pre_prompt, _, prompt = prompt.partition('\n')
+ screen.append(pre_prompt)
+ screeninfo.append((0, []))
p -= ll + 1
- lp = len(prompt)
+ prompt, lp = self.process_prompt(prompt)
l, l2 = disp_str(line)
wrapcount = (len(l) + lp) / w
if wrapcount == 0:
@@ -297,6 +301,31 @@ feeling more loquacious than I am now."""
screeninfo.append((0, []))
return screen
+ 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
+ is returned with these control characters removed. """
+
+ out_prompt = ''
+ l = len(prompt)
+ pos = 0
+ while True:
+ s = prompt.find('\x01', pos)
+ if s == -1:
+ break
+ e = prompt.find('\x02', s)
+ if e == -1:
+ break
+ # Found start and end brackets, subtract from string length
+ l = l - (e-s+1)
+ out_prompt += prompt[pos:s] + prompt[s+1:e]
+ pos = e+1
+ out_prompt += prompt[pos:]
+ return out_prompt, l
+
def bow(self, p=None):
"""Return the 0-based index of the word break preceding p most
immediately.
diff --git a/lib_pypy/pyrepl/unix_console.py b/lib_pypy/pyrepl/unix_console.py
index 9d93fe8ad7..8bf4336da2 100644
--- a/lib_pypy/pyrepl/unix_console.py
+++ b/lib_pypy/pyrepl/unix_console.py
@@ -292,6 +292,12 @@ class UnixConsole(Console):
self.__write_code(self._el)
self.__write(newline[x:])
self.__posxy = len(newline), y
+
+ if '\x1b' in newline:
+ # ANSI escape characters are present, so we can't assume
+ # anything about the position of the cursor. Moving the cursor
+ # to the left margin should work to get to a known position.
+ self.move_cursor(0, y)
def __write(self, text):
self.__buffer.append((text, 0))