changeset 32:ebefe2d57e3b

multiline stops after line 2
author devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil
date Fri, 21 Dec 2007 15:31:17 -0500
parents 5e2f6ec2e383
children 061f40299ed5
files cmd2.py
diffstat 1 files changed, 45 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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