@@ -10,8 +10,16 @@ Module for converting 2D Python lists to a fancy ASCII/Unicode tables
10
10
- [ table2ascii] ( #table2ascii )
11
11
- [ 📥 Installation] ( #-installation )
12
12
- [ 🧑💻 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 )
13
19
- [ ⚙️ Options] ( #️-options )
14
20
- [ 👨🎨 Use cases] ( #-use-cases )
21
+ - [ Discord messages and embeds] ( #discord-messages-and-embeds )
22
+ - [ Terminal outputs] ( #terminal-outputs )
15
23
- [ 🧰 Development] ( #-development )
16
24
17
25
@@ -22,7 +30,7 @@ Module for converting 2D Python lists to a fancy ASCII/Unicode tables
22
30
23
31
## 🧑💻 Usage
24
32
25
- Convert Python lists to ASCII tables
33
+ ### Convert lists to ASCII tables
26
34
27
35
``` py
28
36
from table2ascii import table2ascii
@@ -47,6 +55,8 @@ print(output)
47
55
"""
48
56
```
49
57
58
+ ### Set first or last column headings
59
+
50
60
``` py
51
61
from table2ascii import table2ascii
52
62
@@ -65,6 +75,8 @@ print(output)
65
75
"""
66
76
```
67
77
78
+ ### Set column widths and alignments
79
+
68
80
``` py
69
81
from table2ascii import table2ascii, Alignment
70
82
@@ -88,21 +100,78 @@ print(output)
88
100
"""
89
101
```
90
102
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
+
91
160
## ⚙️ Options
92
161
93
162
All parameters are optional.
94
163
95
164
Soon table2ascii will support more options for customization.
96
165
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 |
106
175
107
176
## 👨🎨 Use cases
108
177
0 commit comments