fix(table): highlight columns added by add_row

This commit is contained in:
TomJGooding 2024-10-03 16:05:56 +01:00
parent 5ba9cb56e6
commit 16b3830408
3 changed files with 26 additions and 1 deletions

View File

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Fixed
- Fixed `Table` columns not highlighting when added by `add_row` https://github.com/Textualize/rich/issues/3517
## [13.9.1] - 2024-10-01
### Fixed

View File

@ -451,7 +451,7 @@ class Table(JupyterMixin):
]
for index, renderable in enumerate(cell_renderables):
if index == len(columns):
column = Column(_index=index)
column = Column(_index=index, highlight=self.highlight)
for _ in self.rows:
add_cell(column, Text(""))
self.columns.append(column)

View File

@ -363,6 +363,25 @@ def test_placement_table_box_elements(show_header, show_footer, expected):
assert output == expected
def test_columns_highlight_added_by_add_row() -> None:
"""Regression test for https://github.com/Textualize/rich/issues/3517"""
table = Table(show_header=False, highlight=True)
table.add_row("1", repr("FOO"))
assert table.columns[0].highlight == table.highlight
assert table.columns[1].highlight == table.highlight
console = Console(record=True)
console.print(table)
output = console.export_text(styles=True)
print(repr(output))
expected = (
"┌───┬───────┐\n\x1b[1;36m1\x1b[0m │ \x1b[32m'FOO'\x1b[0m │\n└───┴───────┘\n"
)
assert output == expected
if __name__ == "__main__":
render = render_tables()
print(render)