FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
bashplotlib/bashplotlib/utils/helpers.py at master · t-turin/bashplotlib · GitHub
t-turin
/
bashplotlib
Public
forked from
robert/bashplotlib
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
bashplotlib
/
bashplotlib
/
utils
/
helpers.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
86 lines (70 loc) · 1.94 KB
Breadcrumbs
bashplotlib
/
bashplotlib
/
utils
/
helpers.py
Copy path
File metadata and controls
86 lines (70 loc) · 1.94 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/evn python
# -*- coding: utf-8 -*-
"""
Various helpful function for bashplotlib
"""
import
sys
isiterable
=
lambda
x
:
hasattr
(
x
,
'__iter__'
)
or
hasattr
(
x
,
'__getitem__'
)
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'
,
"black"
:
'
\033
[30m'
,
"default"
:
'
\033
[39m'
,
"ENDC"
:
'
\033
[39m'
,
}
colour_help
=
', '
.
join
([
colour
for
colour
in
bcolours
if
colour
!=
"ENDC"
])
def
get_colour
(
colour
):
"""
Get the escape code sequence for a colour
"""
return
bcolours
.
get
(
colour
,
bcolours
[
'ENDC'
])
def
printcolour
(
text
,
sameline
=
False
,
colour
=
get_colour
(
"ENDC"
)):
"""
Print color text using escape codes
"""
if
sameline
:
sep
=
''
else
:
sep
=
'
\n
'
sys
.
stdout
.
write
(
get_colour
(
colour
)
+
text
+
bcolours
[
"ENDC"
]
+
sep
)
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
abbreviate
(
labels
,
rfill
=
' '
):
"""
Abbreviate labels without introducing ambiguities.
"""
max_len
=
max
(
len
(
l
)
for
l
in
labels
)
for
i
in
range
(
1
,
max_len
):
abbrev
=
[
l
[:
i
].
ljust
(
i
,
rfill
)
for
l
in
labels
]
if
len
(
abbrev
)
==
len
(
set
(
abbrev
)):
break
return
abbrev
def
box_text
(
text
,
width
,
offset
=
0
):
"""
Return text inside an ascii textbox
"""
box
=
" "
*
offset
+
"-"
*
(
width
+
2
)
+
"
\n
"
box
+=
" "
*
offset
+
"|"
+
text
.
center
(
width
)
+
"|"
+
"
\n
"
box
+=
" "
*
offset
+
"-"
*
(
width
+
2
)
return
box
Back
|
FazBrowse Home
|
New Git URL