Commit 8d5f58d4 authored by Fjen Undso's avatar Fjen Undso
Browse files

smooth color bars

parent 19d80a43
...@@ -29,6 +29,7 @@ class ProgressBar(Drawable): ...@@ -29,6 +29,7 @@ class ProgressBar(Drawable):
): ):
assert width > 2 assert width > 2
assert height > 2 assert height > 2
self.characters = "▁▂▃▄▅▆▇█"
self.value = value self.value = value
self.max = max_value self.max = max_value
self.text = text self.text = text
...@@ -52,11 +53,19 @@ class ProgressBar(Drawable): ...@@ -52,11 +53,19 @@ class ProgressBar(Drawable):
def draw(self): def draw(self):
self.window.erase() self.window.erase()
# draw bar # calculate bar height
top = self.height - int(self.value / self.max * self.height)
bottom = self.height bottom = self.height
for i in range(top, bottom): top_exact = self.value / self.max * self.height
self.window.insstr(i, 0, " " * self.width, self.attr) 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() self.window.refresh()
def set(self, value): def set(self, value):
......
...@@ -36,10 +36,10 @@ class NCHL: ...@@ -36,10 +36,10 @@ class NCHL:
# init colors # init colors
curses.start_color() curses.start_color()
curses.use_default_colors() curses.use_default_colors()
curses.init_pair(curses.COLOR_RED, 0, curses.COLOR_RED) curses.init_pair(curses.COLOR_RED, curses.COLOR_RED, -1)
curses.init_pair(curses.COLOR_GREEN, 0, curses.COLOR_GREEN) curses.init_pair(curses.COLOR_GREEN, curses.COLOR_GREEN, -1)
curses.init_pair(curses.COLOR_BLUE, 0, curses.COLOR_BLUE) curses.init_pair(curses.COLOR_BLUE, curses.COLOR_BLUE, -1)
curses.init_pair(curses.COLOR_WHITE, 0, curses.COLOR_WHITE) curses.init_pair(curses.COLOR_WHITE, curses.COLOR_WHITE, -1)
curses.init_pair(curses.COLOR_YELLOW, curses.COLOR_YELLOW, -1) curses.init_pair(curses.COLOR_YELLOW, curses.COLOR_YELLOW, -1)
try: try:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment