mirror of
https://github.com/Textualize/rich.git
synced 2025-12-23 07:08:35 +00:00
Merge 2bd335f13a into 53757bc234
This commit is contained in:
commit
ee66d57a02
2 changed files with 43 additions and 0 deletions
|
|
@ -702,6 +702,13 @@ class Table(JupyterMixin):
|
|||
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(
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue