summaryrefslogtreecommitdiff
path: root/examples/argparse_completion.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-03-02 14:28:26 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-03-02 14:28:26 -0500
commit6a3b2e93844c5c851d6b4cd60c7f432f6f4afe37 (patch)
treeb84e6ffb95f4f04fe67767fab68f6457647b7a39 /examples/argparse_completion.py
parent6b53e0cac14217f93ba9f7c346a333c218de592d (diff)
downloadcmd2-git-6a3b2e93844c5c851d6b4cd60c7f432f6f4afe37.tar.gz
Updated tab completion example
Diffstat (limited to 'examples/argparse_completion.py')
-rw-r--r--examples/argparse_completion.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/examples/argparse_completion.py b/examples/argparse_completion.py
index fa821b77..7350f46c 100644
--- a/examples/argparse_completion.py
+++ b/examples/argparse_completion.py
@@ -14,6 +14,7 @@ from cmd2 import (
Cmd2ArgumentParser,
CompletionError,
CompletionItem,
+ ansi,
with_argparser,
)
@@ -45,7 +46,9 @@ class ArgparseCompletion(Cmd):
# noinspection PyMethodMayBeStatic
def choices_completion_item(self) -> List[CompletionItem]:
"""Return CompletionItem instead of strings. These give more context to what's being tab completed."""
- items = {1: "My item", 2: "Another item", 3: "Yet another item"}
+ fancy_item = "These things can\ncontain newlines and\n"
+ fancy_item += ansi.style("styled text!!", fg=ansi.fg.bright_yellow, underline=True)
+ items = {1: "My item", 2: "Another item", 3: "Yet another item", 4: fancy_item}
return [CompletionItem(item_id, description) for item_id, description in items.items()]
# noinspection PyMethodMayBeStatic
@@ -73,8 +76,6 @@ class ArgparseCompletion(Cmd):
# want the entire choices list showing in the usage text for this command.
example_parser.add_argument('--choices', choices=food_item_strs, metavar="CHOICE", help="tab complete using choices")
- example_parser.add_argument('--choices', choices=food_item_strs, metavar="CHOICE", help="tab complete using choices")
-
# Tab complete from choices provided by a choices_provider
example_parser.add_argument(
'--choices_provider', choices_provider=choices_provider, help="tab complete using a choices_provider"