Method: rich.__main__.make_test_card
Calls: 1, Exceptions: 0, Paths: 1Back
Path 1: 1 calls (1.0)
Table (1)
1def make_test_card() -> Table:
2 """Get a renderable that demonstrates a number of features."""
3 table = Table.grid(padding=1, pad_edge=True)
4 table.title = "Rich features"
5 table.add_column("Feature", no_wrap=True, justify="center", style="bold red")
6 table.add_column("Demonstration")
7
8 color_table = Table(
9 box=None,
10 expand=False,
11 show_header=False,
12 show_edge=False,
13 pad_edge=False,
14 )
15 color_table.add_row(
16 (
17 "✓ [bold green]4-bit color[/]\n"
18 "✓ [bold blue]8-bit color[/]\n"
19 "✓ [bold magenta]Truecolor (16.7 million)[/]\n"
20 "✓ [bold yellow]Dumb terminals[/]\n"
21 "✓ [bold cyan]Automatic color conversion"
22 ),
23 ColorBox(),
24 )
25
26 table.add_row("Colors", color_table)
27
28 table.add_row(
29 "Styles",
30 "All ansi styles: [bold]bold[/], [dim]dim[/], [italic]italic[/italic], [underline]underline[/], [strike]strikethrough[/], [reverse]reverse[/], and even [blink]blink[/].",
31 )
32
33 lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque in metus sed sapien ultricies pretium a at justo. Maecenas luctus velit et auctor maximus."
34 lorem_table = Table.grid(padding=1, collapse_padding=True)
35 lorem_table.pad_edge = False
36 lorem_table.add_row(
37 Text(lorem, justify="left", style="green"),
38 Text(lorem, justify="center", style="yellow"),
39 Text(lorem, justify="right", style="blue"),
40 Text(lorem, justify="full", style="red"),
41 )
42 table.add_row(
43 "Text",
44 Group(
45 Text.from_markup(
46 """Word wrap text. Justify [green]left[/], [yellow]center[/], [blue]right[/] or [red]full[/].\n"""
47 ),
48 lorem_table,
49 ),
50 )
51
52 def comparison(renderable1: RenderableType, renderable2: RenderableType) -> Table:
53 table = Table(show_header=False, pad_edge=False, box=None, expand=True)
54 table.add_column("1", ratio=1)
55 table.add_column("2", ratio=1)
56 table.add_row(renderable1, renderable2)
57 return table
58
59 table.add_row(
60 "Asian\nlanguage\nsupport",
61 ":flag_for_china: 该库支持中文,日文和韩文文本!\n:flag_for_japan: ライブラリは中国語、日本語、韓国語のテキストをサポートしています\n:flag_for_south_korea: 이 라이브러리는 중국어, 일본어 및 한국어 텍스트를 지원합니다",
62 )
63
64 markup_example = (
65 "[bold magenta]Rich[/] supports a simple [i]bbcode[/i]-like [b]markup[/b] for [yellow]color[/], [underline]style[/], and emoji! "
66 ":+1: :apple: :ant: :bear: :baguette_bread: :bus: "
67 )
68 table.add_row("Markup", markup_example)
69
70 example_table = Table(
71 show_edge=False,
72 show_header=True,
73 expand=False,
74 row_styles=["none", "dim"],
75 box=box.SIMPLE,
76 )
77 example_table.add_column("[green]Date", style="green", no_wrap=True)
78 example_table.add_column("[blue]Title", style="blue")
79 example_table.add_column(
80 "[cyan]Production Budget",
81 style="cyan",
82 justify="right",
83 no_wrap=True,
84 )
85 example_table.add_column(
86 "[magenta]Box Office",
87 style="magenta",
88 justify="right",
89 no_wrap=True,
90 )
91 example_table.add_row(
92 "Dec 20, 2019",
93 "Star Wars: The Rise of Skywalker",
94 "$275,000,000",
95 "$375,126,118",
96 )
97 example_table.add_row(
98 "May 25, 2018",
99 "[b]Solo[/]: A Star Wars Story",
100 "$275,000,000",
101 "$393,151,347",
102 )
103 example_table.add_row(
104 "Dec 15, 2017",
105 "Star Wars Ep. VIII: The Last Jedi",
106 "$262,000,000",
107 "[bold]$1,332,539,889[/bold]",
108 )
109 example_table.add_row(
110 "May 19, 1999",
111 "Star Wars Ep. [b]I[/b]: [i]The phantom Menace",
112 "$115,000,000",
113 "$1,027,044,677",
114 )
115
116 table.add_row("Tables", example_table)
117
118 code = '''\
119def iter_last(values: Iterable[T]) -> Iterable[Tuple[bool, T]]:
120 """Iterate and generate a tuple with a flag for last value."""
121 iter_values = iter(values)
122 try:
123 previous_value = next(iter_values)
124 except StopIteration:
125 return
126 for value in iter_values:
127 yield False, previous_value
128 previous_value = value
129 yield True, previous_value'''
130
131 pretty_data = {
132 "foo": [
133 3.1427,
134 (
135 "Paul Atreides",
136 "Vladimir Harkonnen",
137 "Thufir Hawat",
138 ),
139 ],
140 "atomic": (False, True, None),
141 }
142 table.add_row(
143 "Syntax\nhighlighting\n&\npretty\nprinting",
144 comparison(
145 Syntax(code, "python3", line_numbers=True, indent_guides=True),
146 Pretty(pretty_data, indent_guides=True),
147 ),
148 )
149
150 markdown_example = """\
151# Markdown
152
153Supports much of the *markdown* __syntax__!
154
155- Headers
156- Basic formatting: **bold**, *italic*, `code`
157- Block quotes
158- Lists, and more...
159 """
160 table.add_row(
161 "Markdown", comparison("[cyan]" + markdown_example, Markdown(markdown_example))
162 )
163
164 table.add_row(
165 "+more!",
166 """Progress bars, columns, styled logging handler, tracebacks, etc...""",
167 )
168 return table