Skip to content

Commit df217e5

Browse files
committed
Added a table to a CompletionItem description in argparse_completion.py example.
1 parent f080389 commit df217e5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

examples/argparse_completion.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33

44
import argparse
55

6+
from rich.box import SIMPLE_HEAD
67
from rich.style import Style
8+
from rich.table import Table
79
from rich.text import Text
810

911
from cmd2 import (
1012
Cmd,
1113
Cmd2ArgumentParser,
14+
Cmd2Style,
1215
Color,
1316
CompletionError,
1417
CompletionItem,
@@ -46,7 +49,17 @@ def choices_completion_item(self) -> list[CompletionItem]:
4649
Text("styled text!!", style=Style(color=Color.BRIGHT_YELLOW, underline=True)),
4750
)
4851

49-
items = {1: "My item", 2: "Another item", 3: "Yet another item", 4: fancy_item}
52+
table_item = Table("Left Column", "Right Column", box=SIMPLE_HEAD, border_style=Cmd2Style.RULE_LINE)
53+
table_item.add_row("Yes, it's true.", "CompletionItems can")
54+
table_item.add_row("even display description", "data in tables!")
55+
56+
items = {
57+
1: "My item",
58+
2: "Another item",
59+
3: "Yet another item",
60+
4: fancy_item,
61+
5: table_item,
62+
}
5063
return [CompletionItem(item_id, [description]) for item_id, description in items.items()]
5164

5265
def choices_arg_tokens(self, arg_tokens: dict[str, list[str]]) -> list[str]:

0 commit comments

Comments
 (0)