diff options
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rwxr-xr-x | cmd2.py | 31 |
2 files changed, 20 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index fc7f150c..83e444b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 0.8.8 (TBD, 2018) * Bug Fixes * Prevent crashes that could occur attempting to open a file in non-existent directory or with very long filename +* Enhancements + * ``display_matches`` is no longer restricted to delimited strings ## 0.8.7 (May 28, 2018) * Bug Fixes @@ -939,6 +939,7 @@ class AddSubmenu(object): submenu.allow_appended_space = True submenu.allow_closing_quote = True submenu.display_matches = [] + submenu.matches_delimited = False return _complete_from_cmd(submenu, text, line, begidx, endidx) finally: @@ -949,6 +950,7 @@ class AddSubmenu(object): _self.allow_appended_space = submenu.allow_appended_space _self.allow_closing_quote = submenu.allow_closing_quote _self.display_matches = copy.copy(submenu.display_matches) + _self.matches_delimited = submenu.matches_delimited original_do_help = cmd_obj.do_help original_complete_help = cmd_obj.complete_help @@ -1174,13 +1176,16 @@ class Cmd(cmd.Cmd): # will be added if there is an unmatched opening quote self.allow_closing_quote = True - # Use this list if you are completing strings that contain a common delimiter and you only want to - # display the final portion of the matches as the tab-completion suggestions. The full matches - # still must be returned from your completer function. For an example, look at path_complete() - # which uses this to show only the basename of paths as the suggestions. delimiter_complete() also - # populates this list. + # If the tab-completion suggestions should be displayed in a way that is different than the actual match values, + # then place those results in this list. The full matches still must be returned from your completer function. + # For an example, look at path_complete() which uses this to show only the basename of paths as the + # suggestions. delimiter_complete() also populates this list. self.display_matches = [] + # Used by functions like path_complete() and delimiter_complete() to properly + # quote matches that are completed in a delimited fashion + self.matches_delimited = False + # ----- Methods related to presenting output to the user ----- @property @@ -1380,6 +1385,7 @@ class Cmd(cmd.Cmd): self.allow_appended_space = True self.allow_closing_quote = True self.display_matches = [] + self.matches_delimited = False if rl_type == RlType.GNU: readline.set_completion_display_matches_hook(self._display_matches_gnu_readline) @@ -1557,6 +1563,8 @@ class Cmd(cmd.Cmd): # Display only the portion of the match that's being completed based on delimiter if matches: + # Set this to True for proper quoting of matches with spaces + self.matches_delimited = True # Get the common beginning for the matches common_prefix = os.path.commonprefix(matches) @@ -1758,6 +1766,9 @@ class Cmd(cmd.Cmd): search_str = os.path.join(os.getcwd(), search_str) cwd_added = True + # Set this to True for proper quoting of paths with spaces + self.matches_delimited = True + # Find all matching path completions matches = glob.glob(search_str) @@ -2147,13 +2158,7 @@ class Cmd(cmd.Cmd): display_matches_set = set(self.display_matches) self.display_matches = list(display_matches_set) - # Check if display_matches has been used. If so, then matches - # on delimited strings like paths was done. - if self.display_matches: - matches_delimited = True - else: - matches_delimited = False - + if not self.display_matches: # Since self.display_matches is empty, set it to self.completion_matches # before we alter them. That way the suggestions will reflect how we parsed # the token being completed and not how readline did. @@ -2167,7 +2172,7 @@ class Cmd(cmd.Cmd): # This is the tab completion text that will appear on the command line. common_prefix = os.path.commonprefix(self.completion_matches) - if matches_delimited: + if self.matches_delimited: # Check if any portion of the display matches appears in the tab completion display_prefix = os.path.commonprefix(self.display_matches) |
