Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@
# noinspection PyUnresolvedReferences
from six.moves.urllib.request import urlopen

# Prefer statically linked gnureadline if available (for Mac OS X compatibility due to issues with libedit)
try:
import gnureadline as readline
except ImportError:
try:
import readline
except ImportError:
pass

# Python 3 compatibility hack due to no built-in file keyword in Python 3
# Due to one occurrence of isinstance(<foo>, file) checking to see if something is of file type
try:
Expand Down Expand Up @@ -1111,9 +1120,8 @@ def pseudo_raw_input(self, prompt):
if not len(line):
line = 'EOF'
else:
if line[-1] == '\n': # this was always true in Cmd
line = line[:-1]
return line
line = line.rstrip('\r\n')
return line.strip()

def _cmdloop(self):
"""Repeatedly issue a prompt, accept input, parse an initial prefix
Expand All @@ -1128,12 +1136,10 @@ def _cmdloop(self):
# has been split out so that it can be called separately
if self.use_rawinput and self.completekey:
try:
# noinspection PyUnresolvedReferences
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey + ": complete")
except ImportError:
except NameError:
pass
stop = None
try:
Expand All @@ -1149,10 +1155,8 @@ def _cmdloop(self):
finally:
if self.use_rawinput and self.completekey:
try:
# noinspection PyUnresolvedReferences
import readline
readline.set_completer(self.old_completer)
except ImportError:
except NameError:
pass
return stop

Expand Down