summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-02-27 22:41:53 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-02-27 22:41:53 -0500
commit53c41ea5ff6eda6bba94938c16505e4db10c46b6 (patch)
tree549bcd9171ae3c2ab91baa3a142e79957e27e576 /cmd2
parent60d6e4c7e41ffd21d67c21b4e88efc6775e5a1cd (diff)
downloadcmd2-git-53c41ea5ff6eda6bba94938c16505e4db10c46b6.tar.gz
Updated the examples to illustrate sorting CompletionItems
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/argparse_completer.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py
index 7732c5c5..891622d1 100644
--- a/cmd2/argparse_completer.py
+++ b/cmd2/argparse_completer.py
@@ -70,9 +70,9 @@ from argparse import ZERO_OR_MORE, ONE_OR_MORE, ArgumentError, _, _get_action_na
from typing import List, Dict, Tuple, Callable, Union
from colorama import Fore
-from wcwidth import wcswidth
from .rl_utils import rl_force_redisplay
+from .utils import ansi_safe_wcswidth
# attribute that can optionally added to an argparse argument (called an Action) to
# define the completion choices for the argument. You may provide a Collection or a Function.
@@ -587,16 +587,16 @@ class AutoCompleter(object):
def _format_completions(self, action, completions: List[Union[str, CompletionItem]]) -> List[str]:
if completions and len(completions) > 1 and isinstance(completions[0], CompletionItem):
- # If the user has not already sorted the CompletionItems, then do that now
+ # If the user has not already sorted the CompletionItems, then sort them before appending the descriptions
if not self._cmd2_app.matches_sorted:
completions.sort(key=self._cmd2_app.matches_sort_key)
self._cmd2_app.matches_sorted = True
- token_width = wcswidth(action.dest)
+ token_width = ansi_safe_wcswidth(action.dest)
completions_with_desc = []
for item in completions:
- item_width = wcswidth(item)
+ item_width = ansi_safe_wcswidth(item)
if item_width > token_width:
token_width = item_width