Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 35a92ce

Browse files
author
Michael W. Hudson
committed
Fix bug
[ 676342 ] after using pdb readline does not work correctly using Michael Stone's patch so the completer functionality of cmd is only setup between preloop and postloop.
1 parent c064a1d commit 35a92ce

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

Lib/cmd.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,7 @@ def __init__(self, completekey='tab'):
8686
8787
"""
8888
self.cmdqueue = []
89-
if completekey:
90-
try:
91-
import readline
92-
readline.set_completer(self.complete)
93-
readline.parse_and_bind(completekey+": complete")
94-
except ImportError:
95-
pass
89+
self.completekey = completekey
9690

9791
def cmdloop(self, intro=None):
9892
"""Repeatedly issue a prompt, accept input, parse an initial prefix
@@ -142,14 +136,26 @@ def postcmd(self, stop, line):
142136

143137
def preloop(self):
144138
"""Hook method executed once when the cmdloop() method is called."""
145-
pass
139+
if self.completekey:
140+
try:
141+
import readline
142+
self.old_completer = readline.get_completer()
143+
readline.set_completer(self.complete)
144+
readline.parse_and_bind(self.completekey+": complete")
145+
except ImportError:
146+
pass
146147

147148
def postloop(self):
148149
"""Hook method executed once when the cmdloop() method is about to
149150
return.
150151
151152
"""
152-
pass
153+
if self.completekey:
154+
try:
155+
import readline
156+
readline.set_completer(self.old_completer)
157+
except ImportError:
158+
pass
153159

154160
def parseline(self, line):
155161
line = line.strip()

0 commit comments

Comments
 (0)