summaryrefslogtreecommitdiff
path: root/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-03-27 03:00:10 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-03-27 03:00:10 -0400
commit0ef0e9bde9d32728d6aabdbb7964dafe6e83efb7 (patch)
tree2ebfc6742226bd1082b6ea7021f50e748f543637 /cmd2.py
parentce7612051978393ca9eb19dc6ad1e7f003e7cc4d (diff)
downloadcmd2-git-0ef0e9bde9d32728d6aabdbb7964dafe6e83efb7.tar.gz
Fixed a case where display_matches wasn't being set. Added unit tests.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-xcmd2.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/cmd2.py b/cmd2.py
index 9235d7f5..87f4da2c 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -1330,8 +1330,8 @@ class Cmd(cmd.Cmd):
for cur_initial_token in initial_tokens:
- # Keep empty and quoted tokens
- if len(cur_initial_token) == 0 or cur_initial_token[0] in QUOTES:
+ # Save tokens up to 1 character in length or quoted tokens. No need to parse these.
+ if len(cur_initial_token) <= 1 or cur_initial_token[0] in QUOTES:
raw_tokens.append(cur_initial_token)
continue
@@ -2068,20 +2068,23 @@ class Cmd(cmd.Cmd):
self.completion_matches = []
return None
- # Check if we need to remove text from the beginning of tab completions
- if text_to_remove:
- self.completion_matches = [m.replace(text_to_remove, '', 1) for m in self.completion_matches]
-
- # Check if we need to restore a shortcut in the tab completions
- if shortcut_to_restore:
+ if text_to_remove or shortcut_to_restore:
# If self.display_matches is empty, then set it to self.completion_matches
- # before we restore the shortcut so the tab completion suggestions that display to
- # the user don't have the shortcut character.
+ # before we alter them. That way the suggestions will reflect how we parsed
+ # the token being completed and not how readline did.
if len(self.display_matches) == 0:
self.display_matches = self.completion_matches
- # Prepend all tab completions with the shortcut so it doesn't get erased from the command line
- self.completion_matches = [shortcut_to_restore + match for match in self.completion_matches]
+ # Check if we need to remove text from the beginning of tab completions
+ if text_to_remove:
+ self.completion_matches = \
+ [m.replace(text_to_remove, '', 1) for m in self.completion_matches]
+
+ # Check if we need to restore a shortcut in the tab completions
+ # so it doesn't get erased from the command line
+ if shortcut_to_restore:
+ self.completion_matches = \
+ [shortcut_to_restore + match for match in self.completion_matches]
# Check if the token being completed has an unclosed quote
if len(raw_completion_token) == 1: