Skip to content

Commit 93fc641

Browse files
committed
Fix match-case so table formatting is as desired
1 parent 55fcbda commit 93fc641

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

examples/rich_tables.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,27 @@ def do_countries(self, _: cmd2.Statement) -> None:
9090
table.caption = "Data from https://worldpopulationreview.com/ and Wikipedia"
9191

9292
for header in COUNTRY_HEADERS:
93+
header_style = None
94+
style = None
9395
match header:
94-
case s if "2025 Population" in s:
96+
case population if "2025 Population" in population:
9597
justify = "right"
9698
header_style = Color.BRIGHT_BLUE
9799
style = Color.BLUE
98-
case s if "Density" in s:
100+
case density if "Density" in density:
99101
justify = "right"
100102
header_style = Color.BRIGHT_RED
101103
style = Color.RED
102-
case s if "per capita" in s:
104+
case percap if "per capita" in percap:
103105
justify = "right"
104106
header_style = Color.BRIGHT_GREEN
105107
style = Color.GREEN
108+
case area if 'Area' in area:
109+
justify = "right"
110+
case gdp if 'GDP' in gdp:
111+
justify = "right"
106112
case _:
107113
justify = "left"
108-
style = None
109-
header_style = None
110114

111115
table.add_column(header, justify=justify, header_style=header_style, style=style)
112116

0 commit comments

Comments
 (0)