resolved RESOLVED PASS · 14 tool calls · 109 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 -n \"mid_left\\|mid_right\\|mid_vertical\\|foot_left\\|foot_right\\|foot_vertical\" /workspace/rich/table.py | head -40"
} | {"status": "ok", "stdout": "", "exit_code": 0}full{"status": "ok", "stdout": "", "exit_code": 0} |
| 2 | run_command | {
"command": "ls /workspace/rich/ | head; grep -rn \"mid_left\" /workspace/rich/ | head -20"
} | {"status": "ok", "stdout": "", "exit_code": 0}full{"status": "ok", "stdout": "", "exit_code": 0} |
| 3 | run_command | {
"command": "ls /workspace; echo ---; ls /workspace/rich 2>&1 | head"
} | {"status": "ok", "stdout": "---\nls: /tmp/swe_work/or20_qwen27b_v2/rich_2725/a/workspace/rich: No such file or directory\n", "exit_code": 0}full{"status": "ok", "stdout": "---\nls: /tmp/swe_work/or20_qwen27b_v2/rich_2725/a/workspace/rich: No such file or directory\n", "exit_code": 0} |
| 4 | run_command | {
"command": "pwd; ls -la; find / -name \"table.py\" -path \"*rich*\" 2>/dev/null | head"
} | {"status": "ok", "stdout": "/private/workspace\ntotal 1208\ndrwx------@ 53 jp wheel 1696 Sep 23 22:41 .\ndrwxr-xr-x@ 4 jp wheel 128 Sep 23 22:41 ..\n-rw-r--r--@full{"status": "ok", "stdout": "/private/workspace\ntotal 1208\ndrwx------@ 53 jp wheel 1696 Sep 23 22:41 .\ndrwxr-xr-x@ 4 jp wheel 128 Sep 23 22:41 ..\n-rw-r--r--@ 1 jp wheel 204 Jul 15 10:02 .coveragerc\ndrwxr-xr-x@ 4 jp wheel 128 Jul 15 10:02 .faq\ndrwxr-xr-x@ 12 jp wheel 384 Sep 23 22:41 .git\ndrwxr-xr-x@ 7 jp wheel 224 Jul 15 10:02 .github\n-rw-r--r--@ 1 jp wheel 1375 Jul 15 10:02 .gitignore\n-rw-r--r--@ 1 jp wheel 1258 Jul 15 10:02 .pre-commit-config.yaml\n-rw-r--r--@ 1 jp wheel 432 Jul 15 10:02 .readthedocs.yml\ndrwxr-xr-x@ 5 jp wheel 160 Jul 15 10:02 assets\n-rw-r--r--@ 1 jp wheel 860 Jul 15 10:02 asv.conf.json\n-rw-r--r--@ 1 jp wheel 182 Jul 15 10:02 asvhashfile\ndrwxr-xr-x@ 7 jp wheel 224 Jul 15 10:02 benchmarks\n-rw-r--r--@ 1 jp wheel 66509 Jul 15 10:02 CHANGELOG.md\n-rw-r--r--@ 1 jp wheel 3350 Jul 15 10:02 CODE_OF_CONDUCT.md\n-rw-r--r--@ 1 jp wheel 5840 Jul 15 10:02 CONTRIBUTING.md\n-rw-r--r--@ 1 jp wheel 3650 Jul 15 10:02 CONTRIBUTORS.md\ndrwxr-xr-x@ 7 jp wheel 224 Jul 15 10:02 docs\ndrwxr-xr-x@ 39 jp wheel 1248 Jul 15 10:02 examples\n-rw-r--r--@ 1 jp wheel 5137 Jul 15 10:02 FAQ.md\n-rw-r--r--@ 1 jp wheel 298 Jul 15 10:02 faq.yml\ndrwxr-xr-x@ 24 jp wheel 768 Jul 15 10:02 imgs\n-rw-r--r--@ 1 jp wheel 1056 Jul 15 10:02 LICENSE\n-rw-r--r--@ 1 jp wheel 799 Jul 15 10:02 make.bat\n-rw-r--r--@ 1 jp wheel 307 Jul 15 10:02 Makefile\n-rw-r--r--@ 1 jp wheel 57783 Jul 15 10:02 poetry.lock\n-rw-r--r--@ 1 jp wheel 1875 Jul 15 10:02 pyproject.toml\n-rw-r--r--@ 1 jp wheel 109 Sep 23 22:41 pytest.ini\ndrwxr-xr-x@ 11 jp wheel 352 Jul 15 10:02 questions\n-rw-r--r--@ 1 jp wheel 17198 Jul 15 10:02 README.cn.md\n-rw-r--r--@ 1 jp wheel 18800 Jul 15 10:02 README.de-ch.md\n-rw-r--r--@ 1 jp wheel 20223 Jul 15 10:02 README.de.md\n-rw-r--r--@ 1 jp wheel 19598 Jul 15 10:02 README.es.md\n-rw-r--r--@ 1 jp wheel 23033 Jul 15 10:02 README.fa.md\n-rw-r |
| 5 | run_command | {
"command": "grep -n \"mid_left\\|mid_right\\|mid_vertical\\|foot_left\\|foot_right\\|foot_vertical\\|head_left\\|head_right\\|head_vertical\" /private/workspace/rich/table.py"
} | {"status": "error", "error_type": "CommandError", "error_message": "Command failed with exit code 2", "details": {"stdout": "", "stderr": "grep: /private/workspfull{"status": "error", "error_type": "CommandError", "error_message": "Command failed with exit code 2", "details": {"stdout": "", "stderr": "grep: /private/workspace/rich/table.py: No such file or directory\n", "exit_code": 2}} |
| 6 | run_command | {
"command": "ls rich/ | head -30; grep -n \"mid_left\\|mid_right\\|mid_vertical\\|foot_left\\|foot_right\\|foot_vertical\" rich/table.py"
} | {"status": "ok", "stdout": "__init__.py\n__main__.py\n_cell_widths.py\n_emoji_codes.py\n_emoji_replace.py\n_export_format.py\n_extension.py\n_fileno.py\n_inspecfull{"status": "ok", "stdout": "__init__.py\n__main__.py\n_cell_widths.py\n_emoji_codes.py\n_emoji_replace.py\n_export_format.py\n_extension.py\n_fileno.py\n_inspect.py\n_log_render.py\n_loop.py\n_null_file.py\n_palettes.py\n_pick.py\n_ratio.py\n_spinners.py\n_stack.py\n_timer.py\n_win32_console.py\n_windows_renderer.py\n_windows.py\n_wrap.py\nabc.py\nalign.py\nansi.py\nbar.py\nbox.py\ncells.py\ncolor_triplet.py\ncolor.py\n779: _Segment(_box.foot_left, border_style),\n780: _Segment(_box.foot_right, border_style),\n781: _Segment(_box.foot_vertical, border_style),\n784: _Segment(_box.mid_left, border_style),\n785: _Segment(_box.mid_right, border_style),\n786: _Segment(_box.mid_vertical, border_style),\n", "exit_code": 0} |
| 7 | read_file | {
"filepath": "rich/table.py",
"start_line": 755,
"end_line": 800
} | {"status": "ok", "filepath": "rich/table.py", "content": " )\n if self.box\n else None\n )\n _box = _box.get_plain_headed_box() if _box and not self.show_headerfull{"status": "ok", "filepath": "rich/table.py", "content": " )\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", "start_line": 755, "end_line": 800, "total_lines": 1000, "is_truncated": false} |
| 8 | read_file | {
"filepath": "rich/table.py",
"start_line": 800,
"end_line": 880
} | {"status": "ok", "filepath": "rich/table.py", "content": " footer_row = last and show_footer\n row = (\n self.rows[index - show_header]\n if (not header_row andfull{"status": "ok", "filepath": "rich/table.py", "content": " 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:\n row_style = get_style(\n get_row_style(console, index - 1 if show_header else index)\n )\n for width, cell, column in zip(widths, row_cell, columns):\n render_options = options.update(\n width=width,\n justify=column.justify,\n no_wrap=column.no_wrap,\n overflow=column.overflow,\n height=None,\n )\n lines = console.render_lines(\n cell.renderable,\n render_options,\n style=get_style(cell.style) + row_style,\n )\n max_height = max(max_height, len(lines))\n cells.append(lines)\n\n row_height = max(len(cell) for cell in cells)\n\n def align_cell(\n cell: List[List[Segment]],\n vertical: \"VerticalAlignMethod\",\n width: int,\n style: Style,\n ) -> List[List[Segment]]:\n if header_row:\n vertical = \"bottom\"\n elif footer_row:\n vertical = \"top\"\n\n if vertical == \"top\":\n return _Segment.align_top(cell, width, row_height, style)\n elif vertical == \"middle\":\n return _Segment.align_middle(cell, width, row_height, style)\n return _Segment.align_bottom(cell, width, row_height, style) |
| 9 | run_command | {
"command": "grep -n \"def get_row\\|def get_top\\|def get_bottom\\|def get_plain_headed_box\" rich/box.py"
} | {"status": "ok", "stdout": "91: def get_plain_headed_box(self) -> \"Box\":\n101: def get_top(self, widths: Iterable[int]) -> str:\n121: def get_row(\n170: def gfull{"status": "ok", "stdout": "91: def get_plain_headed_box(self) -> \"Box\":\n101: def get_top(self, widths: Iterable[int]) -> str:\n121: def get_row(\n170: def get_bottom(self, widths: Iterable[int]) -> str:\n", "exit_code": 0} |
| 10 | read_file | {
"filepath": "rich/box.py",
"start_line": 85,
"end_line": 175
} | {"status": "ok", "filepath": "rich/box.py", "content": " if options.legacy_windows and safe:\n box = LEGACY_WINDOWS_SUBSTITUTIONS.get(box, box)\n if options.ascfull{"status": "ok", "filepath": "rich/box.py", "content": " if options.legacy_windows and safe:\n box = LEGACY_WINDOWS_SUBSTITUTIONS.get(box, box)\n if options.ascii_only and not box.ascii:\n box = ASCII\n return box\n\n def get_plain_headed_box(self) -> \"Box\":\n \"\"\"If this box uses special characters for the borders of the header, then\n return the equivalent box that does not.\n\n Returns:\n Box: The most similar Box that doesn't use header-specific box characters.\n If the current Box already satisfies this criterion, then it's returned.\n \"\"\"\n return PLAIN_HEADED_SUBSTITUTIONS.get(self, self)\n\n def get_top(self, widths: Iterable[int]) -> str:\n \"\"\"Get the top of a simple box.\n\n Args:\n widths (List[int]): Widths of columns.\n\n Returns:\n str: A string of box characters.\n \"\"\"\n\n parts: List[str] = []\n append = parts.append\n append(self.top_left)\n for last, width in loop_last(widths):\n append(self.top * width)\n if not last:\n append(self.top_divider)\n append(self.top_right)\n return \"\".join(parts)\n\n def get_row(\n self,\n widths: Iterable[int],\n level: Literal[\"head\", \"row\", \"foot\", \"mid\"] = \"row\",\n edge: bool = True,\n ) -> str:\n \"\"\"Get the top of a simple box.\n\n Args:\n width (List[int]): Widths of columns.\n\n Returns:\n str: A string of box characters.\n \"\"\"\n if level == \"head\":\n left = self.head_row_left\n horizontal = self.head_row_horizontal\n cross = self.head_row_cross\n right = self.head_row_right\n elif level == \"row\":\n left = self.row_left\n horizontal = self.row_horizontal\n cross = self.r |
| 11 | edit_file | {
"filepath": "rich/table.py",
"old_string": " (\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 ),",
"new_string": " (\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 ),"
} | {"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": "cat > /tmp/check.py <<'EOF'\nfrom rich.console import Console\nfrom rich.table import Table\n\ntable = Table()\ntable.add_column(\"Date\")\ntable.add_column(\"Title\")\ntable.add_column(\"Production\")\ntable.add_column(\"Box Office\")\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\ntable.box.head_left = '1'\ntable.box.head_vertical = '2'\ntable.box.head_right = '3'\ntable.box.mid_left = '4'\ntable.box.mid_vertical = '5'\ntable.box.mid_right = '6'\ntable.box.foot_left = '7'\ntable.box.foot_vertical = '8'\ntable.box.foot_right = '9'\n\nconsole = Console(width=80, force_terminal=False)\nconsole.print(table)\nEOF\npython3 /tmp/check.py"
} | {"status": "ok", "stdout": "\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501full{"status": "ok", "stdout": "\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n1 Date 2 Title 2 Production 2 Box Office 3\n\u2521\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2529\n4 Dec 20, 2019 5 Star Wars: The Rise of 5 $275,000,000 5 $375,126,118 6\n4 5 Skywalker 5 5 6\n4 May 25, 2018 5 Solo: A Star Wars Story 5 $275,000,000 5 $393,151,347 6\n7 Dec 15, 2017 8 Star Wars Ep. VIII: The Last 8 $262,000,000 8 $1,332,539,889 9\n7 8 Jedi 8 8 9\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n", "exit_code": 0} |
| 13 | run_command | {
"command": "python -m pytest tests/test_table.py tests/test_box.py -q 2>&1 | tail -5"
} | {"status": "ok", "stdout": "..................... [100%]\n21 passed in 0.12s\n", "exit_code": 0}full{"status": "ok", "stdout": "..................... [100%]\n21 passed in 0.12s\n", "exit_code": 0} |
| 14 | run_command | {
"command": "grep -n \"box_segments\" rich/table.py; git diff"
} | {"status": "ok", "stdout": "772: box_segments = [\n793: box_segments = []\n869: left, right, _divider = box_segments[0 if first else (2 if last else 1)]\ndiff -full{"status": "ok", "stdout": "772: box_segments = [\n793: box_segments = []\n869: left, right, _divider = box_segments[0 if first else (2 if last else 1)]\ndiff --git a/rich/table.py b/rich/table.py\nindex fe4054cf..44e457be 100644\n--- a/rich/table.py\n+++ b/rich/table.py\n@@ -775,16 +775,16 @@ class Table(JupyterMixin):\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+ _Segment(_box.foot_left, border_style),\n+ _Segment(_box.foot_right, border_style),\n+ _Segment(_box.foot_vertical, border_style),\n+ ),\n ]\n if show_edge:\n yield _Segment(_box.get_top(widths), border_style)\n", "exit_code": 0} |
| 15 | 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.12s