# HG changeset patch # User devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil # Date 1198269077 18000 # Node ID ebefe2d57e3bedf12f3e2f23eef366c7651d252c # Parent 5e2f6ec2e383d7ea12f5a89f505143c14861877d multiline stops after line 2 diff -r 5e2f6ec2e383 -r ebefe2d57e3b cmd2.py --- a/cmd2.py Fri Dec 21 15:06:13 2007 -0500 +++ b/cmd2.py Fri Dec 21 15:31:17 2007 -0500 @@ -94,9 +94,52 @@ if not len(line): line = 'EOF' else: - line = line[:-1] # chop \n + if line[-1] == '\n': # this was always true in Cmd + line = line[:-1] return line - + + def cmdloop(self, intro=None): + """Repeatedly issue a prompt, accept input, parse an initial prefix + off the received input, and dispatch to action methods, passing them + the remainder of the line as argument. + """ + + # An almost perfect copy from Cmd; however, the pseudo_raw_input portion + # has been split out so that it can be called separately + + self.preloop() + if self.use_rawinput and self.completekey: + try: + import readline + self.old_completer = readline.get_completer() + readline.set_completer(self.complete) + readline.parse_and_bind(self.completekey+": complete") + except ImportError: + pass + try: + if intro is not None: + self.intro = intro + if self.intro: + self.stdout.write(str(self.intro)+"\n") + stop = None + while not stop: + if self.cmdqueue: + line = self.cmdqueue.pop(0) + else: + line = self.pseudo_raw_input(self.prompt) + line = self.precmd(line) + stop = self.onecmd(line) + stop = self.postcmd(stop, line) + self.postloop() + finally: + if self.use_rawinput and self.completekey: + try: + import readline + readline.set_completer(self.old_completer) + except ImportError: + pass + + def do_EOF(self, arg): return True do_eof = do_EOF