Skip to content

Commit 6e409a4

Browse files
authored
feat: Add ascii_rounded and ascii_rounded_box table styles (#45)
1 parent 3c2cdf6 commit 6e409a4

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

docs/source/styles.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,52 @@ Preset styles
135135
2 | 30 40 35 30
136136
-----------------------
137137
138+
.. _PresetStyle.ascii_rounded:
139+
140+
`ascii_rounded`
141+
~~~~~~~~~~~~~~~
142+
143+
.. code-block:: none
144+
145+
/=============================\
146+
| # | G H R S |
147+
|=====|=======================|
148+
| 1 | 30 40 35 30 |
149+
|-----|-----------------------|
150+
| 2 | 30 40 35 30 |
151+
|=====|=======================|
152+
| SUM | 130 140 135 130 |
153+
\=====|=======================/
154+
155+
/=======================\
156+
| 1 | 30 40 35 30 |
157+
|---|-------------------|
158+
| 2 | 30 40 35 30 |
159+
\===|===================/
160+
161+
.. _PresetStyle.ascii_rounded_box:
162+
163+
`ascii_rounded_box`
164+
~~~~~~~~~~~~~~~~~~~
165+
166+
.. code-block:: none
167+
168+
/=============================\
169+
| # | G | H | R | S |
170+
|=====|=====|=====|=====|=====|
171+
| 1 | 30 | 40 | 35 | 30 |
172+
|-----|-----|-----|-----|-----|
173+
| 2 | 30 | 40 | 35 | 30 |
174+
|=====|=====|=====|=====|=====|
175+
| SUM | 130 | 140 | 135 | 130 |
176+
\=====|=====|=====|=====|=====/
177+
178+
/=======================\
179+
| 1 | 30 | 40 | 35 | 30 |
180+
|---|----|----|----|----|
181+
| 2 | 30 | 40 | 35 | 30 |
182+
\===|====|====|====|====/
183+
138184
.. _PresetStyle.ascii_simple:
139185

140186
`ascii_simple`

table2ascii/preset_style.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ class PresetStyle:
4343
ascii_minimalist = TableStyle.from_string(" --- | === --- -- ")
4444
ascii_borderless = TableStyle.from_string(" | - ")
4545
ascii_simple = TableStyle.from_string(" = | = ")
46+
ascii_rounded = TableStyle.from_string("/===\|| |=|=||-|-|\|=/")
47+
ascii_rounded_box = TableStyle.from_string("/===\||||=||||-|||\||/")
4648
markdown = TableStyle.from_string(" ||||-||| ")

tests/test_styles.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,52 @@ def test_ascii_borderless():
563563
assert text == expected
564564

565565

566+
def test_ascii_rounded():
567+
text = t2a(
568+
header=["#", "G", "H", "R", "S"],
569+
body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]],
570+
footer=["SUM", "130", "140", "135", "130"],
571+
first_col_heading=True,
572+
last_col_heading=False,
573+
style=PresetStyle.ascii_rounded,
574+
)
575+
expected = (
576+
"/=============================\\\n"
577+
"| # | G H R S |\n"
578+
"|=====|=======================|\n"
579+
"| 1 | 30 40 35 30 |\n"
580+
"|-----|-----------------------|\n"
581+
"| 2 | 30 40 35 30 |\n"
582+
"|=====|=======================|\n"
583+
"| SUM | 130 140 135 130 |\n"
584+
"\\=====|=======================/"
585+
)
586+
assert text == expected
587+
588+
589+
def test_ascii_rounded_box():
590+
text = t2a(
591+
header=["#", "G", "H", "R", "S"],
592+
body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]],
593+
footer=["SUM", "130", "140", "135", "130"],
594+
first_col_heading=True,
595+
last_col_heading=False,
596+
style=PresetStyle.ascii_rounded_box,
597+
)
598+
expected = (
599+
"/=============================\\\n"
600+
"| # | G | H | R | S |\n"
601+
"|=====|=====|=====|=====|=====|\n"
602+
"| 1 | 30 | 40 | 35 | 30 |\n"
603+
"|-----|-----|-----|-----|-----|\n"
604+
"| 2 | 30 | 40 | 35 | 30 |\n"
605+
"|=====|=====|=====|=====|=====|\n"
606+
"| SUM | 130 | 140 | 135 | 130 |\n"
607+
"\\=====|=====|=====|=====|=====/"
608+
)
609+
assert text == expected
610+
611+
566612
def test_ascii_simple():
567613
text = t2a(
568614
header=["#", "G", "H", "R", "S"],

0 commit comments

Comments
 (0)