Skip to content

Commit a821cb0

Browse files
committed
Added color to some columns for illustrative purposes
1 parent 8090ee4 commit a821cb0

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

examples/rich_tables.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
'Country',
3232
'2025 Population',
3333
'Area (M km^2)',
34-
'Density (/km^2)',
34+
'Population Density (/km^2)',
3535
'GDP (million US$)',
3636
'GDP per capita (US$)',
3737
]
@@ -101,6 +101,18 @@ def do_countries(self, _: cmd2.Statement) -> None:
101101
str_row = [f"{item:,}" if isinstance(item, int) else str(item) for item in row]
102102
table.add_row(*str_row)
103103

104+
# Make Population column blue
105+
table.columns[2].header_style = "bold blue"
106+
table.columns[2].style = "blue"
107+
108+
# Make Density column red
109+
table.columns[4].header_style = "bold red"
110+
table.columns[4].style = "red"
111+
112+
# Make GDB per capita column green
113+
table.columns[6].header_style = "bold green"
114+
table.columns[6].style = "green"
115+
104116
self.poutput(table)
105117

106118

0 commit comments

Comments
 (0)