Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions rich/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,13 @@ def _get_padding_width(self, column_index: int) -> int:
if self.collapse_padding:
if column_index > 0:
pad_left = max(0, pad_left - pad_right)
if not self.pad_edge:
first_column = column_index == 0
last_column = column_index == len(self.columns) - 1
if first_column:
pad_left = 0
if last_column:
pad_right = 0
return pad_left + pad_right

def _measure_column(
Expand Down
36 changes: 36 additions & 0 deletions tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,42 @@ def test_columns_highlight_added_by_add_row() -> None:
assert output == expected


def test_pad_edge_false_with_fixed_width_columns() -> None:
"""Regression test for https://github.com/Textualize/rich/issues/3892

When pad_edge=False with fixed-width columns, the edge columns should not
have extra padding added to their width calculation.
"""
output = io.StringIO()
console = Console(
width=60,
file=output,
force_terminal=True,
legacy_windows=False,
color_system=None,
_environ={},
)

table = Table(
Column('verb', width=5),
Column('noun', width=5),
Column('wh', width=2),
box=None,
pad_edge=False,
expand=False,
show_header=True,
)
table.add_row('hello', 'world', 'oh')
console.print(table)

result = output.getvalue().rstrip('\n')
expected = '\n'.join([
'verb noun wh',
'hello world oh'
])
assert result == expected


if __name__ == "__main__":
render = render_tables()
print(render)
Expand Down