Skip to content

Commit 6607492

Browse files
authored
Merge pull request #3518 from TomJGooding/fix-table-highlight-columns-added-by-add-row
fix(table): highlight columns added by add_row
2 parents e732952 + 16b3830 commit 6607492

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Fixed
11+
12+
- Fixed `Table` columns not highlighting when added by `add_row` https://github.com/Textualize/rich/issues/3517
13+
814
## [13.9.1] - 2024-10-01
915

1016
### Fixed

rich/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def add_cell(column: Column, renderable: "RenderableType") -> None:
451451
]
452452
for index, renderable in enumerate(cell_renderables):
453453
if index == len(columns):
454-
column = Column(_index=index)
454+
column = Column(_index=index, highlight=self.highlight)
455455
for _ in self.rows:
456456
add_cell(column, Text(""))
457457
self.columns.append(column)

tests/test_table.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,25 @@ def test_placement_table_box_elements(show_header, show_footer, expected):
363363
assert output == expected
364364

365365

366+
def test_columns_highlight_added_by_add_row() -> None:
367+
"""Regression test for https://github.com/Textualize/rich/issues/3517"""
368+
table = Table(show_header=False, highlight=True)
369+
table.add_row("1", repr("FOO"))
370+
371+
assert table.columns[0].highlight == table.highlight
372+
assert table.columns[1].highlight == table.highlight
373+
374+
console = Console(record=True)
375+
console.print(table)
376+
output = console.export_text(styles=True)
377+
print(repr(output))
378+
379+
expected = (
380+
"┌───┬───────┐\n\x1b[1;36m1\x1b[0m │ \x1b[32m'FOO'\x1b[0m │\n└───┴───────┘\n"
381+
)
382+
assert output == expected
383+
384+
366385
if __name__ == "__main__":
367386
render = render_tables()
368387
print(render)

0 commit comments

Comments
 (0)