Skip to content

Commit

Permalink
fix(table): highlight columns added by add_row
Browse files Browse the repository at this point in the history
  • Loading branch information
TomJGooding committed Oct 3, 2024
1 parent 5ba9cb5 commit 16b3830
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rich/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def add_cell(column: Column, renderable: "RenderableType") -> None:
]
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)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 16b3830

Please sign in to comment.