Skip to content

Commit 9d9fb78

Browse files
authored
Merge pull request #10 from DenverCoder1/new-styles
Added preset styles and a way to add custom styles
2 parents 5db4b07 + e08b339 commit 9d9fb78

15 files changed

+1640
-323
lines changed

README.md

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,16 @@ Module for converting 2D Python lists to a fancy ASCII/Unicode tables
1010
- [table2ascii](#table2ascii)
1111
- [📥 Installation](#-installation)
1212
- [🧑‍💻 Usage](#-usage)
13+
- [Convert lists to ASCII tables](#convert-lists-to-ascii-tables)
14+
- [Set first or last column headings](#set-first-or-last-column-headings)
15+
- [Set column widths and alignments](#set-column-widths-and-alignments)
16+
- [Use a preset style](#use-a-preset-style)
17+
- [Define a custom style](#define-a-custom-style)
18+
- [🎨 Preset styles](#-preset-styles)
1319
- [⚙️ Options](#️-options)
1420
- [👨‍🎨 Use cases](#-use-cases)
21+
- [Discord messages and embeds](#discord-messages-and-embeds)
22+
- [Terminal outputs](#terminal-outputs)
1523
- [🧰 Development](#-development)
1624

1725

@@ -22,7 +30,7 @@ Module for converting 2D Python lists to a fancy ASCII/Unicode tables
2230

2331
## 🧑‍💻 Usage
2432

25-
Convert Python lists to ASCII tables
33+
### Convert lists to ASCII tables
2634

2735
```py
2836
from table2ascii import table2ascii
@@ -47,6 +55,8 @@ print(output)
4755
"""
4856
```
4957

58+
### Set first or last column headings
59+
5060
```py
5161
from table2ascii import table2ascii
5262

@@ -65,6 +75,8 @@ print(output)
6575
"""
6676
```
6777

78+
### Set column widths and alignments
79+
6880
```py
6981
from table2ascii import table2ascii, Alignment
7082

@@ -88,21 +100,78 @@ print(output)
88100
"""
89101
```
90102

103+
### Use a preset style
104+
105+
```py
106+
from table2ascii import table2ascii, PresetStyle
107+
108+
output = table2ascii(
109+
header=["First", "Second", "Third", "Fourth"],
110+
body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]],
111+
column_widths=[10] * 4,
112+
style=PresetStyle.ascii_box
113+
)
114+
115+
print(output)
116+
117+
"""
118+
+----------+----------+----------+----------+
119+
| First | Second | Third | Fourth |
120+
+----------+----------+----------+----------+
121+
| 10 | 30 | 40 | 35 |
122+
+----------+----------+----------+----------+
123+
| 20 | 10 | 20 | 5 |
124+
+----------+----------+----------+----------+
125+
"""
126+
```
127+
128+
### Define a custom style
129+
130+
Check [`TableStyle`](https://github.com/DenverCoder1/table2ascii/blob/main/table2ascii/table_style.py) for more info and [`PresetStyle`](https://github.com/DenverCoder1/table2ascii/blob/main/table2ascii/preset_style.py) for examples.
131+
132+
```py
133+
from table2ascii import table2ascii, TableStyle
134+
135+
my_style = TableStyle.from_string("*-..*||:+-+:+ *''*")
136+
137+
output = table2ascii(
138+
header=["First", "Second", "Third"],
139+
body=[["10", "30", "40"], ["20", "10", "20"], ["30", "20", "30"]],
140+
style=my_style
141+
)
142+
143+
print(output)
144+
145+
"""
146+
*-------.--------.-------*
147+
| First : Second : Third |
148+
+-------:--------:-------+
149+
| 10 : 30 : 40 |
150+
| 20 : 10 : 20 |
151+
| 30 : 20 : 30 |
152+
*-------'--------'-------*
153+
"""
154+
```
155+
156+
## 🎨 Preset styles
157+
158+
See a list of all preset styles [here](/style_list).
159+
91160
## ⚙️ Options
92161

93162
All parameters are optional.
94163

95164
Soon table2ascii will support more options for customization.
96165

97-
| Option | Type | Default | Description |
98-
| :-----------------: | :-------: | :----------: | :------------------------------------------------------------------------------------: |
99-
| `header` | `List` | `None` | First row of table seperated by header row seperator |
100-
| `body` | `2D List` | `None` | List of rows for the main section of the table |
101-
| `footer` | `List` | `None` | Last row of table seperated by header row seperator |
102-
| `column_widths` | `List` | automatic | List of column widths in characters for each column |
103-
| `alignments` | `List` | all centered | Alignments for each column (ex. `[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT]`) |
104-
| `first_col_heading` | `bool` | `False` | Whether to add a heading column seperator after the first column |
105-
| `last_col_heading` | `bool` | `False` | Whether to add a heading column seperator before the last column |
166+
| Option | Type | Default | Description |
167+
| :-----------------: | :---------------: | :----------: | :----------------------------------------------------------------------------------------: |
168+
| `header` | `List[str]` | `None` | First row of table seperated by header row seperator |
169+
| `body` | `List[List[str]]` | `None` | List of rows for the main section of the table |
170+
| `footer` | `List[str]` | `None` | Last row of table seperated by header row seperator |
171+
| `column_widths` | `List[int]` | automatic | List of column widths in characters for each column |
172+
| `alignments` | `List[int]` | all centered | Alignments for each column<br/>(ex. `[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT]`) |
173+
| `first_col_heading` | `bool` | `False` | Whether to add a heading column seperator after the first column |
174+
| `last_col_heading` | `bool` | `False` | Whether to add a heading column seperator before the last column |
106175

107176
## 👨‍🎨 Use cases
108177

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def run(self):
5959

6060
setup(
6161
name="table2ascii",
62-
version="0.0.3",
62+
version="0.1.1",
6363
author="Jonah Lawrence",
6464
author_email="jonah@freshidea.com",
6565
description="Convert 2D Python lists into Unicode/Ascii tables",

0 commit comments

Comments
 (0)