resolved RESOLVED PASS · 13 tool calls · 93 s · Textualize/rich
fix table rendering order of box elements
## Type of changes
- [x] Bug fix
- [ ] New feature
- [ ] Documentation / docstrings
- [x] Tests
- [ ] Other
## Checklist
- [x] I've run the latest [black](https://github.com/psf/black) with default args on new code.
- [x] I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
- [x] I've added tests for new code.
- [x] I accept that @willmcgugan may be pedantic in the code review.
## Description
* Previously "mid" box elements appeared in last line of table (footer), while "footer" box elements appeared mid table body. Reversed that order so mid is truly mid, footer is truly footer.
* Tested with:
```
table.box.head_left = '1'
table.box.head_vertical = '2'
table.box.head_right = '3'
table.box.mid_left = '4'
table.box.mid_vertical = '5'
table.box.mid_right = '6'
table.box.foot_left = '7'
table.box.foot_vertical = '8'
table.box.foot_right = '9'
```
After change, correct ordering:
```
+--------------------------------------------------------------------------+
1Date 2Title 2 Production2 Box Office3
|------------ --------------------------------- ------------ --------------|
4Dec 20, 20195Star Wars: The Rise of Skywalker 5$275,000,0005 $375,126,1186
4May 25, 20185Solo: A Star Wars Story 5$275,000,0005 $393,151,3476
7Dec 15, 20178Star Wars Ep. VIII: The Last Jedi8$262,000,0008$1,332,539,8899
+--------------------------------------------------------------------------+
```
* All non-skipped prior automated tests pass. No automated tests added. Unclear that additional test for box ordering would add proportionate value.
| # | Tool | Arguments | Result |
|---|---|---|---|
| 1 | run_command | {
"command": "grep -rn \"table.box\" . | head -20"
} | {"status": "ok", "stdout": "./examples/table_movie.py:172: table.box = box_style\n./rich/box.py:475: table.box = getattr(box, box_name)\n", "stderr": "", "exit_full{"status": "ok", "stdout": "./examples/table_movie.py:172: table.box = box_style\n./rich/box.py:475: table.box = getattr(box, box_name)\n", "stderr": "", "exit_code": 0} |
| 2 | run_command | {
"command": "grep -rn \"mid_left\" . | head -20"
} | {"status": "ok", "stdout": "./rich/box.py:50: self.mid_left, _, self.mid_vertical, self.mid_right = iter(line4)\n./rich/box.py:146: left = self.mid_left\n./richfull{"status": "ok", "stdout": "./rich/box.py:50: self.mid_left, _, self.mid_vertical, self.mid_right = iter(line4)\n./rich/box.py:146: left = self.mid_left\n./rich/table.py:784: _Segment(_box.mid_left, border_style),\n./rich/panel.py:226: line_start = Segment(box.mid_left, border_style)\n", "stderr": "", "exit_code": 0} |
| 3 | read_file | {
"filepath": "rich/table.py",
"start_line": 750,
"end_line": 850
} | {"status": "ok", "filepath": "rich/table.py", "content": " )\n row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))\n _box = (\n self.box.substitute(\full{"status": "ok", "filepath": "rich/table.py", "content": " )\n row_cells: List[Tuple[_Cell, ...]] = list(zip(*_column_cells))\n _box = (\n self.box.substitute(\n options, safe=pick_bool(self.safe_box, console.safe_box)\n )\n if self.box\n else None\n )\n _box = _box.get_plain_headed_box() if _box and not self.show_header else _box\n\n new_line = Segment.line()\n\n columns = self.columns\n show_header = self.show_header\n show_footer = self.show_footer\n show_edge = self.show_edge\n show_lines = self.show_lines\n leading = self.leading\n\n _Segment = Segment\n if _box:\n box_segments = [\n (\n _Segment(_box.head_left, border_style),\n _Segment(_box.head_right, border_style),\n _Segment(_box.head_vertical, border_style),\n ),\n (\n _Segment(_box.foot_left, border_style),\n _Segment(_box.foot_right, border_style),\n _Segment(_box.foot_vertical, border_style),\n ),\n (\n _Segment(_box.mid_left, border_style),\n _Segment(_box.mid_right, border_style),\n _Segment(_box.mid_vertical, border_style),\n ),\n ]\n if show_edge:\n yield _Segment(_box.get_top(widths), border_style)\n yield new_line\n else:\n box_segments = []\n\n get_row_style = self.get_row_style\n get_style = console.get_style\n\n for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):\n header_row = first and show_header\n footer_row = last and show_footer\n row = (\n self.rows[index - show_header]\n if (not header_row |
| 4 | read_file | {
"end_line": 950,
"filepath": "rich/table.py",
"start_line": 850
} | {"status": "ok", "filepath": "rich/table.py", "content": " _Segment.set_shape(\n align_cell(\n cell,\n _cell.vertical,\n width,\n get_style(_cell.style) + row_sfull{"status": "ok", "filepath": "rich/table.py", "content": " _Segment.set_shape(\n align_cell(\n cell,\n _cell.vertical,\n width,\n get_style(_cell.style) + row_style,\n ),\n width,\n max_height,\n )\n for width, _cell, cell, column in zip(widths, row_cell, cells, columns)\n ]\n\n if _box:\n if last and show_footer:\n yield _Segment(\n _box.get_row(widths, \"foot\", edge=show_edge), border_style\n )\n yield new_line\n left, right, _divider = box_segments[0 if first else (2 if last else 1)]\n\n # If the column divider is whitespace also style it with the row background\n divider = (\n _divider\n if _divider.text.strip()\n else _Segment(\n _divider.text, row_style.background_style + _divider.style\n )\n )\n for line_no in range(max_height):\n if show_edge:\n yield left\n for last_cell, rendered_cell in loop_last(cells):\n yield from rendered_cell[line_no]\n if not last_cell:\n yield divider\n if show_edge:\n yield right\n yield new_line\n else:\n for line_no in range(max_height):\n for rendered_cell in cells:\n yield from rendered_cell[line_no]\n yield new_line\n if _box and first and show_header:\n yield _Segment(\n _box.get_row(widths, \"head\", edge=sh |
| 5 | read_file | {
"end_line": 810,
"filepath": "rich/table.py",
"start_line": 770
} | {"status": "ok", "filepath": "rich/table.py", "content": " _Segment = Segment\n if _box:\n box_segments = [\n (\n _Segment(_box.head_left, border_style),\n _Segfull{"status": "ok", "filepath": "rich/table.py", "content": " _Segment = Segment\n if _box:\n box_segments = [\n (\n _Segment(_box.head_left, border_style),\n _Segment(_box.head_right, border_style),\n _Segment(_box.head_vertical, border_style),\n ),\n (\n _Segment(_box.foot_left, border_style),\n _Segment(_box.foot_right, border_style),\n _Segment(_box.foot_vertical, border_style),\n ),\n (\n _Segment(_box.mid_left, border_style),\n _Segment(_box.mid_right, border_style),\n _Segment(_box.mid_vertical, border_style),\n ),\n ]\n if show_edge:\n yield _Segment(_box.get_top(widths), border_style)\n yield new_line\n else:\n box_segments = []\n\n get_row_style = self.get_row_style\n get_style = console.get_style\n\n for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):\n header_row = first and show_header\n footer_row = last and show_footer\n row = (\n self.rows[index - show_header]\n if (not header_row and not footer_row)\n else None\n )\n max_height = 1\n cells: List[List[List[Segment]]] = []\n if header_row or footer_row:\n row_style = Style.null()\n else:", "start_line": 770, "end_line": 810, "total_lines": 1000, "is_truncated": false} |
| 6 | run_command | {
"command": "cat <<EOF > /tmp/repro.py\nfrom rich.console import Console\nfrom rich.table import Table\nfrom rich.box import Box\n\nconsole = Console(force_terminal=True)\ntable = Table(show_header=True, show_footer=True)\n\n# Custom box characters to verify ordering\nclass CustomBox(Box):\n def __init__(self):\n super().__init__()\n self.head_left = '1'\n self.head_vertical = '2'\n self.head_right = '3'\n\n self.mid_left = '4'\n self.mid_vertical = '5'\n self.mid_right = '6'\n\n self.foot_left = '7'\n self.foot_vertical = '8'\n self.foot_right = '9'\n\ntable.box = CustomBox()\ntable.add_column(\"Date\")\ntable.add_column(\"Title\")\ntable.add_column(\"Production\")\ntable.add_column(\"Box Office\")\n\ntable.add_row(\"Dec 20, 2019\", \"Star Wars: The Rise of Skywalker\", \"$275,000,000\", \"$375,126,118\")\ntable.add_row(\"May 25, 2018\", \"Solo: A Star Wars Story\", \"$275,000,000\", \"$393,151,347\")\ntable.add_row(\"Dec 15, 2017\", \"Star Wars Ep. VIII: The Last Jedi\", \"$262,000,000\", \"$1,332,539,889\")\n\nconsole.print(table)\nEOF\npython3 /tmp/repro.py\n"
} | {"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"/tmp/repro.py\", line 24, in <module>\n table.bofull{"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"/tmp/repro.py\", line 24, in <module>\n table.box = CustomBox()\n ~~~~~~~~~^^\n File \"/tmp/repro.py\", line 11, in __init__\n super().__init__()\n ~~~~~~~~~~~~~~~~^^\nTypeError: Box.__init__() missing 1 required positional argument: 'box'\n", "details": {"stdout": "", "stderr": "Traceback (most recent call last):\n File \"/tmp/repro.py\", line 24, in <module>\n table.box = CustomBox()\n ~~~~~~~~~^^\n File \"/tmp/repro.py\", line 11, in __init__\n super().__init__()\n ~~~~~~~~~~~~~~~~^^\nTypeError: Box.__init__() missing 1 required positional argument: 'box'\n", "exit_code": 1}} |
| 7 | read_file | {
"filepath": "rich/box.py",
"start_line": 1,
"end_line": 50
} | {"status": "ok", "filepath": "rich/box.py", "content": "import sys\nfrom typing import TYPE_CHECKING, Iterable, List\n\nif sys.version_info >= (3, 8):\n from tyfull{"status": "ok", "filepath": "rich/box.py", "content": "import sys\nfrom typing import TYPE_CHECKING, Iterable, List\n\nif sys.version_info >= (3, 8):\n from typing import Literal\nelse:\n from typing_extensions import Literal # pragma: no cover\n\n\nfrom ._loop import loop_last\n\nif TYPE_CHECKING:\n from rich.console import ConsoleOptions\n\n\nclass Box:\n \"\"\"Defines characters to render boxes.\n\n \u250c\u2500\u252c\u2510 top\n \u2502 \u2502\u2502 head\n \u251c\u2500\u253c\u2524 head_row\n \u2502 \u2502\u2502 mid\n \u251c\u2500\u253c\u2524 row\n \u251c\u2500\u253c\u2524 foot_row\n \u2502 \u2502\u2502 foot\n \u2514\u2500\u2534\u2518 bottom\n\n Args:\n box (str): Characters making up box.\n ascii (bool, optional): True if this box uses ascii characters only. Default is False.\n \"\"\"\n\n def __init__(self, box: str, *, ascii: bool = False) -> None:\n self._box = box\n self.ascii = ascii\n line1, line2, line3, line4, line5, line6, line7, line8 = box.splitlines()\n # top\n self.top_left, self.top, self.top_divider, self.top_right = iter(line1)\n # head\n self.head_left, _, self.head_vertical, self.head_right = iter(line2)\n # head_row\n (\n self.head_row_left,\n self.head_row_horizontal,\n self.head_row_cross,\n self.head_row_right,\n ) = iter(line3)\n\n # mid\n self.mid_left, _, self.mid_vertical, self.mid_right = iter(line4)", "start_line": 1, "end_line": 50, "total_lines": 480, "is_truncated": false} |
| 8 | run_command | {
"command": "cat <<EOF > /tmp/repro.py\nfrom rich.console import Console\nfrom rich.table import Table\nfrom rich.box import Box\n\nconsole = Console(force_terminal=True)\ntable = Table(show_header=True, show_footer=True)\n\n# Custom box characters to verify ordering\nclass CustomBox(Box):\n def __init__(self):\n # Use a dummy box string to satisfy the parent __init__\n super().__init__(\"1234\\n5678\\n9012\\n3456\\n7890\\n1234\\n5678\\n9012\")\n self.head_left = '1'\n self.head_vertical = '2'\n self.head_right = '3'\n\n self.mid_left = '4'\n self.mid_vertical = '5'\n self.mid_right = '6'\n\n self.foot_left = '7'\n self.foot_vertical = '8'\n self.foot_right = '9'\n\ntable.box = CustomBox()\ntable.add_column(\"Date\")\ntable.add_column(\"Title\")\ntable.add_column(\"Production\")\ntable.add_column(\"Box Office\")\n\ntable.add_row(\"Dec 20, 2019\", \"Star Wars: The Rise of Skywalker\", \"$275,000,000\", \"$375,126,118\")\ntable.add_row(\"May 25, 2018\", \"Solo: A Star Wars Story\", \"$275,000,000\", \"$393,151,347\")\ntable.add_row(\"Dec 15, 2017\", \"Star Wars Ep. VIII: The Last Jedi\", \"$262,000,000\", \"$1,332,539,889\")\n\nconsole.print(table)\nEOF\npython3 /tmp/repro.py\n"
} | {"status": "ok", "stdout": "12222222222222232222222222222222222222222222222222232222222222223222222222222224\n1 Date 2 Title 2 Production 2 Box Office 3\n900000full{"status": "ok", "stdout": "12222222222222232222222222222222222222222222222222232222222222223222222222222224\n1 Date 2 Title 2 Production 2 Box Office 3\n90000000000000010000000000000000000000000000000000010000000000001000000000000002\n7 Dec 20, 2019 8 Star Wars: The Rise of Skywalker 8 75,000,000 8 75,126,118 9\n7 May 25, 2018 8 Solo: A Star Wars Story 8 75,000,000 8 93,151,347 9\n7 Dec 15, 2017 8 Star Wars Ep. VIII: The Last Jedi 8 62,000,000 8 ,332,539,889 9\n12222222222222232222222222222222222222222222222222232222222222223222222222222224\n4 5 5 5 6\n90000000000000010000000000000000000000000000000000010000000000001000000000000002\n", "stderr": "", "exit_code": 0} |
| 9 | read_file | {
"end_line": 810,
"filepath": "rich/table.py",
"start_line": 770
} | {"status": "ok", "filepath": "rich/table.py", "content": " _Segment = Segment\n if _box:\n box_segments = [\n (\n _Segment(_box.head_left, border_style),\n _Segfull{"status": "ok", "filepath": "rich/table.py", "content": " _Segment = Segment\n if _box:\n box_segments = [\n (\n _Segment(_box.head_left, border_style),\n _Segment(_box.head_right, border_style),\n _Segment(_box.head_vertical, border_style),\n ),\n (\n _Segment(_box.foot_left, border_style),\n _Segment(_box.foot_right, border_style),\n _Segment(_box.foot_vertical, border_style),\n ),\n (\n _Segment(_box.mid_left, border_style),\n _Segment(_box.mid_right, border_style),\n _Segment(_box.mid_vertical, border_style),\n ),\n ]\n if show_edge:\n yield _Segment(_box.get_top(widths), border_style)\n yield new_line\n else:\n box_segments = []\n\n get_row_style = self.get_row_style\n get_style = console.get_style\n\n for index, (first, last, row_cell) in enumerate(loop_first_last(row_cells)):\n header_row = first and show_header\n footer_row = last and show_footer\n row = (\n self.rows[index - show_header]\n if (not header_row and not footer_row)\n else None\n )\n max_height = 1\n cells: List[List[List[Segment]]] = []\n if header_row or footer_row:\n row_style = Style.null()\n else:", "start_line": 770, "end_line": 810, "total_lines": 1000, "is_truncated": false} |
| 10 | read_file | {
"end_line": 870,
"filepath": "rich/table.py",
"start_line": 850
} | {"status": "ok", "filepath": "rich/table.py", "content": " _Segment.set_shape(\n align_cell(\n cell,\n _cell.vertical,\n width,\n get_style(_cell.style) + row_sfull{"status": "ok", "filepath": "rich/table.py", "content": " _Segment.set_shape(\n align_cell(\n cell,\n _cell.vertical,\n width,\n get_style(_cell.style) + row_style,\n ),\n width,\n max_height,\n )\n for width, _cell, cell, column in zip(widths, row_cell, cells, columns)\n ]\n\n if _box:\n if last and show_footer:\n yield _Segment(\n _box.get_row(widths, \"foot\", edge=show_edge), border_style\n )\n yield new_line\n left, right, _divider = box_segments[0 if first else (2 if last else 1)]\n", "start_line": 850, "end_line": 870, "total_lines": 1000, "is_truncated": false} |
| 11 | edit_file | {
"filepath": "rich/table.py",
"new_string": " box_segments = [\n (\n _Segment(_box.head_left, border_style),\n _Segment(_box.head_right, border_style),\n _Segment(_box.head_vertical, border_style),\n ),\n (\n _Segment(_box.mid_left, border_style),\n _Segment(_box.mid_right, border_style),\n _Segment(_box.mid_vertical, border_style),\n ),\n (\n _Segment(_box.foot_left, border_style),\n _Segment(_box.foot_right, border_style),\n _Segment(_box.foot_vertical, border_style),\n ),\n ]",
"old_string": " box_segments = [\n (\n _Segment(_box.head_left, border_style),\n _Segment(_box.head_right, border_style),\n _Segment(_box.head_vertical, border_style),\n ),\n (\n _Segment(_box.foot_left, border_style),\n _Segment(_box.foot_right, border_style),\n _Segment(_box.foot_vertical, border_style),\n ),\n (\n _Segment(_box.mid_left, border_style),\n _Segment(_box.mid_right, border_style),\n _Segment(_box.mid_vertical, border_style),\n ),\n ]"
} | {"status": "ok", "filepath": "rich/table.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/table.py\n+++ b/rich/table.py\n@@ -776,14 +776,14 @@\n full{"status": "ok", "filepath": "rich/table.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/rich/table.py\n+++ b/rich/table.py\n@@ -776,14 +776,14 @@\n _Segment(_box.head_vertical, border_style),\n ),\n (\n+ _Segment(_box.mid_left, border_style),\n+ _Segment(_box.mid_right, border_style),\n+ _Segment(_box.mid_vertical, border_style),\n+ ),\n+ (\n _Segment(_box.foot_left, border_style),\n _Segment(_box.foot_right, border_style),\n _Segment(_box.foot_vertical, border_style),\n- ),\n- (\n- _Segment(_box.mid_left, border_style),\n- _Segment(_box.mid_right, border_style),\n- _Segment(_box.mid_vertical, border_style),\n ),\n ]\n if show_edge:\n", "is_truncated": false} |
| 12 | run_command | {
"command": "python3 /tmp/repro.py"
} | {"status": "ok", "stdout": "12222222222222232222222222222222222222222222222222232222222222223222222222222224\n1 Date 2 Title 2 Production 2 Box Office 3\n900000full{"status": "ok", "stdout": "12222222222222232222222222222222222222222222222222232222222222223222222222222224\n1 Date 2 Title 2 Production 2 Box Office 3\n90000000000000010000000000000000000000000000000000010000000000001000000000000002\n4 Dec 20, 2019 5 Star Wars: The Rise of Skywalker 5 75,000,000 5 75,126,118 6\n4 May 25, 2018 5 Solo: A Star Wars Story 5 75,000,000 5 93,151,347 6\n4 Dec 15, 2017 5 Star Wars Ep. VIII: The Last Jedi 5 62,000,000 5 ,332,539,889 6\n12222222222222232222222222222222222222222222222222232222222222223222222222222224\n7 8 8 8 9\n90000000000000010000000000000000000000000000000000010000000000001000000000000002\n", "stderr": "", "exit_code": 0} |
| 13 | run_command | {
"command": "python3 -m pytest tests/test_table.py -q"
} | {"status": "ok", "stdout": "............... [100%]\n15 passed in 0.14s\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "............... [100%]\n15 passed in 0.14s\n", "stderr": "", "exit_code": 0} |
| 14 | submit_patch | {} | {"status": "ok", "patch_size": 1099, "files_changed": 1}full{"status": "ok", "patch_size": 1099, "files_changed": 1} |
diff --git a/rich/table.py b/rich/table.py
index fe4054cf..44e457be 100644
--- a/rich/table.py
+++ b/rich/table.py
@@ -775,16 +775,16 @@ class Table(JupyterMixin):
_Segment(_box.head_right, border_style),
_Segment(_box.head_vertical, border_style),
),
- (
- _Segment(_box.foot_left, border_style),
- _Segment(_box.foot_right, border_style),
- _Segment(_box.foot_vertical, border_style),
- ),
(
_Segment(_box.mid_left, border_style),
_Segment(_box.mid_right, border_style),
_Segment(_box.mid_vertical, border_style),
),
+ (
+ _Segment(_box.foot_left, border_style),
+ _Segment(_box.foot_right, border_style),
+ _Segment(_box.foot_vertical, border_style),
+ ),
]
if show_edge:
yield _Segment(_box.get_top(widths), border_style)
................... [100%] 19 passed in 0.13s