diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-05-03 19:52:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-03 19:52:55 -0400 |
commit | 72c5974027ab4f22905be9bc7201ae35d8ca7fb8 (patch) | |
tree | 5c9d21ce43ca9847cb28df66d7995a3b5feb71ce | |
parent | f27390116ae1ef334df72de13b9cb1a603c37ec5 (diff) | |
parent | 660bd38a1ecc36a6c7aaa5c27841a3957978802b (diff) | |
download | cmd2-git-72c5974027ab4f22905be9bc7201ae35d8ca7fb8.tar.gz |
Merge pull request #91 from python-cmd2/readline_improvements
Readline improvements
-rwxr-xr-x | cmd2.py | 22 |
1 files changed, 13 insertions, 9 deletions
@@ -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 |