changeset 77:bb44928c3856

migrating to onecmd from select
author catherine@Elli.myhome.westell.com
date Sat, 28 Jun 2008 11:10:01 -0400
parents dcd5d13e5603
children 94d89298a8ef
files cmd2.py
diffstat 1 files changed, 7 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Sat Jun 28 10:31:12 2008 -0400
+++ b/cmd2.py	Sat Jun 28 11:10:01 2008 -0400
@@ -148,6 +148,7 @@
             s = '%s %s' % (shortcut, s[1:])
         self.searchable = self.asEntered = s
         self.app = app
+        self.terminator_pattern = self.punctuationPattern(self.app.terminators)
         self.output_destination_pattern = self.punctuationPattern(['>>', '>'])
         self.input_source_pattern = self.punctuationPattern(['<'])
         self.pipe_destination_pattern = self.punctuationPattern(['|'])
@@ -161,6 +162,11 @@
         pattern = pyparsing.SkipTo(processed) + processed + pyparsing.restOfLine
         return pattern
     def parse(self):
+        termination = self.terminator_pattern.searchString(self.asEntered)
+        if termination:
+            self.terminator = termination[0][1]
+            if len(termination[0]) > 3:
+                self.terminator_suffix = termination[0][2]        
         punctuators = ['|','>','>>','<']
         punctuators.extend(self.app.terminators)          
         punctuated = self.punctuationPattern(punctuators).searchString(self.asEntered)
@@ -176,17 +182,9 @@
             self.cmd, self.arg = None, None         
             
     def complete(self):
-        terminator_finder = self.punctuationPattern(self.app.terminators)
-        result = terminator_finder.searchString(self.asEntered)
-        while not result:
+        while not self.terminator_pattern.searchString(self.asEntered):
             inp = self.app.pseudo_raw_input(self.app.continuationPrompt)
             self.asEntered = '%s\n%s' % (self.asEntered, inp)
-            result = terminator_finder.searchString(self.asEntered)
-        self.terminator = result[0][1]
-        if len(result[0]) > 3:
-            self.terminator_suffix = result[0][2]
-        else:
-            self.terminator_suffix = None
     def redirectedInput(self):
         inputFrom = self.input_source_pattern.searchString(self.searchable)
         if inputFrom: