Skip to content

Commit 9f15260

Browse files
authored
Merge pull request #2725 from jonathan-3play/fix_table_box_rendering_order
fix table rendering order of box elements
2 parents 577def2 + 2884da3 commit 9f15260

File tree

4 files changed

+143
-5
lines changed

4 files changed

+143
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ 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+
- Improved detection of `attrs` library, that isn't confused by the presence of the `attr` library.
13+
- Fixed `Table` rendering of box elements so "footer" elements truly appear at bottom of table, "mid" elements in main table body.
14+
815
## [13.7.1] - 2024-02-28
916

1017
### Fixed
@@ -124,6 +131,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
124131

125132
- Added Polish README
126133

134+
127135
### Changed
128136

129137
- `rich.progress.track()` will now show the elapsed time after finishing the task https://github.com/Textualize/rich/pull/2659

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The following people have contributed to the development of Rich:
1515
- [Ed Davis](https://github.com/davised)
1616
- [Pete Davison](https://github.com/pd93)
1717
- [James Estevez](https://github.com/jstvz)
18+
- [Jonathan Eunice](https://github.com/jonathan-3play)
1819
- [Aryaz Eghbali](https://github.com/AryazE)
1920
- [Oleksis Fraga](https://github.com/oleksis)
2021
- [Andy Gimblett](https://github.com/gimbo)

rich/table.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -775,16 +775,16 @@ def _render(
775775
_Segment(_box.head_right, border_style),
776776
_Segment(_box.head_vertical, border_style),
777777
),
778-
(
779-
_Segment(_box.foot_left, border_style),
780-
_Segment(_box.foot_right, border_style),
781-
_Segment(_box.foot_vertical, border_style),
782-
),
783778
(
784779
_Segment(_box.mid_left, border_style),
785780
_Segment(_box.mid_right, border_style),
786781
_Segment(_box.mid_vertical, border_style),
787782
),
783+
(
784+
_Segment(_box.foot_left, border_style),
785+
_Segment(_box.foot_right, border_style),
786+
_Segment(_box.foot_vertical, border_style),
787+
),
788788
]
789789
if show_edge:
790790
yield _Segment(_box.get_top(widths), border_style)

tests/test_table.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# encoding=utf-8
22

33
import io
4+
from textwrap import dedent
45

56
import pytest
67

@@ -234,6 +235,134 @@ def test_section():
234235
assert output == expected
235236

236237

238+
@pytest.mark.parametrize(
239+
"show_header,show_footer,expected",
240+
[
241+
(
242+
False,
243+
False,
244+
dedent(
245+
"""
246+
abbbbbcbbbbbbbbbcbbbbcbbbbbd
247+
1Dec 2Skywalker2275M2375M 3
248+
4May 5Solo 5275M5393M 6
249+
ijjjjjkjjjjjjjjjkjjjjkjjjjjl
250+
7Dec 8Last Jedi8262M81333M9
251+
qrrrrrsrrrrrrrrrsrrrrsrrrrrt
252+
"""
253+
).lstrip(),
254+
),
255+
(
256+
True,
257+
False,
258+
dedent(
259+
"""
260+
abbbbbcbbbbbbbbbcbbbbcbbbbbd
261+
1Month2Nickname 2Cost2Gross3
262+
efffffgfffffffffgffffgfffffh
263+
4Dec 5Skywalker5275M5375M 6
264+
4May 5Solo 5275M5393M 6
265+
ijjjjjkjjjjjjjjjkjjjjkjjjjjl
266+
7Dec 8Last Jedi8262M81333M9
267+
qrrrrrsrrrrrrrrrsrrrrsrrrrrt
268+
"""
269+
).lstrip(),
270+
),
271+
(
272+
False,
273+
True,
274+
dedent(
275+
"""
276+
abbbbbcbbbbbbbbbcbbbbcbbbbbd
277+
1Dec 2Skywalker2275M2375M 3
278+
4May 5Solo 5275M5393M 6
279+
ijjjjjkjjjjjjjjjkjjjjkjjjjjl
280+
4Dec 5Last Jedi5262M51333M6
281+
mnnnnnonnnnnnnnnonnnnonnnnnp
282+
7MONTH8NICKNAME 8COST8GROSS9
283+
qrrrrrsrrrrrrrrrsrrrrsrrrrrt
284+
"""
285+
).lstrip(),
286+
),
287+
(
288+
True,
289+
True,
290+
dedent(
291+
"""
292+
abbbbbcbbbbbbbbbcbbbbcbbbbbd
293+
1Month2Nickname 2Cost2Gross3
294+
efffffgfffffffffgffffgfffffh
295+
4Dec 5Skywalker5275M5375M 6
296+
4May 5Solo 5275M5393M 6
297+
ijjjjjkjjjjjjjjjkjjjjkjjjjjl
298+
4Dec 5Last Jedi5262M51333M6
299+
mnnnnnonnnnnnnnnonnnnonnnnnp
300+
7MONTH8NICKNAME 8COST8GROSS9
301+
qrrrrrsrrrrrrrrrsrrrrsrrrrrt
302+
"""
303+
).lstrip(),
304+
),
305+
],
306+
)
307+
def test_placement_table_box_elements(show_header, show_footer, expected):
308+
"""Ensure box drawing characters correctly positioned."""
309+
310+
table = Table(
311+
box=box.ASCII, show_header=show_header, show_footer=show_footer, padding=0
312+
)
313+
314+
# content rows indicated by numerals, pure dividers by letters
315+
table.box.__dict__.update(
316+
top_left="a",
317+
top="b",
318+
top_divider="c",
319+
top_right="d",
320+
head_left="1",
321+
head_vertical="2",
322+
head_right="3",
323+
head_row_left="e",
324+
head_row_horizontal="f",
325+
head_row_cross="g",
326+
head_row_right="h",
327+
mid_left="4",
328+
mid_vertical="5",
329+
mid_right="6",
330+
row_left="i",
331+
row_horizontal="j",
332+
row_cross="k",
333+
row_right="l",
334+
foot_left="7",
335+
foot_vertical="8",
336+
foot_right="9",
337+
foot_row_left="m",
338+
foot_row_horizontal="n",
339+
foot_row_cross="o",
340+
foot_row_right="p",
341+
bottom_left="q",
342+
bottom="r",
343+
bottom_divider="s",
344+
bottom_right="t",
345+
)
346+
347+
# add content - note headers title case, footers upper case
348+
table.add_column("Month", "MONTH", width=5)
349+
table.add_column("Nickname", "NICKNAME", width=9)
350+
table.add_column("Cost", "COST", width=4)
351+
table.add_column("Gross", "GROSS", width=5)
352+
353+
table.add_row("Dec", "Skywalker", "275M", "375M")
354+
table.add_row("May", "Solo", "275M", "393M")
355+
table.add_section()
356+
table.add_row("Dec", "Last Jedi", "262M", "1333M")
357+
358+
console = Console(record=True, width=28)
359+
console.print(table)
360+
output = console.export_text()
361+
print(repr(output))
362+
363+
assert output == expected
364+
365+
237366
if __name__ == "__main__":
238367
render = render_tables()
239368
print(render)

0 commit comments

Comments
 (0)