summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2017-05-03 19:52:55 -0400
committerGitHub <noreply@github.com>2017-05-03 19:52:55 -0400
commit72c5974027ab4f22905be9bc7201ae35d8ca7fb8 (patch)
tree5c9d21ce43ca9847cb28df66d7995a3b5feb71ce /cmd2.py
parentf27390116ae1ef334df72de13b9cb1a603c37ec5 (diff)
parent660bd38a1ecc36a6c7aaa5c27841a3957978802b (diff)
downloadcmd2-git-72c5974027ab4f22905be9bc7201ae35d8ca7fb8.tar.gz
Merge pull request #91 from python-cmd2/readline_improvements
Readline improvements
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/cmd2.py b/cmd2.py
index e2201632..ed481330 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -62,6 +62,15 @@ from six.moves import zip
# 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:
@@ -1111,9 +1120,8 @@ class Cmd(cmd.Cmd):
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
@@ -1128,12 +1136,10 @@ class Cmd(cmd.Cmd):
# 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:
@@ -1149,10 +1155,8 @@ class Cmd(cmd.Cmd):
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