Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Fjen Undso
nchl
Commits
8d5f58d4
Commit
8d5f58d4
authored
Aug 30, 2019
by
Fjen Undso
Browse files
smooth color bars
parent
19d80a43
Changes
2
Show whitespace changes
Inline
Side-by-side
gui/progressbar.py
View file @
8d5f58d4
...
...
@@ -29,6 +29,7 @@ class ProgressBar(Drawable):
):
assert
width
>
2
assert
height
>
2
self
.
characters
=
"▁▂▃▄▅▆▇█"
self
.
value
=
value
self
.
max
=
max_value
self
.
text
=
text
...
...
@@ -52,11 +53,19 @@ class ProgressBar(Drawable):
def
draw
(
self
):
self
.
window
.
erase
()
# draw bar
top
=
self
.
height
-
int
(
self
.
value
/
self
.
max
*
self
.
height
)
# calculate bar height
bottom
=
self
.
height
for
i
in
range
(
top
,
bottom
):
self
.
window
.
insstr
(
i
,
0
,
" "
*
self
.
width
,
self
.
attr
)
top_exact
=
self
.
value
/
self
.
max
*
self
.
height
top_full
=
self
.
height
-
int
(
top_exact
)
# completely filled pixel height
top_fraction
=
top_exact
%
1
# partly filled pixel
# draw bar
if
top_fraction
:
# partly filled pixel
char_idx
=
int
(
top_fraction
*
8
)
self
.
window
.
insstr
(
top_full
-
1
,
0
,
self
.
characters
[
char_idx
]
*
self
.
width
,
self
.
attr
)
for
i
in
range
(
top_full
,
bottom
):
# full pixel
self
.
window
.
insstr
(
i
,
0
,
self
.
characters
[
-
1
]
*
self
.
width
,
self
.
attr
)
self
.
window
.
refresh
()
def
set
(
self
,
value
):
...
...
nchl.py
View file @
8d5f58d4
...
...
@@ -36,10 +36,10 @@ class NCHL:
# init colors
curses
.
start_color
()
curses
.
use_default_colors
()
curses
.
init_pair
(
curses
.
COLOR_RED
,
0
,
curses
.
COLOR_RED
)
curses
.
init_pair
(
curses
.
COLOR_GREEN
,
0
,
curses
.
COLOR_GREEN
)
curses
.
init_pair
(
curses
.
COLOR_BLUE
,
0
,
curses
.
COLOR_BLUE
)
curses
.
init_pair
(
curses
.
COLOR_WHITE
,
0
,
curses
.
COLOR_WHITE
)
curses
.
init_pair
(
curses
.
COLOR_RED
,
curses
.
COLOR_RED
,
-
1
)
curses
.
init_pair
(
curses
.
COLOR_GREEN
,
curses
.
COLOR_GREEN
,
-
1
)
curses
.
init_pair
(
curses
.
COLOR_BLUE
,
curses
.
COLOR_BLUE
,
-
1
)
curses
.
init_pair
(
curses
.
COLOR_WHITE
,
curses
.
COLOR_WHITE
,
-
1
)
curses
.
init_pair
(
curses
.
COLOR_YELLOW
,
curses
.
COLOR_YELLOW
,
-
1
)
try
:
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment