resolved RESOLVED LOOP PASS · 17 tool calls · 202 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 \"box\" --include=*.py rich | grep \"table\" | head -20"
} | {"status": "ok", "stdout": "rich/table.py:14:from . import box, errors\nrich/table.py:47: box (box.Box, optional): One of the constants in box.py used to draw tfull{"status": "ok", "stdout": "rich/table.py:14:from . import box, errors\nrich/table.py:47: box (box.Box, optional): One of the constants in box.py used to draw the edges (see :ref:`appendix_box`), or ``None`` for no box lines. Defaults to box.HEAVY_HEAD.\nrich/table.py:48: safe_box (Optional[bool], optional): Disable box characters that don't display on windows legacy terminal with *raster* fonts. Defaults to True.\nrich/table.py:55: show_edge (bool, optional): Draw a box around the outside of the table. Defaults to True.\nrich/table.py:160: box (box.Box, optional): One of the constants in box.py used to draw the edges (see :ref:`appendix_box`), or ``None`` for no box lines. Defaults to box.HEAVY_HEAD.\nrich/table.py:161: safe_box (Optional[bool], optional): Disable box characters that don't display on windows legacy terminal with *raster* fonts. Defaults to True.\nrich/table.py:168: show_edge (bool, optional): Draw a box around the outside of the table. Defaults to True.\nrich/table.py:193: box: Optional[box.Box] = box.HEAVY_HEAD,\nrich/table.py:194: safe_box: Optional[bool] = None,\nrich/table.py:221: self.box = box\nrich/table.py:222: self.safe_box = safe_box\nrich/table.py:273: box=None,\nrich/table.py:297: if self.box and self.show_edge:\nrich/table.py:299: if self.box:\nrich/table.py:752: _box = (\nrich/table.py:753: self.box.substitute(\nrich/table.py:754: options, safe=pick_bool(self.safe_box, console.safe_box)\nrich/table.py:756: if self.box\nrich/table.py:759: _box = _box.get_plain_headed_box() if _box and not self.show_header else _box\nrich/table.py:771: if _box:\n", "stderr": "", "exit_code": 0} |
| 2-5 ×4 | run_command | {
"command": "grep -n \"box\" rich/table.py | grep -C 5 \"render\" | head -40"
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 6 | run_command | {
"command": "grep -n \"box\" rich/table.py | head -40"
} | {"status": "ok", "stdout": "14:from . import box, errors\n47: box (box.Box, optional): One of the constants in box.py used to draw the edges (see :ref:`appendixfull{"status": "ok", "stdout": "14:from . import box, errors\n47: box (box.Box, optional): One of the constants in box.py used to draw the edges (see :ref:`appendix_box`), or ``None`` for no box lines. Defaults to box.HEAVY_HEAD.\n48: safe_box (Optional[bool], optional): Disable box characters that don't display on windows legacy terminal with *raster* fonts. Defaults to True.\n55: show_edge (bool, optional): Draw a box around the outside of the table. Defaults to True.\n160: box (box.Box, optional): One of the constants in box.py used to draw the edges (see :ref:`appendix_box`), or ``None`` for no box lines. Defaults to box.HEAVY_HEAD.\n161: safe_box (Optional[bool], optional): Disable box characters that don't display on windows legacy terminal with *raster* fonts. Defaults to True.\n168: show_edge (bool, optional): Draw a box around the outside of the table. Defaults to True.\n193: box: Optional[box.Box] = box.HEAVY_HEAD,\n194: safe_box: Optional[bool] = None,\n221: self.box = box\n222: self.safe_box = safe_box\n273: box=None,\n297: if self.box and self.show_edge:\n299: if self.box:\n752: _box = (\n753: self.box.substitute(\n754: options, safe=pick_bool(self.safe_box, console.safe_box)\n756: if self.box\n759: _box = _box.get_plain_headed_box() if _box and not self.show_header else _box\n771: if _box:\n772: box_segments = [\n774: _Segment(_box.head_left, border_style),\n775: _Segment(_box.head_right, border_style),\n776: _Segment(_box.head_vertical, border_style),\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: _Se |
| 7 | run_command | {
"command": "sed -n '770,795p' rich/table.py"
} | {"status": "ok", "stdout": " _Segment = Segment\n if _box:\n box_segments = [\n (\n _Segment(_box.head_left, border_style),\n _Segment(_box.head_right, border_sfull{"status": "ok", "stdout": " _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", "stderr": "", "exit_code": 0} |
| 8 | run_command | {
"command": "sed -n '860,920p' rich/table.py"
} | {"status": "ok", "stdout": " 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 _Segmenfull{"status": "ok", "stdout": " 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=show_edge), border_style\n )\n yield new_line\n end_section = row and row.end_section\n if _box and (show_lines or leading or end_section):\n if (\n not last\n and not (show_footer and index >= len(row_cells) - 2)\n and not (show_header and header |
| 9 | run_command | {
"command": "cat <<EOF > /tmp/repro.py\nfrom rich.table import Table\nfrom rich.console import Console\nfrom rich import box\n\nconsole = Console(force_terminal=True)\ntable = Table(box=box.Box())\ntable.box.head_left = '1'\ntable.box.head_vertical = '2'\ntable.box.head_right = '3'\n\ntable.box.mid_left = '4'\ntable.box.mid_vertical = '5'\ntable.box.mid_right = '6'\n\ntable.box.foot_left = '7'\ntable.box.foot_vertical = '8'\ntable.box.foot_right = '9'\n\ntable.add_column(\"Date\")\ntable.add_column(\"Title\")\ntable.add_column(\"Budget\")\ntable.add_column(\"Box Office\")\n\ntable.add_row(\"Dec 20, 2019\", \"Star Wars: The Rise of Skywalker\", \"\\$275,000,000\", \"\\$375,126,188\")\ntable.add_row(\"May 25, 2018\", \"Solo: A Star Wars Story\", \"\\$275,000,000\", \"\\$393,147,000\")\ntable.add_row(\"Dec 15, 2017\", \"Star Wars: The Last Jedi\", \"\\$262,000,000\", \"\\$1,332,539,899\")\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 6, in <module>\n table = Tfull{"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"/tmp/repro.py\", line 6, in <module>\n table = Table(box=box.Box())\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 6, in <module>\n table = Table(box=box.Box())\n ~~~~~~~^^\nTypeError: Box.__init__() missing 1 required positional argument: 'box'\n", "exit_code": 1}} |
| 10 | run_command | {
"command": "grep -n \"class Box\" rich/box.py"
} | {"status": "ok", "stdout": "16:class Box:\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "16:class Box:\n", "stderr": "", "exit_code": 0} |
| 11 | run_command | {
"command": "sed -n '16,50p' rich/box.py"
} | {"status": "ok", "stdout": "class Box:\n \"\"\"Defines characters to render boxes.\n\n \u250c\u2500\u252c\u2510 top\n \u2502 \u2502\u2502 head\n \u251c\u2500\u2full{"status": "ok", "stdout": "class 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)\n", "stderr": "", "exit_code": 0} |
| 12 | run_command | {
"command": "cat <<EOF > /tmp/repro.py\nfrom rich.table import Table\nfrom rich.console import Console\nfrom rich import box\n\nconsole = Console(force_terminal=True)\n# Use a custom box string to create a Box object\ncustom_box_str = (\n \"TL T TD TR\\n\"\n \"HL V HV HR\\n\"\n \"HRL HH HC HRR\\n\"\n \"ML V MV MR\\n\"\n \"RL RH RC RR\\n\"\n \"FL V FV FR\\n\"\n \"FRL FH FC FRR\\n\"\n \"BL B BD BR\"\n)\ntable = Table(box=box.Box(custom_box_str))\ntable.box.head_left = '1'\ntable.box.head_vertical = '2'\ntable.box.head_right = '3'\n\ntable.box.mid_left = '4'\ntable.box.mid_vertical = '5'\ntable.box.mid_right = '6'\n\ntable.box.foot_left = '7'\ntable.box.foot_vertical = '8'\ntable.box.foot_right = '9'\n\ntable.add_column(\"Date\")\ntable.add_column(\"Title\")\ntable.add_column(\"Budget\")\ntable.add_column(\"Box Office\")\n\ntable.add_row(\"Dec 20, 2019\", \"Star Wars: The Rise of Skywalker\", \"\\$275,000,000\", \"\\$375,126,188\")\ntable.add_row(\"May 25, 2018\", \"Solo: A Star Wars Story\", \"\\$275,000,000\", \"\\$393,147,000\")\ntable.add_row(\"Dec 15, 2017\", \"Star Wars: The Last Jedi\", \"\\$262,000,000\", \"\\$1,332,539,899\")\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 17, in <module>\n table = full{"status": "error", "error_type": "CommandError", "error_message": "Traceback (most recent call last):\n File \"/tmp/repro.py\", line 17, in <module>\n table = Table(box=box.Box(custom_box_str))\n ~~~~~~~^^^^^^^^^^^^^^^^\n File \"/workspace/rich/box.py\", line 38, in __init__\n self.top_left, self.top, self.top_divider, self.top_right = iter(line1)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nValueError: too many values to unpack (expected 4)\n", "details": {"stdout": "", "stderr": "Traceback (most recent call last):\n File \"/tmp/repro.py\", line 17, in <module>\n table = Table(box=box.Box(custom_box_str))\n ~~~~~~~^^^^^^^^^^^^^^^^\n File \"/workspace/rich/box.py\", line 38, in __init__\n self.top_left, self.top, self.top_divider, self.top_right = iter(line1)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nValueError: too many values to unpack (expected 4)\n", "exit_code": 1}} |
| 13 | run_command | {
"command": "cat <<EOF > /tmp/repro.py\nfrom rich.table import Table\nfrom rich.console import Console\nfrom rich import box\n\nconsole = Console(force_terminal=True)\n# Use a custom box string to create a Box object. \n# Each line must have exactly 4 characters.\ncustom_box_str = (\n \"1234\\n\"\n \"5678\\n\"\n \"90ab\\n\"\n \"cdef\\n\"\n \"ghij\\n\"\n \"klmn\\n\"\n \"opqr\\n\"\n \"stuv\"\n)\ntable = Table(box=box.Box(custom_box_str))\ntable.box.head_left = '1'\ntable.box.head_vertical = '2'\ntable.box.head_right = '3'\n\ntable.box.mid_left = '4'\ntable.box.mid_vertical = '5'\ntable.box.mid_right = '6'\n\ntable.box.foot_left = '7'\ntable.box.foot_vertical = '8'\ntable.box.foot_right = '9'\n\ntable.add_column(\"Date\")\ntable.add_column(\"Title\")\ntable.add_column(\"Budget\")\ntable.add_column(\"Box Office\")\n\ntable.add_row(\"Dec 20, 2019\", \"Star Wars: The Rise of Skywalker\", \"\\$275,000,000\", \"\\$375,126,188\")\ntable.add_row(\"May 25, 2018\", \"Solo: A Star Wars Story\", \"\\$275,000,000\", \"\\$393,147,000\")\ntable.add_row(\"Dec 15, 2017\", \"Star Wars: The Last Jedi\", \"\\$262,000,000\", \"\\$1,332,539,899\")\n\nconsole.print(table)\nEOF\npython3 /tmp/repro.py\n"
} | {"status": "ok", "stdout": "12222222222222232222222222222222222222222222222322222222222222322222222222222224\n1 Date 2 Title 2 Budget 2 Box Office 3\n9000000000full{"status": "ok", "stdout": "12222222222222232222222222222222222222222222222322222222222222322222222222222224\n1 Date 2 Title 2 Budget 2 Box Office 3\n900000000000000a0000000000000000000000000000000a00000000000000a0000000000000000b\n7 Dec 20, 2019 8 Star Wars: The Rise of 8 $275,000,000 8 $375,126,188 9\n7 8 Skywalker 8 8 9\n7 May 25, 2018 8 Solo: A Star Wars Story 8 $275,000,000 8 $393,147,000 9\n4 Dec 15, 2017 5 Star Wars: The Last Jedi 5 $262,000,000 5 $1,332,539,899 6\nsttttttttttttttutttttttttttttttttttttttttttttttuttttttttttttttuttttttttttttttttv\n", "stderr": "", "exit_code": 0} |
| 14 | edit_file | {
"filepath": "rich/table.py",
"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 ),",
"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 ),"
} | {"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} |
| 15 | run_command | {
"command": "python3 /tmp/repro.py"
} | {"status": "ok", "stdout": "12222222222222232222222222222222222222222222222322222222222222322222222222222224\n1 Date 2 Title 2 Budget 2 Box Office 3\n9000000000full{"status": "ok", "stdout": "12222222222222232222222222222222222222222222222322222222222222322222222222222224\n1 Date 2 Title 2 Budget 2 Box Office 3\n900000000000000a0000000000000000000000000000000a00000000000000a0000000000000000b\n4 Dec 20, 2019 5 Star Wars: The Rise of 5 $275,000,000 5 $375,126,188 6\n4 5 Skywalker 5 5 6\n4 May 25, 2018 5 Solo: A Star Wars Story 5 $275,000,000 5 $393,147,000 6\n7 Dec 15, 2017 8 Star Wars: The Last Jedi 8 $262,000,000 8 $1,332,539,899 9\nsttttttttttttttutttttttttttttttttttttttttttttttuttttttttttttttuttttttttttttttttv\n", "stderr": "", "exit_code": 0} |
| 16 | run_command | {
"command": "cd /workspace && git status --short && git diff --stat"
} | {"status": "ok", "stdout": " M rich/table.py\n rich/table.py | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": " M rich/table.py\n rich/table.py | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n", "stderr": "", "exit_code": 0} |
| 17 | run_command | {
"command": "python3 -c \"import rich.table\""
} | {"status": "ok", "stdout": "", "stderr": "", "exit_code": 0}full{"status": "ok", "stdout": "", "stderr": "", "exit_code": 0} |
| 18 | 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.19s