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.
(self, intro=None)
| 96 | self.completekey = completekey |
| 97 | |
| 98 | def cmdloop(self, intro=None): |
| 99 | """Repeatedly issue a prompt, accept input, parse an initial prefix |
| 100 | off the received input, and dispatch to action methods, passing them |
| 101 | the remainder of the line as argument. |
| 102 | |
| 103 | """ |
| 104 | |
| 105 | self.preloop() |
| 106 | if self.use_rawinput and self.completekey: |
| 107 | try: |
| 108 | import readline |
| 109 | self.old_completer = readline.get_completer() |
| 110 | readline.set_completer(self.complete) |
| 111 | readline.parse_and_bind(self.completekey+": complete") |
| 112 | except ImportError: |
| 113 | pass |
| 114 | try: |
| 115 | if intro is not None: |
| 116 | self.intro = intro |
| 117 | if self.intro: |
| 118 | self.stdout.write(str(self.intro)+"\n") |
| 119 | stop = None |
| 120 | while not stop: |
| 121 | if self.cmdqueue: |
| 122 | line = self.cmdqueue.pop(0) |
| 123 | else: |
| 124 | if self.use_rawinput: |
| 125 | try: |
| 126 | line = input(self.prompt) |
| 127 | except EOFError: |
| 128 | line = 'EOF' |
| 129 | else: |
| 130 | self.stdout.write(self.prompt) |
| 131 | self.stdout.flush() |
| 132 | line = self.stdin.readline() |
| 133 | if not len(line): |
| 134 | line = 'EOF' |
| 135 | else: |
| 136 | line = line.rstrip('\r\n') |
| 137 | line = self.precmd(line) |
| 138 | stop = self.onecmd(line) |
| 139 | stop = self.postcmd(stop, line) |
| 140 | self.postloop() |
| 141 | finally: |
| 142 | if self.use_rawinput and self.completekey: |
| 143 | try: |
| 144 | import readline |
| 145 | readline.set_completer(self.old_completer) |
| 146 | except ImportError: |
| 147 | pass |
| 148 | |
| 149 | |
| 150 | def precmd(self, line): |