Commits

kenko  committed cc28a4a

better readline support

  • Participants
  • Parent commits 641d644

Comments (0)

Files changed (2)

File pyline/colors.py

     effectize = __getitem__
     __format__ = __getitem__
     def __str__(self):
-        return ''.join(e.code for e in self.effects)
+        return  ''.join(e.code for e in self.effects)
 
 class Effect(EffectBase):
     def __init__(self, code, *names):
         return clear.effectize(self.code + text)
     __format__ = __getitem__
     def effectize(self, text):
-        return self.code + text
+        return '\001' + self.code + '\002' + text
     def __str__(self):
         return self.code
 

File pyline/pyline.py

 
     def say(self, s, *vals, **keys):
         s = str(s)
+        self.last_said = []
         if not s: return
         s = self.effectize_string(s, vals, keys)
         s, ws = utils.remove_capture_whitespace(s)
         lines = s.split('\n')
         lines = ['\n'.join(textwrap.wrap(s, self.wrap_at)) for s in lines]
         remaining = self.page(lines)
+        self.last_said.extend(remaining)
+        self.last_said[-1] += ws
         remaining = '\n'.join(remaining)+ws
         self.out.write(remaining)
-        if remaining[-1] not in '\t ':
+        if remaining[-1] not in '\t ':            
             self.out.write('\n')
         self.out.flush()
 
         self._say_question(q)
         return self._answer_question(q)
 
-    def _say_question(self, q):
+    def _say_question(self, q):            
         self.say(str(q))
         
     def _prep_question(self, question, prompt, answer, **k):
                 if cands and not get_completer():
                     set_here = True
                     set_completer(map(str,cands))
-            line = raw_input()
+            readline.rl_already_prompted = 1
+            self.out.write(utils.effectize_string("\r{0.erase_line}"))
+            line = raw_input(self.last_said[-1])
             if set_here:
                 clear_completer()
             return line
         # the what if lines is a multiple of page_at?
         size = len(lines)
         page_at = self.page_at
-        while size > page_at:
+        while size > page_at:            
             self.out.write('\n'.join(lines[:page_at]))
+            self.last_said.extend(lines[:page_at])
             lines = lines[page_at:]
             size -= page_at
             self.out.write('\n')