forked from glamp/bashplotlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
51 lines (44 loc) · 1.21 KB
/
helpers.py
File metadata and controls
51 lines (44 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
bcolours = {
"white": '\033[97m',
"aqua": '\033[96m',
"pink": '\033[95m',
"blue": '\033[94m',
"yellow": '\033[93m',
"green": '\033[92m',
"red": '\033[91m',
"grey": '\033[90m',
"ENDC": '\033[0m'
}
def get_colour(colour):
return bcolours.get(colour, bcolours['white'])
def printcolor(txt, sameline=False, color=get_colour("white")):
if sameline:
if color=='\033[97m':
print txt,
else:
print color + txt + bcolours["ENDC"],
else:
if color=='\033[97m':
print txt
else:
print color + txt + bcolours["ENDC"]
def drange(start, stop, step=1.0, include_stop=False):
"generate between 2 numbers w/ optional step, optionally include upper bound"
if step==0:
step = 0.01
r = start
if include_stop:
while r <= stop:
yield r
r += step
r = round(r, 10)
else:
while r < stop:
yield r
r += step
r = round(r, 10)
def box_text(text, width, offset=0):
box = " "*offset + "-"*(width+2) + "\n"
box += " "*offset + "|"+ text.center(width) + "|" + "\n"
box += " "*offset + "-"*(width+2)
return box