comparison cmd2.py @ 90:1cd189536e90

going to improve Save
author catherine@Elli.myhome.westell.com
date Wed, 03 Sep 2008 17:32:49 -0400
parents bd0adc37f3cc
children 88f2aa240af1
comparison
equal deleted inserted replaced
88:bd0adc37f3cc 90:1cd189536e90
192 """Lists single-key shortcuts available.""" 192 """Lists single-key shortcuts available."""
193 result = "\n".join('%s: %s' % (sc[0], sc[1]) for sc in self.shortcuts.items()) 193 result = "\n".join('%s: %s' % (sc[0], sc[1]) for sc in self.shortcuts.items())
194 self.stdout.write("Single-key shortcuts for other commands:\n%s\n" % (result)) 194 self.stdout.write("Single-key shortcuts for other commands:\n%s\n" % (result))
195 195
196 terminatorPattern = (pyparsing.Literal(';') ^ pyparsing.Literal('\n\n')) \ 196 terminatorPattern = (pyparsing.Literal(';') ^ pyparsing.Literal('\n\n')) \
197 ('terminator') 197 ^ (pyparsing.Literal('\nEOF') + pyparsing.lineEnd) ('terminator')
198 argSeparatorPattern = pyparsing.Word(pyparsing.printables)('command') \ 198 argSeparatorPattern = pyparsing.Word(pyparsing.printables)('command') \
199 + pyparsing.SkipTo(pyparsing.StringEnd())('args') 199 + pyparsing.SkipTo(pyparsing.StringEnd())('args')
200 filenamePattern = pyparsing.Word(pyparsing.alphanums + '#$-_~{},.!:\\/') 200 filenamePattern = pyparsing.Word(pyparsing.alphanums + '#$-_~{},.!:\\/')
201 integerPattern = pyparsing.Word(pyparsing.nums).setParseAction( lambda s,l,t: [ int(t[0]) ] ) 201 integerPattern = pyparsing.Word(pyparsing.nums).setParseAction( lambda s,l,t: [ int(t[0]) ] )
202 pipePattern = pyparsing.Literal('|')('pipe') + pyparsing.restOfLine('pipeTo') 202 pipePattern = pyparsing.Literal('|')('pipe') + pyparsing.restOfLine('pipeTo')
512 do_edit = do_ed 512 do_edit = do_ed
513 513
514 def do_save(self, fname=None): 514 def do_save(self, fname=None):
515 """Saves most recent command to a file.""" 515 """Saves most recent command to a file."""
516 516
517 if fname is None: 517 if not fname:
518 fname = self.defaultFileName 518 fname = self.defaultFileName
519 try: 519 try:
520 f = open(fname, 'w') 520 f = open(fname, 'w')
521 f.write(self.history[-1]) 521 f.write(self.history[-1])
522 f.close() 522 f.close()