Skip to content

Commit 6a3b2e9

Browse files
committed
Updated tab completion example
1 parent 6b53e0c commit 6a3b2e9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

examples/argparse_completion.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Cmd2ArgumentParser,
1515
CompletionError,
1616
CompletionItem,
17+
ansi,
1718
with_argparser,
1819
)
1920

@@ -45,7 +46,9 @@ def choices_completion_error(self) -> List[str]:
4546
# noinspection PyMethodMayBeStatic
4647
def choices_completion_item(self) -> List[CompletionItem]:
4748
"""Return CompletionItem instead of strings. These give more context to what's being tab completed."""
48-
items = {1: "My item", 2: "Another item", 3: "Yet another item"}
49+
fancy_item = "These things can\ncontain newlines and\n"
50+
fancy_item += ansi.style("styled text!!", fg=ansi.fg.bright_yellow, underline=True)
51+
items = {1: "My item", 2: "Another item", 3: "Yet another item", 4: fancy_item}
4952
return [CompletionItem(item_id, description) for item_id, description in items.items()]
5053

5154
# noinspection PyMethodMayBeStatic
@@ -73,8 +76,6 @@ def choices_arg_tokens(self, arg_tokens: Dict[str, List[str]]) -> List[str]:
7376
# want the entire choices list showing in the usage text for this command.
7477
example_parser.add_argument('--choices', choices=food_item_strs, metavar="CHOICE", help="tab complete using choices")
7578

76-
example_parser.add_argument('--choices', choices=food_item_strs, metavar="CHOICE", help="tab complete using choices")
77-
7879
# Tab complete from choices provided by a choices_provider
7980
example_parser.add_argument(
8081
'--choices_provider', choices_provider=choices_provider, help="tab complete using a choices_provider"

0 commit comments

Comments
 (0)