Mercurial > python-cmd2
comparison cmd2.py @ 69:824651b4d1b1
slash-endings working
author | catherine@Elli.myhome.westell.com |
---|---|
date | Mon, 23 Jun 2008 22:01:57 -0400 |
parents | e06961ebd035 |
children | 48b0bf2e3d2e |
comparison
equal
deleted
inserted
replaced
68:e06961ebd035 | 69:824651b4d1b1 |
---|---|
126 else: | 126 else: |
127 def getPasteBuffer(): | 127 def getPasteBuffer(): |
128 raise OSError, pastebufferr % ('xclip', 'On Debian/Ubuntu, install with "sudo apt-get install xclip"') | 128 raise OSError, pastebufferr % ('xclip', 'On Debian/Ubuntu, install with "sudo apt-get install xclip"') |
129 setPasteBuffer = getPasteBuffer | 129 setPasteBuffer = getPasteBuffer |
130 | 130 |
131 pyparsing.ParserElement.setDefaultWhitespaceChars(' \t') # see http://pyparsing.wikispaces.com/message/view/home/1352689 | |
131 def punctuationParser(punctuators): | 132 def punctuationParser(punctuators): |
132 """ | 133 """ |
133 Produces a string parser based on a list of targets to search for. | 134 Produces a string parser based on a list of targets to search for. |
134 Output is a parser function. | 135 Output is a parser function. |
135 Parser's output is a tuple: (before the target, [elements of the target], after the target) | 136 Parser's output is a tuple: (before the target, [elements of the target], after the target) |
136 >>> p = punctuationParser([';', 'EOF']) | 137 >>> p = punctuationParser([';', 'EOF']) |
137 >>> p('is terminated;') | 138 >>> p('is terminated;') |
138 ('is terminated', [';'], '') | 139 ('is terminated', [';'], '') |
139 >>> p('is terminated EOF after the end') | 140 >>> p('is terminated EOF after the end') |
140 ('is terminated', ['EOF'], ' after the end') | 141 ('is terminated', ['EOF'], 'after the end') |
141 >>> p('is not terminated') | 142 >>> p('is not terminated') |
142 >>> pattern1 = pyparsing.Literal(';') + pyparsing.Optional(pyparsing.Word(pyparsing.nums)) | 143 >>> pattern1 = pyparsing.Literal(';') + pyparsing.Optional(pyparsing.Word(pyparsing.nums)) |
143 >>> p2 = punctuationParser([pattern1, 'EOF']) | 144 >>> p2 = punctuationParser([pattern1, 'EOF']) |
144 >>> p2('the quick brown fox;4') | 145 >>> p2('the quick brown fox;4') |
145 ('the quick brown fox', [';', '4'], '') | 146 ('the quick brown fox', [';', '4'], '') |
162 return None | 163 return None |
163 return parser | 164 return parser |
164 | 165 |
165 class Cmd(cmd.Cmd): | 166 class Cmd(cmd.Cmd): |
166 caseInsensitive = True | 167 caseInsensitive = True |
167 terminators = [';','\n'] | 168 terminators = [';', pyparsing.LineEnd() + pyparsing.LineEnd()] |
168 multilineCommands = [] # commands that need a terminator to be finished | 169 multilineCommands = [] # commands that need a terminator to be finished |
169 terminatorKeepingCommands = [] # commands that expect to process their own terminators (else it will be stripped during parse) | 170 terminatorKeepingCommands = [] # commands that expect to process their own terminators (else it will be stripped during parse) |
170 continuationPrompt = '> ' | 171 continuationPrompt = '> ' |
171 shortcuts = {'?': 'help', '!': 'shell', '@': 'load'} | 172 shortcuts = {'?': 'help', '!': 'shell', '@': 'load'} |
172 excludeFromHistory = '''run r list l history hi ed edit li eof'''.split() | 173 excludeFromHistory = '''run r list l history hi ed edit li eof'''.split() |
188 self.stdout.write(""" | 189 self.stdout.write(""" |
189 Commands are %(casesensitive)scase-sensitive. | 190 Commands are %(casesensitive)scase-sensitive. |
190 Commands may be terminated with: %(terminators)s | 191 Commands may be terminated with: %(terminators)s |
191 Settable parameters: %(settable)s | 192 Settable parameters: %(settable)s |
192 """ % | 193 """ % |
193 { 'casesensitive': ('not ' and self.caseInsensitive) or '', | 194 { 'casesensitive': (self.caseInsensitive or '') and 'not ', |
194 'terminators': ' '.join(str(self.terminators)), | 195 'terminators': str(self.terminators), |
195 'settable': ' '.join(self.settable) | 196 'settable': ' '.join(self.settable) |
196 }) | 197 }) |
197 | 198 |
198 def do_help(self, arg): | 199 def do_help(self, arg): |
199 cmd.Cmd.do_help(self, arg) | 200 cmd.Cmd.do_help(self, arg) |