Mercurial > python-cmd2
comparison cmd2.py @ 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 |
comparison
equal
deleted
inserted
replaced
76:dcd5d13e5603 | 77:bb44928c3856 |
---|---|
146 shortcut = app.shortcuts.get(s[0]) | 146 shortcut = app.shortcuts.get(s[0]) |
147 if shortcut and hasattr(app, 'do_%s' % shortcut): | 147 if shortcut and hasattr(app, 'do_%s' % shortcut): |
148 s = '%s %s' % (shortcut, s[1:]) | 148 s = '%s %s' % (shortcut, s[1:]) |
149 self.searchable = self.asEntered = s | 149 self.searchable = self.asEntered = s |
150 self.app = app | 150 self.app = app |
151 self.terminator_pattern = self.punctuationPattern(self.app.terminators) | |
151 self.output_destination_pattern = self.punctuationPattern(['>>', '>']) | 152 self.output_destination_pattern = self.punctuationPattern(['>>', '>']) |
152 self.input_source_pattern = self.punctuationPattern(['<']) | 153 self.input_source_pattern = self.punctuationPattern(['<']) |
153 self.pipe_destination_pattern = self.punctuationPattern(['|']) | 154 self.pipe_destination_pattern = self.punctuationPattern(['|']) |
154 def punctuationPattern(self, punctuators): | 155 def punctuationPattern(self, punctuators): |
155 processed = punctuators[:] | 156 processed = punctuators[:] |
159 processed.ignore(pyparsing.sglQuotedString) | 160 processed.ignore(pyparsing.sglQuotedString) |
160 processed.ignore(pyparsing.dblQuotedString) | 161 processed.ignore(pyparsing.dblQuotedString) |
161 pattern = pyparsing.SkipTo(processed) + processed + pyparsing.restOfLine | 162 pattern = pyparsing.SkipTo(processed) + processed + pyparsing.restOfLine |
162 return pattern | 163 return pattern |
163 def parse(self): | 164 def parse(self): |
165 termination = self.terminator_pattern.searchString(self.asEntered) | |
166 if termination: | |
167 self.terminator = termination[0][1] | |
168 if len(termination[0]) > 3: | |
169 self.terminator_suffix = termination[0][2] | |
164 punctuators = ['|','>','>>','<'] | 170 punctuators = ['|','>','>>','<'] |
165 punctuators.extend(self.app.terminators) | 171 punctuators.extend(self.app.terminators) |
166 punctuated = self.punctuationPattern(punctuators).searchString(self.asEntered) | 172 punctuated = self.punctuationPattern(punctuators).searchString(self.asEntered) |
167 if punctuated: | 173 if punctuated: |
168 self.executable, self.searchable = punctuated[0][0], self.asEntered[len(punctuated[0][0]):] | 174 self.executable, self.searchable = punctuated[0][0], self.asEntered[len(punctuated[0][0]):] |
174 self.arg = Arguments(self.arg, self) | 180 self.arg = Arguments(self.arg, self) |
175 except pyparsing.ParseException: | 181 except pyparsing.ParseException: |
176 self.cmd, self.arg = None, None | 182 self.cmd, self.arg = None, None |
177 | 183 |
178 def complete(self): | 184 def complete(self): |
179 terminator_finder = self.punctuationPattern(self.app.terminators) | 185 while not self.terminator_pattern.searchString(self.asEntered): |
180 result = terminator_finder.searchString(self.asEntered) | |
181 while not result: | |
182 inp = self.app.pseudo_raw_input(self.app.continuationPrompt) | 186 inp = self.app.pseudo_raw_input(self.app.continuationPrompt) |
183 self.asEntered = '%s\n%s' % (self.asEntered, inp) | 187 self.asEntered = '%s\n%s' % (self.asEntered, inp) |
184 result = terminator_finder.searchString(self.asEntered) | |
185 self.terminator = result[0][1] | |
186 if len(result[0]) > 3: | |
187 self.terminator_suffix = result[0][2] | |
188 else: | |
189 self.terminator_suffix = None | |
190 def redirectedInput(self): | 188 def redirectedInput(self): |
191 inputFrom = self.input_source_pattern.searchString(self.searchable) | 189 inputFrom = self.input_source_pattern.searchString(self.searchable) |
192 if inputFrom: | 190 if inputFrom: |
193 if inputFrom[0][-1].strip(): | 191 if inputFrom[0][-1].strip(): |
194 input = self.app.fileimport(source=inputFrom[0][-1].strip()) | 192 input = self.app.fileimport(source=inputFrom[0][-1].strip()) |