[pypy-svn] pypy default: update the inlined pyrepl to revision 4d9968d3e7da

antocuni commits-noreply at bitbucket.org
Thu Mar 31 18:25:55 CEST 2011


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r43059:ed0020d371de
Date: 2011-03-31 18:18 +0200
http://bitbucket.org/pypy/pypy/changeset/ed0020d371de/

Log:	update the inlined pyrepl to revision 4d9968d3e7da

diff --git a/lib_pypy/pyrepl/unix_console.py b/lib_pypy/pyrepl/unix_console.py
--- a/lib_pypy/pyrepl/unix_console.py
+++ b/lib_pypy/pyrepl/unix_console.py
@@ -292,6 +292,12 @@
                 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))

diff --git a/lib_pypy/pyrepl/reader.py b/lib_pypy/pyrepl/reader.py
--- a/lib_pypy/pyrepl/reader.py
+++ b/lib_pypy/pyrepl/reader.py
@@ -274,8 +274,12 @@
                         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 @@
                 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.


More information about the Pypy-commit mailing list