Commits

Ronny Pfannschmidt committed 0199cc7

clean up escape matching in the input statemachine

Comments (0)

Files changed (2)

tests/test_input.py

     def press_keys(self, input):
         for press in split_input(input):
             result = self.keypress(press)
-            if result.next_tree is not None:
+            if result.next_tree or result.final:
                 yield result
 
 def test_split_input():
 
 def test_simple_dd():
     machine = CheckInputMachine(normal)
-    
 
     call = machine.keypress("d")
     assert call.call
     assert final.count == 2
     assert final.previous_actor is call
 
+
+def test_escape():
+    machine = CheckInputMachine(normal)
+    print list(machine.press_keys("d<Esc>"))
+    call, resetkeypress = machine.press_keys("d<Esc>")
         self.count = count
 
     def __repr__(self):
-        return "<Match %s>" %' '.join("%s=%r"%(x, getattr(self, x)) for x in self.__slots__ if x[0]!='_')
+        return "<Match %s>" %' '.join(
+                "%s=%r"%(x, getattr(self, x)) 
+                for x in self.__slots__ if x[0]!='_' and getattr(self, x) is not None)
 
     @property
     def previous_actor(self):
     def keypress(self, press):
         #XXX: this is ugly painfull shit
         if press == '<Esc>':
-            self.current = self.tree
-            self.input = ""
-            self.match = Match()
+            match = Match(reset=True, next_tree=self.tree)
         else:
             self.input += press
+            match = self.current.match(''.join(self.input), self.match)
 
-        match = self.current.match(''.join(self.input), self.match)
         self.match = match
         if match.next_tree is not None:
             self.current = match.next_tree
         if match.reset or match.final:
             self.current = self.tree
             self.input = ""
-            self.match = Match()
 
         return match