outputformat 0.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- outputformat/__init__.py +11 -0
- outputformat/color.py +89 -0
- outputformat/dict.py +53 -0
- outputformat/emoji.py +33 -0
- outputformat/fonts.py +381 -0
- outputformat/list.py +69 -0
- outputformat/misc.py +31 -0
- outputformat/plot.py +277 -0
- outputformat/title.py +235 -0
- outputformat/tools.py +218 -0
- outputformat-0.1.4.dist-info/METADATA +24 -0
- outputformat-0.1.4.dist-info/RECORD +15 -0
- outputformat-0.1.4.dist-info/WHEEL +5 -0
- outputformat-0.1.4.dist-info/licenses/LICENSE +21 -0
- outputformat-0.1.4.dist-info/top_level.txt +1 -0
outputformat/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
from outputformat.title import boxtitle
|
|
2
|
+
from outputformat.title import linetitle
|
|
3
|
+
from outputformat.title import bigtitle
|
|
4
|
+
from outputformat.list import showlist
|
|
5
|
+
from outputformat.plot import bar
|
|
6
|
+
from outputformat.plot import barlist
|
|
7
|
+
from outputformat.dict import showdict
|
|
8
|
+
from outputformat.misc import br
|
|
9
|
+
from outputformat.misc import b
|
|
10
|
+
from outputformat.color import c
|
|
11
|
+
from outputformat.color import rainbow
|
outputformat/color.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import outputformat as ouf
|
|
2
|
+
|
|
3
|
+
# Just a shortcut for the ANSI end code
|
|
4
|
+
ansi_end = "\033[0;00m"
|
|
5
|
+
|
|
6
|
+
# list of possible color maps
|
|
7
|
+
cmaps = ["hsv", "blue-red", "green-red", "cool", "hot", "greys", "random"]
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def ansi_hsv(hsv_tuple):
|
|
11
|
+
"""Creates a ANSI code from a HSV tuple
|
|
12
|
+
|
|
13
|
+
Parameters
|
|
14
|
+
----------
|
|
15
|
+
hsv_tuple : tuple
|
|
16
|
+
HSV color, tuple of 3 float values.
|
|
17
|
+
|
|
18
|
+
Returns
|
|
19
|
+
-------
|
|
20
|
+
string
|
|
21
|
+
ANSI code with the color
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
rgb_tuple = ouf.tools.hsv2rgb(hsv_tuple)
|
|
26
|
+
|
|
27
|
+
ansi_pre = f"\033[38;2;{rgb_tuple[0]};{rgb_tuple[1]};{rgb_tuple[2]}m"
|
|
28
|
+
|
|
29
|
+
return ansi_pre
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def string_hsv(input, hsv_tuple):
|
|
33
|
+
"""Apply HSV color to string"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
Parameters
|
|
37
|
+
----------
|
|
38
|
+
input : str
|
|
39
|
+
Text to be colored.
|
|
40
|
+
hsv_tuple : tuple
|
|
41
|
+
Tuple for HSV color (h ,s, v)
|
|
42
|
+
|
|
43
|
+
Returns
|
|
44
|
+
-------
|
|
45
|
+
str
|
|
46
|
+
String with the ANSI color
|
|
47
|
+
|
|
48
|
+
"""
|
|
49
|
+
string = str(input)
|
|
50
|
+
ansi_pre = ansi_hsv(hsv_tuple)
|
|
51
|
+
ansi_post = ouf.color.ansi_end
|
|
52
|
+
return f"{ansi_pre}{string}{ansi_post}"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def c(input, color, cmap="hsv", bold=False, return_str=False):
|
|
56
|
+
|
|
57
|
+
string = str(input)
|
|
58
|
+
outputstring = ""
|
|
59
|
+
|
|
60
|
+
if color == "rainbow":
|
|
61
|
+
outputstring = ouf.rainbow(input, cmap=cmap, bold=bold, return_str=True)
|
|
62
|
+
|
|
63
|
+
else:
|
|
64
|
+
# Parse color
|
|
65
|
+
color = ouf.tools.parse_color(color, cmap)
|
|
66
|
+
outputstring = string_hsv(string, color)
|
|
67
|
+
|
|
68
|
+
if bold:
|
|
69
|
+
outputstring = ouf.b(outputstring, return_str=True)
|
|
70
|
+
|
|
71
|
+
if return_str:
|
|
72
|
+
return outputstring
|
|
73
|
+
else:
|
|
74
|
+
print(outputstring)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def rainbow(input, cmap="hsv", bold=False, return_str=False):
|
|
78
|
+
string = str(input)
|
|
79
|
+
|
|
80
|
+
outputstring = ""
|
|
81
|
+
|
|
82
|
+
for idx, char in enumerate(string):
|
|
83
|
+
ratio = idx / len(string)
|
|
84
|
+
outputstring += ouf.c(char, color=ratio, cmap=cmap, bold=bold, return_str=True)
|
|
85
|
+
|
|
86
|
+
if return_str:
|
|
87
|
+
return outputstring
|
|
88
|
+
else:
|
|
89
|
+
print(outputstring)
|
outputformat/dict.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from outputformat.title import boxtitle
|
|
2
|
+
from outputformat.title import linetitle
|
|
3
|
+
from outputformat import tools
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def showdict(data, style="line", title=False, return_str=False, precision=4):
|
|
7
|
+
# Start outputstring
|
|
8
|
+
outputstring = ""
|
|
9
|
+
|
|
10
|
+
# Get keys and values as lists
|
|
11
|
+
keys = list(data.keys())
|
|
12
|
+
values = list(data.values())
|
|
13
|
+
|
|
14
|
+
# Clean values
|
|
15
|
+
values = tools.prepare_data(values, precision=precision)
|
|
16
|
+
|
|
17
|
+
# Get the longest title to use the proper padding
|
|
18
|
+
longest_key = len(max(keys, key=len))
|
|
19
|
+
|
|
20
|
+
# Get markers and title
|
|
21
|
+
markers = tools.get_markers_and_title(style, title)
|
|
22
|
+
marker_first, marker_middle, marker_last, title = markers
|
|
23
|
+
|
|
24
|
+
if title:
|
|
25
|
+
outputstring += title + "\n"
|
|
26
|
+
|
|
27
|
+
for idx in range(len(data)):
|
|
28
|
+
|
|
29
|
+
marker = tools.decide_marker(
|
|
30
|
+
idx, marker_first, marker_middle, marker_last, style, data
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# Get value to display
|
|
34
|
+
value = values[idx]
|
|
35
|
+
|
|
36
|
+
# In case value is a list, fix display
|
|
37
|
+
if isinstance(value, list):
|
|
38
|
+
clean_value = ""
|
|
39
|
+
for sub_idx, sub_value in enumerate(value):
|
|
40
|
+
clean_value += f"{sub_value}"
|
|
41
|
+
if sub_idx < len(value) - 1:
|
|
42
|
+
clean_value += ", "
|
|
43
|
+
|
|
44
|
+
value = clean_value
|
|
45
|
+
|
|
46
|
+
# Add to the outputstring
|
|
47
|
+
outputstring += f"{marker} {keys[idx]:.<{longest_key}}: {value}"
|
|
48
|
+
outputstring += "\n"
|
|
49
|
+
|
|
50
|
+
if return_str:
|
|
51
|
+
return outputstring
|
|
52
|
+
else:
|
|
53
|
+
print(outputstring)
|
outputformat/emoji.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Simply a list of shortcuts for the emoji unicode
|
|
2
|
+
|
|
3
|
+
supported_list = [
|
|
4
|
+
"crazy",
|
|
5
|
+
"sad",
|
|
6
|
+
"circle_red",
|
|
7
|
+
"circle_orange",
|
|
8
|
+
"circle_yellow",
|
|
9
|
+
"circle_green",
|
|
10
|
+
"circle_white",
|
|
11
|
+
"circle_black",
|
|
12
|
+
"star",
|
|
13
|
+
"heart",
|
|
14
|
+
"thumbs_up",
|
|
15
|
+
"check",
|
|
16
|
+
"clap",
|
|
17
|
+
"bomb",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
crazy = "\U0001F92A"
|
|
21
|
+
sad = "\U0001F625"
|
|
22
|
+
circle_red = "\U0001F534"
|
|
23
|
+
circle_orange = "\U0001F7E0"
|
|
24
|
+
circle_yellow = "\U0001F7E1"
|
|
25
|
+
circle_green = "\U0001F7E2"
|
|
26
|
+
circle_white = "\U000026AA"
|
|
27
|
+
circle_black = "\U000026AB"
|
|
28
|
+
star = "\U00002B50"
|
|
29
|
+
heart = "\U0001F496"
|
|
30
|
+
thumbs_up = "\U0001F44D"
|
|
31
|
+
check = "\U00002705"
|
|
32
|
+
clap = "\U0001F44F"
|
|
33
|
+
bomb = "\U0001F4A3"
|
outputformat/fonts.py
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
# List of characters suported
|
|
2
|
+
# Every new font must include these
|
|
3
|
+
suported_chars = "0123456789abcdefghijklmnopqrstuvwxyz_-+!?.':= "
|
|
4
|
+
|
|
5
|
+
# List of styles (fonts) that can be used
|
|
6
|
+
# Every new font name must be included here
|
|
7
|
+
font_styles = ["small", "big"]
|
|
8
|
+
|
|
9
|
+
small = {
|
|
10
|
+
"0": ["█▀█", "█▄█"],
|
|
11
|
+
"1": ["▄█", " █"],
|
|
12
|
+
"2": ["▀█", "█▄"],
|
|
13
|
+
"3": ["▀▀█", "▄██"],
|
|
14
|
+
"4": ["█ █", "▀▀█"],
|
|
15
|
+
"5": ["█▀", "▄█"],
|
|
16
|
+
"6": ["█▄▄", "█▄█"],
|
|
17
|
+
"7": ["▀▀█", " █"],
|
|
18
|
+
"8": ["█▀█", "███"],
|
|
19
|
+
"9": ["█▀█", "▀▀█"],
|
|
20
|
+
"a": ["▄▀█", "█▀█"],
|
|
21
|
+
"b": ["█▄▄", "█▄█"],
|
|
22
|
+
"c": ["█▀▀", "█▄▄"],
|
|
23
|
+
"d": ["█▀▄", "█▄▀"],
|
|
24
|
+
"e": ["█▀▀", "██▄"],
|
|
25
|
+
"f": ["█▀▀", "█▀ "],
|
|
26
|
+
"g": ["█▀▀", "█▄█"],
|
|
27
|
+
"h": ["█ █", "█▀█"],
|
|
28
|
+
"i": ["█", "█"],
|
|
29
|
+
"j": [" █", "█▄█"],
|
|
30
|
+
"k": ["█▄▀", "█ █"],
|
|
31
|
+
"l": ["█ ", "█▄▄"],
|
|
32
|
+
"m": ["█▀▄▀█", "█ ▀ █"],
|
|
33
|
+
"n": ["█▄ █", "█ ▀█"],
|
|
34
|
+
"o": ["█▀█", "█▄█"],
|
|
35
|
+
"p": ["█▀█", "█▀▀"],
|
|
36
|
+
"q": ["█▀█", "▀▀█"],
|
|
37
|
+
"r": ["█▀█", "█▀▄"],
|
|
38
|
+
"s": ["█▀", "▄█"],
|
|
39
|
+
"t": ["▀█▀", " █ "],
|
|
40
|
+
"u": ["█ █", "█▄█"],
|
|
41
|
+
"v": ["█ █", "▀▄▀"],
|
|
42
|
+
"w": ["█ █ █", "▀▄▀▄▀"],
|
|
43
|
+
"x": ["▀▄▀", "█ █"],
|
|
44
|
+
"y": ["█▄█", " █ "],
|
|
45
|
+
"z": ["▀█", "█▄"],
|
|
46
|
+
"_": [" ", "▄▄▄"],
|
|
47
|
+
"-": [" ", "▀▀"],
|
|
48
|
+
"+": [" ▄ ", "▀█▀"],
|
|
49
|
+
"!": ["█", "▄"],
|
|
50
|
+
"?": ["█▀█", " ▄"],
|
|
51
|
+
".": [" ", "▄"],
|
|
52
|
+
"'": ["▀", " "],
|
|
53
|
+
":": ["▄", "▄"],
|
|
54
|
+
"=": ["▄▄", "▄▄"],
|
|
55
|
+
" ": [" ", " "],
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
big = {
|
|
59
|
+
"0": [
|
|
60
|
+
" ██████ ",
|
|
61
|
+
"██ ████",
|
|
62
|
+
"██ ██ ██",
|
|
63
|
+
"████ ██",
|
|
64
|
+
" ██████ ",
|
|
65
|
+
],
|
|
66
|
+
"1": [
|
|
67
|
+
" ██",
|
|
68
|
+
"███",
|
|
69
|
+
" ██",
|
|
70
|
+
" ██",
|
|
71
|
+
" ██",
|
|
72
|
+
],
|
|
73
|
+
"2": [
|
|
74
|
+
"██████ ",
|
|
75
|
+
" ██",
|
|
76
|
+
" █████ ",
|
|
77
|
+
"██ ",
|
|
78
|
+
"███████",
|
|
79
|
+
],
|
|
80
|
+
"3": [
|
|
81
|
+
"██████ ",
|
|
82
|
+
" ██",
|
|
83
|
+
" █████ ",
|
|
84
|
+
" ██",
|
|
85
|
+
"██████ ",
|
|
86
|
+
],
|
|
87
|
+
"4": [
|
|
88
|
+
"██ ██",
|
|
89
|
+
"██ ██",
|
|
90
|
+
"███████",
|
|
91
|
+
" ██",
|
|
92
|
+
" ██",
|
|
93
|
+
],
|
|
94
|
+
"5": [
|
|
95
|
+
"███████",
|
|
96
|
+
"██ ",
|
|
97
|
+
"███████",
|
|
98
|
+
" ██",
|
|
99
|
+
"███████",
|
|
100
|
+
],
|
|
101
|
+
"6": [
|
|
102
|
+
" ██████ ",
|
|
103
|
+
"██ ",
|
|
104
|
+
"███████ ",
|
|
105
|
+
"██ ██",
|
|
106
|
+
" ██████ ",
|
|
107
|
+
],
|
|
108
|
+
"7": [
|
|
109
|
+
"███████",
|
|
110
|
+
" ██",
|
|
111
|
+
" ██ ",
|
|
112
|
+
" ██ ",
|
|
113
|
+
" ██ ",
|
|
114
|
+
],
|
|
115
|
+
"8": [
|
|
116
|
+
" █████ ",
|
|
117
|
+
"██ ██",
|
|
118
|
+
" █████ ",
|
|
119
|
+
"██ ██",
|
|
120
|
+
" █████ ",
|
|
121
|
+
],
|
|
122
|
+
"9": [
|
|
123
|
+
" █████ ",
|
|
124
|
+
"██ ██",
|
|
125
|
+
" ██████",
|
|
126
|
+
" ██",
|
|
127
|
+
" █████ ",
|
|
128
|
+
],
|
|
129
|
+
"a": [
|
|
130
|
+
" █████ ",
|
|
131
|
+
"██ ██",
|
|
132
|
+
"███████",
|
|
133
|
+
"██ ██",
|
|
134
|
+
"██ ██",
|
|
135
|
+
],
|
|
136
|
+
"b": [
|
|
137
|
+
"██████ ",
|
|
138
|
+
"██ ██",
|
|
139
|
+
"██████ ",
|
|
140
|
+
"██ ██",
|
|
141
|
+
"██████ ",
|
|
142
|
+
],
|
|
143
|
+
"c": [
|
|
144
|
+
" ██████",
|
|
145
|
+
"██ ",
|
|
146
|
+
"██ ",
|
|
147
|
+
"██ ",
|
|
148
|
+
" ██████",
|
|
149
|
+
],
|
|
150
|
+
"d": [
|
|
151
|
+
"██████ ",
|
|
152
|
+
"██ ██",
|
|
153
|
+
"██ ██",
|
|
154
|
+
"██ ██",
|
|
155
|
+
"██████ ",
|
|
156
|
+
],
|
|
157
|
+
"e": [
|
|
158
|
+
"███████",
|
|
159
|
+
"██ ",
|
|
160
|
+
"█████ ",
|
|
161
|
+
"██ ",
|
|
162
|
+
"███████",
|
|
163
|
+
],
|
|
164
|
+
"f": [
|
|
165
|
+
"███████",
|
|
166
|
+
"██ ",
|
|
167
|
+
"█████ ",
|
|
168
|
+
"██ ",
|
|
169
|
+
"██ ",
|
|
170
|
+
],
|
|
171
|
+
"g": [
|
|
172
|
+
" ██████ ",
|
|
173
|
+
"██ ",
|
|
174
|
+
"██ ███",
|
|
175
|
+
"██ ██",
|
|
176
|
+
" ██████ ",
|
|
177
|
+
],
|
|
178
|
+
"h": [
|
|
179
|
+
"██ ██",
|
|
180
|
+
"██ ██",
|
|
181
|
+
"███████",
|
|
182
|
+
"██ ██",
|
|
183
|
+
"██ ██",
|
|
184
|
+
],
|
|
185
|
+
"i": [
|
|
186
|
+
"██",
|
|
187
|
+
"██",
|
|
188
|
+
"██",
|
|
189
|
+
"██",
|
|
190
|
+
"██",
|
|
191
|
+
],
|
|
192
|
+
"j": [
|
|
193
|
+
" ██",
|
|
194
|
+
" ██",
|
|
195
|
+
" ██",
|
|
196
|
+
"██ ██",
|
|
197
|
+
" █████ ",
|
|
198
|
+
],
|
|
199
|
+
"k": [
|
|
200
|
+
"██ ██",
|
|
201
|
+
"██ ██ ",
|
|
202
|
+
"█████ ",
|
|
203
|
+
"██ ██ ",
|
|
204
|
+
"██ ██",
|
|
205
|
+
],
|
|
206
|
+
"l": [
|
|
207
|
+
"██ ",
|
|
208
|
+
"██ ",
|
|
209
|
+
"██ ",
|
|
210
|
+
"██ ",
|
|
211
|
+
"███████",
|
|
212
|
+
],
|
|
213
|
+
"m": [
|
|
214
|
+
"███ ███",
|
|
215
|
+
"████ ████",
|
|
216
|
+
"██ ████ ██",
|
|
217
|
+
"██ ██ ██",
|
|
218
|
+
"██ ██",
|
|
219
|
+
],
|
|
220
|
+
"n": [
|
|
221
|
+
"███ ██",
|
|
222
|
+
"████ ██",
|
|
223
|
+
"██ ██ ██",
|
|
224
|
+
"██ ██ ██",
|
|
225
|
+
"██ ████",
|
|
226
|
+
],
|
|
227
|
+
"o": [
|
|
228
|
+
" ██████ ",
|
|
229
|
+
"██ ██",
|
|
230
|
+
"██ ██",
|
|
231
|
+
"██ ██",
|
|
232
|
+
" ██████ ",
|
|
233
|
+
],
|
|
234
|
+
"p": [
|
|
235
|
+
"██████ ",
|
|
236
|
+
"██ ██",
|
|
237
|
+
"██████ ",
|
|
238
|
+
"██ ",
|
|
239
|
+
"██ ",
|
|
240
|
+
],
|
|
241
|
+
"q": [
|
|
242
|
+
" ██████ ",
|
|
243
|
+
"██ ██",
|
|
244
|
+
"██ ██",
|
|
245
|
+
"██ ▄▄ ██",
|
|
246
|
+
" ████▀▄▄",
|
|
247
|
+
],
|
|
248
|
+
"r": [
|
|
249
|
+
"██████ ",
|
|
250
|
+
"██ ██",
|
|
251
|
+
"██████ ",
|
|
252
|
+
"██ ██",
|
|
253
|
+
"██ ██",
|
|
254
|
+
],
|
|
255
|
+
"s": [
|
|
256
|
+
"███████",
|
|
257
|
+
"██ ",
|
|
258
|
+
"███████",
|
|
259
|
+
" ██",
|
|
260
|
+
"███████",
|
|
261
|
+
],
|
|
262
|
+
"t": [
|
|
263
|
+
"████████",
|
|
264
|
+
" ██ ",
|
|
265
|
+
" ██ ",
|
|
266
|
+
" ██ ",
|
|
267
|
+
" ██ ",
|
|
268
|
+
],
|
|
269
|
+
"u": [
|
|
270
|
+
"██ ██",
|
|
271
|
+
"██ ██",
|
|
272
|
+
"██ ██",
|
|
273
|
+
"██ ██",
|
|
274
|
+
" ██████ ",
|
|
275
|
+
],
|
|
276
|
+
"v": [
|
|
277
|
+
"██ ██",
|
|
278
|
+
"██ ██",
|
|
279
|
+
"██ ██",
|
|
280
|
+
" ██ ██ ",
|
|
281
|
+
" ████ ",
|
|
282
|
+
],
|
|
283
|
+
"w": [
|
|
284
|
+
"██ ██",
|
|
285
|
+
"██ ██",
|
|
286
|
+
"██ █ ██",
|
|
287
|
+
"██ ███ ██",
|
|
288
|
+
" ███ ███ ",
|
|
289
|
+
],
|
|
290
|
+
"x": [
|
|
291
|
+
"██ ██",
|
|
292
|
+
" ██ ██ ",
|
|
293
|
+
" ███ ",
|
|
294
|
+
" ██ ██ ",
|
|
295
|
+
"██ ██",
|
|
296
|
+
],
|
|
297
|
+
"y": [
|
|
298
|
+
"██ ██",
|
|
299
|
+
" ██ ██ ",
|
|
300
|
+
" ████ ",
|
|
301
|
+
" ██ ",
|
|
302
|
+
" ██ ",
|
|
303
|
+
],
|
|
304
|
+
"z": [
|
|
305
|
+
"███████",
|
|
306
|
+
" ███ ",
|
|
307
|
+
" ███ ",
|
|
308
|
+
" ███ ",
|
|
309
|
+
"███████",
|
|
310
|
+
],
|
|
311
|
+
"_": [
|
|
312
|
+
" ",
|
|
313
|
+
" ",
|
|
314
|
+
" ",
|
|
315
|
+
" ",
|
|
316
|
+
"███████",
|
|
317
|
+
],
|
|
318
|
+
"-": [
|
|
319
|
+
" ",
|
|
320
|
+
" ",
|
|
321
|
+
"█████",
|
|
322
|
+
" ",
|
|
323
|
+
" ",
|
|
324
|
+
],
|
|
325
|
+
"+": [
|
|
326
|
+
" ",
|
|
327
|
+
" █ ",
|
|
328
|
+
"█████",
|
|
329
|
+
" █ ",
|
|
330
|
+
" ",
|
|
331
|
+
],
|
|
332
|
+
"!": [
|
|
333
|
+
"██",
|
|
334
|
+
"██",
|
|
335
|
+
"██",
|
|
336
|
+
" ",
|
|
337
|
+
"██",
|
|
338
|
+
],
|
|
339
|
+
"?": [
|
|
340
|
+
"██████ ",
|
|
341
|
+
" ██",
|
|
342
|
+
" ▄███ ",
|
|
343
|
+
" ▀▀ ",
|
|
344
|
+
" ██ ",
|
|
345
|
+
],
|
|
346
|
+
".": [
|
|
347
|
+
" ",
|
|
348
|
+
" ",
|
|
349
|
+
" ",
|
|
350
|
+
" ",
|
|
351
|
+
"██",
|
|
352
|
+
],
|
|
353
|
+
"'": [
|
|
354
|
+
"██",
|
|
355
|
+
"█ ",
|
|
356
|
+
" ",
|
|
357
|
+
" ",
|
|
358
|
+
" ",
|
|
359
|
+
],
|
|
360
|
+
":": [
|
|
361
|
+
" ",
|
|
362
|
+
"██",
|
|
363
|
+
" ",
|
|
364
|
+
"██",
|
|
365
|
+
" ",
|
|
366
|
+
],
|
|
367
|
+
"=": [
|
|
368
|
+
" ",
|
|
369
|
+
"████",
|
|
370
|
+
" ",
|
|
371
|
+
"████",
|
|
372
|
+
" ",
|
|
373
|
+
],
|
|
374
|
+
" ": [
|
|
375
|
+
" ",
|
|
376
|
+
" ",
|
|
377
|
+
" ",
|
|
378
|
+
" ",
|
|
379
|
+
" ",
|
|
380
|
+
],
|
|
381
|
+
}
|
outputformat/list.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from outputformat.title import boxtitle
|
|
2
|
+
from outputformat.title import linetitle
|
|
3
|
+
from outputformat import tools
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def showlist(data, style="bullet", title=False, return_str=False, precision=4):
|
|
7
|
+
"""Show each item of a given list.
|
|
8
|
+
|
|
9
|
+
Parameters
|
|
10
|
+
----------
|
|
11
|
+
data : list
|
|
12
|
+
List of items to display. Anything passed here will be converted to list
|
|
13
|
+
|
|
14
|
+
style : string, default: 'bullet'
|
|
15
|
+
How items are displayed. Options are: 'bullet', 'line', 'box', 'ordinal'
|
|
16
|
+
'bullet' or '*': Simple bullet points
|
|
17
|
+
'line' or '-': Line under the title, connected to the items
|
|
18
|
+
'box': Title with a box decoration
|
|
19
|
+
'ordinal' or '#': Shows a numbered list in ascending order
|
|
20
|
+
|
|
21
|
+
In case any other string is passed, it will be used as marker
|
|
22
|
+
For example:
|
|
23
|
+
>>> showlist(["Item A", "Item B", "Item C"], style="~>")
|
|
24
|
+
~> Item A
|
|
25
|
+
~> Item B
|
|
26
|
+
~> Item C
|
|
27
|
+
|
|
28
|
+
title : string, optional
|
|
29
|
+
Title to be displayed before the list.
|
|
30
|
+
In case 'title = False', the 'line' and 'box' styles give the same result
|
|
31
|
+
|
|
32
|
+
return_str : Bool, default: False
|
|
33
|
+
If True, returns a string instead of printing.
|
|
34
|
+
|
|
35
|
+
Returns
|
|
36
|
+
-------
|
|
37
|
+
string
|
|
38
|
+
Only returns in case 'return_str = True', otherwise None
|
|
39
|
+
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
# Start outputstring
|
|
43
|
+
outputstring = ""
|
|
44
|
+
|
|
45
|
+
# Prepare and clean data
|
|
46
|
+
data = tools.prepare_data(data, precision=precision)
|
|
47
|
+
|
|
48
|
+
# Get markers and title
|
|
49
|
+
markers = tools.get_markers_and_title(style, title)
|
|
50
|
+
marker_first, marker_middle, marker_last, title = markers
|
|
51
|
+
|
|
52
|
+
# Add title, if we have one
|
|
53
|
+
if title:
|
|
54
|
+
outputstring += f"{title}\n"
|
|
55
|
+
|
|
56
|
+
# Add list items
|
|
57
|
+
for idx in range(len(data)):
|
|
58
|
+
|
|
59
|
+
marker = tools.decide_marker(
|
|
60
|
+
idx, marker_first, marker_middle, marker_last, style, data
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
# Generate string for this item
|
|
64
|
+
outputstring += f"{marker} {data[idx]}\n"
|
|
65
|
+
|
|
66
|
+
if return_str:
|
|
67
|
+
return outputstring
|
|
68
|
+
else:
|
|
69
|
+
print(outputstring)
|
outputformat/misc.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
def br(nlines=1, return_str=False):
|
|
2
|
+
"""Short summary.
|
|
3
|
+
|
|
4
|
+
Parameters
|
|
5
|
+
----------
|
|
6
|
+
nlines : int
|
|
7
|
+
Number of lines to break.
|
|
8
|
+
return_str : bool
|
|
9
|
+
If True, returns a string instead of printing.
|
|
10
|
+
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
outputstring = "\n" * (nlines - 1)
|
|
14
|
+
|
|
15
|
+
if return_str:
|
|
16
|
+
return outputstring
|
|
17
|
+
else:
|
|
18
|
+
print(outputstring)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def b(input, return_str=False):
|
|
22
|
+
"""Bold the string"""
|
|
23
|
+
ansi_bold = "\033[1m"
|
|
24
|
+
ansi_end = "\033[0m"
|
|
25
|
+
|
|
26
|
+
outputstring = f"{ansi_bold}{str(input)}{ansi_end}"
|
|
27
|
+
|
|
28
|
+
if return_str:
|
|
29
|
+
return outputstring
|
|
30
|
+
else:
|
|
31
|
+
print(outputstring)
|