Skip to content

Commit c59ee9f

Browse files
committed
Update documentation
1 parent b7c5c61 commit c59ee9f

File tree

6 files changed

+104
-23
lines changed

6 files changed

+104
-23
lines changed

Diff for: README.md

+34
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,40 @@ print(output)
159159
"""
160160
```
161161

162+
### 🪄 Merge adjacent cells
163+
164+
```py
165+
from table2ascii import table2ascii, Merge, PresetStyle
166+
167+
output = table2ascii(
168+
header=["#", "G", "Merge", Merge.LEFT, "S"],
169+
body=[
170+
[1, 5, 6, 200, Merge.LEFT],
171+
[2, "E", "Long cell", Merge.LEFT, Merge.LEFT],
172+
["Bonus", Merge.LEFT, Merge.LEFT, "F", "G"],
173+
],
174+
footer=["SUM", "100", "200", Merge.LEFT, "300"],
175+
style=PresetStyle.double_thin_box,
176+
first_col_heading=True,
177+
)
178+
179+
print(output)
180+
181+
"""
182+
╔═════╦═════╤═══════╤═════╗
183+
║ # ║ G │ Merge │ S ║
184+
╠═════╬═════╪═══╤═══╧═════╣
185+
║ 1 ║ 5 │ 6 │ 200 ║
186+
╟─────╫─────┼───┴─────────╢
187+
║ 2 ║ E │ Long cell ║
188+
╟─────╨─────┴───┬───┬─────╢
189+
║ Bonus │ F │ G ║
190+
╠═════╦═════╤═══╧═══╪═════╣
191+
║ SUM ║ 100 │ 200 │ 300 ║
192+
╚═════╩═════╧═══════╧═════╝
193+
"""
194+
```
195+
162196
## ⚙️ Options
163197

164198
All parameters are optional.

Diff for: docs/source/api.rst

+7
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,31 @@
33
API Reference
44
=============
55

6+
.. _table2ascii:
7+
68
table2ascii
79
~~~~~~~~~~~
810

911
.. autofunction:: table2ascii
1012

13+
.. _Alignment:
1114

1215
Alignment
1316
~~~~~~~~~
1417

1518
.. autoenum:: Alignment
1619
:members:
1720

21+
.. _Merge:
22+
1823
Merge
1924
~~~~~
2025

2126
.. autoenum:: Merge
2227
:members:
2328

29+
.. _PresetStyle:
30+
2431
PresetStyle
2532
~~~~~~~~~~~
2633

Diff for: docs/source/usage.rst

+42-5
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ Set column widths and alignments
5959
header=["#", "G", "H", "R", "S"],
6060
body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]],
6161
first_col_heading=True,
62-
column_widths=[5] * 5, # [5, 5, 5, 5, 5]
63-
alignments=[Alignment.LEFT] + [Alignment.RIGHT] * 4, # First is left, remaining 4 are right
62+
column_widths=[5, 5, 5, 5, 5],
63+
alignments=[Alignment.LEFT] + [Alignment.RIGHT] * 4,
6464
)
6565
6666
print(output)
@@ -84,7 +84,7 @@ Use a preset style
8484
output = table2ascii(
8585
header=["First", "Second", "Third", "Fourth"],
8686
body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]],
87-
column_widths=[10] * 4,
87+
column_widths=[10, 10, 10, 10],
8888
style=PresetStyle.ascii_box
8989
)
9090
@@ -130,7 +130,7 @@ Check :ref:`TableStyle` for more info.
130130
output = table2ascii(
131131
header=["First", "Second", "Third"],
132132
body=[["10", "30", "40"], ["20", "10", "20"], ["30", "20", "30"]],
133-
style=my_style
133+
style=my_style,
134134
)
135135
136136
print(output)
@@ -143,4 +143,41 @@ Check :ref:`TableStyle` for more info.
143143
| 20 : 10 : 20 |
144144
| 30 : 20 : 30 |
145145
*-------'--------'-------*
146-
"""
146+
"""
147+
148+
Merge adjacent cells
149+
~~~~~~~~~~~~~~~~~~~~
150+
151+
Check :ref:`Merge` for more info.
152+
153+
.. code:: py
154+
155+
from table2ascii import table2ascii, Merge, PresetStyle
156+
157+
output = table2ascii(
158+
header=["#", "G", "Merge", Merge.LEFT, "S"],
159+
body=[
160+
[1, 5, 6, 200, Merge.LEFT],
161+
[2, "E", "Long cell", Merge.LEFT, Merge.LEFT],
162+
["Bonus", Merge.LEFT, Merge.LEFT, "F", "G"],
163+
],
164+
footer=["SUM", "100", "200", Merge.LEFT, "300"],
165+
style=PresetStyle.double_thin_box,
166+
first_col_heading=True,
167+
)
168+
169+
print(output)
170+
171+
"""
172+
╔═════╦═════╤═══════╤═════╗
173+
║ # ║ G │ Merge │ S ║
174+
╠═════╬═════╪═══╤═══╧═════╣
175+
║ 1 ║ 5 │ 6 │ 200 ║
176+
╟─────╫─────┼───┴─────────╢
177+
║ 2 ║ E │ Long cell ║
178+
╟─────╨─────┴───┬───┬─────╢
179+
║ Bonus │ F │ G ║
180+
╠═════╦═════╤═══╧═══╪═════╣
181+
║ SUM ║ 100 │ 200 │ 300 ║
182+
╚═════╩═════╧═══════╧═════╝
183+
"""

Diff for: table2ascii/merge.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,30 @@ class Merge(Enum):
88
with the cell to its left.
99
1010
In the case that the contents of the merged cell are longer than the
11-
contents of the unmerged cells in the rows above and below, the merged
12-
cell will be wrapped onto multiple lines.
11+
combined widths of the unmerged cells in the rows above and below,
12+
the merged cell will be wrapped onto multiple lines. The ``column_widths``
13+
option can be used to control the widths of the unmerged cells.
1314
1415
Example::
1516
1617
from table2ascii import table2ascii, Merge, PresetStyle
1718
1819
table2ascii(
19-
body=[
20-
["A", "B", "C", "D"],
21-
["E", "Long cell contents", Merge.LEFT, Merge.LEFT],
22-
],
20+
header=["Name", "Price", "Category", "Stock"],
21+
body=[["Milk", "$2.99", "N/A", Merge.LEFT]],
22+
footer=["Description", "Milk is a nutritious beverage", Merge.LEFT, Merge.LEFT],
2323
style=PresetStyle.double_box,
2424
)
2525
2626
\"\"\"
27-
╔═══╦═══╦═══╦═══╗
28-
║ A ║ B ║ C ║ D ║
29-
╠═══╬═══╩═══╩═══╣
30-
║ E ║ Long cell ║
31-
║ ║ contents ║
32-
╚═══╩═══════════╝
27+
╔═════════════╦═══════╦══════════╦═══════╗
28+
║ Name ║ Price ║ Category ║ Stock ║
29+
╠═════════════╬═══════╬══════════╩═══════╣
30+
║ Milk ║ $2.99 ║ N/A ║
31+
╠═════════════╬═══════╩══════════════════╣
32+
║ Description ║ Milk is a nutritious ║
33+
║ ║ beverage ║
34+
╚═════════════╩══════════════════════════╝
3335
\"\"\"
3436
3537
.. versionadded:: 1.0.0

Diff for: table2ascii/table_style.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class TableStyle:
66
"""Class for storing information about a table style
77
8-
Parts of the table labeled alphabetically:
8+
Parts of the table labeled alphabetically from A to V:
99
1010
.. code-block::
1111
@@ -58,9 +58,10 @@ class TableStyle:
5858
5959
.. versionchanged:: 1.0.0
6060
61-
Added fields for ``col_row_top_tee``, ``col_row_bottom_tee``, ``heading_row_top_tee``,
62-
``heading_row_bottom_tee``, ``heading_col_body_row_top_tee``, ``heading_col_body_row_bottom_tee``,
63-
``heading_col_heading_row_top_tee``, ``heading_col_heading_row_bottom_tee``
61+
Added fields for edges of merged cells -- ``col_row_top_tee``, ``col_row_bottom_tee``,
62+
``heading_row_top_tee``, ``heading_row_bottom_tee``, ``heading_col_body_row_top_tee``,
63+
``heading_col_body_row_bottom_tee``, ``heading_col_heading_row_top_tee``,
64+
``heading_col_heading_row_bottom_tee``
6465
"""
6566

6667
# parts of the table

Diff for: tests/test_merge.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_merge_line_wrap():
9595
],
9696
footer=[
9797
"Description",
98-
"Long cell value that is merge and wraps to multiple lines",
98+
"Long cell value that is merged and wraps to multiple lines",
9999
Merge.LEFT,
100100
Merge.LEFT,
101101
Merge.LEFT,
@@ -109,7 +109,7 @@ def test_merge_line_wrap():
109109
"╠═════════════╪═══════╪══════════╪═══════╪══════╣\n"
110110
"║ test │ 443 │ test │ 67 │ test ║\n"
111111
"╠═════════════╪═══════╧══════════╧═══════╧══════╣\n"
112-
"║ Description │ Long cell value that is merge \n"
112+
"║ Description │ Long cell value that is merged\n"
113113
"║ │ and wraps to multiple lines ║\n"
114114
"╚═════════════╧═════════════════════════════════╝"
115115
)

0 commit comments

Comments
 (0)