commit
ae1b9a8f8f
@ -389,6 +389,26 @@ def make_graph(values, upper_limit=100.0):
|
|||||||
for n in values[:len(values)-1]) # Don't show the upper limit value.
|
for n in values[:len(values)-1]) # Don't show the upper limit value.
|
||||||
return graph
|
return graph
|
||||||
|
|
||||||
|
|
||||||
|
def make_vertical_bar(percentage, width=1):
|
||||||
|
"""
|
||||||
|
Draws a vertical bar made of unicode characters.
|
||||||
|
|
||||||
|
:param value: A value between 0 and 100
|
||||||
|
:param width: How many characters wide the bar should be.
|
||||||
|
:returns: Bar as a String
|
||||||
|
"""
|
||||||
|
bar = u' _▁▂▃▄▅▆▇█'
|
||||||
|
percentage //= 10
|
||||||
|
if percentage < 0:
|
||||||
|
output = bar[0]
|
||||||
|
elif percentage >= len(bar):
|
||||||
|
output = bar[-1]
|
||||||
|
else:
|
||||||
|
output = bar[percentage]
|
||||||
|
return output * width
|
||||||
|
|
||||||
|
|
||||||
def make_bar(percentage):
|
def make_bar(percentage):
|
||||||
"""
|
"""
|
||||||
Draws a bar made of unicode box characters.
|
Draws a bar made of unicode box characters.
|
||||||
|
@ -67,6 +67,9 @@ class CpuUsage(IntervalModule):
|
|||||||
self.prev_total[cpu] = total
|
self.prev_total[cpu] = total
|
||||||
self.prev_busy[cpu] = busy
|
self.prev_busy[cpu] = busy
|
||||||
|
|
||||||
|
if diff_total == 0:
|
||||||
|
return 0
|
||||||
|
else:
|
||||||
return int(diff_busy / diff_total * 100)
|
return int(diff_busy / diff_total * 100)
|
||||||
|
|
||||||
def gen_format_all(self, usage):
|
def gen_format_all(self, usage):
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
from i3pystatus.core.color import ColorRangeModule
|
||||||
from i3pystatus.cpu_usage import CpuUsage
|
from i3pystatus.cpu_usage import CpuUsage
|
||||||
from i3pystatus.core.util import make_bar
|
from i3pystatus.core.util import make_bar, make_vertical_bar
|
||||||
|
|
||||||
class CpuUsageBar(CpuUsage):
|
|
||||||
|
class CpuUsageBar(CpuUsage, ColorRangeModule):
|
||||||
"""
|
"""
|
||||||
Shows CPU usage as a bar (made with unicode box characters).
|
Shows CPU usage as a bar (made with unicode box characters).
|
||||||
The first output will be inacurate.
|
The first output will be inacurate.
|
||||||
|
|
||||||
Linux only
|
Linux only
|
||||||
|
|
||||||
|
Requires the PyPI package `colour`.
|
||||||
|
|
||||||
Available formatters:
|
Available formatters:
|
||||||
|
|
||||||
* {usage_bar} usage average of all cores
|
* {usage_bar} usage average of all cores
|
||||||
@ -19,10 +22,23 @@ class CpuUsageBar(CpuUsage):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
format = "{usage_bar}"
|
format = "{usage_bar}"
|
||||||
|
bar_type = 'horizontal'
|
||||||
|
cpu = 'usage_bar'
|
||||||
|
|
||||||
settings = (
|
settings = (
|
||||||
("format", "format string"),
|
("format", "format string"),
|
||||||
|
("bar_type", "whether the bar should be vertical or horizontal. "
|
||||||
|
"Allowed values: `vertical` or `horizontal`"),
|
||||||
|
("cpu", "cpu to base the colors on. Choices are 'usage_cpu' for all or 'usage_cpu*'."
|
||||||
|
" Replace '*' by core number starting at 0."),
|
||||||
|
("start_color", "Hex or English name for start of color range, eg '#00FF00' or 'green'"),
|
||||||
|
("end_color", "Hex or English name for end of color range, eg '#FF0000' or 'red'")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
super().init()
|
||||||
|
self.colors = self.get_hex_color_range(self.start_color, self.end_color, 100)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
cpu_usage = self.get_usage()
|
cpu_usage = self.get_usage()
|
||||||
|
|
||||||
@ -30,7 +46,12 @@ class CpuUsageBar(CpuUsage):
|
|||||||
|
|
||||||
for core, usage in cpu_usage.items():
|
for core, usage in cpu_usage.items():
|
||||||
core = core.replace('usage', 'usage_bar')
|
core = core.replace('usage', 'usage_bar')
|
||||||
|
if self.bar_type == 'horizontal':
|
||||||
cpu_usage_bar[core] = make_bar(usage)
|
cpu_usage_bar[core] = make_bar(usage)
|
||||||
|
elif self.bar_type == 'vertical':
|
||||||
|
cpu_usage_bar[core] = make_vertical_bar(usage)
|
||||||
|
else:
|
||||||
|
raise Exception("bar_type must be 'horizontal' or 'vertical'!")
|
||||||
|
|
||||||
cpu_usage.update(cpu_usage_bar)
|
cpu_usage.update(cpu_usage_bar)
|
||||||
|
|
||||||
@ -38,6 +59,6 @@ class CpuUsageBar(CpuUsage):
|
|||||||
cpu_usage['usage_bar'] = cpu_usage['usage_bar_cpu']
|
cpu_usage['usage_bar'] = cpu_usage['usage_bar_cpu']
|
||||||
|
|
||||||
self.output = {
|
self.output = {
|
||||||
"full_text": self.format.format_map(cpu_usage)
|
"full_text": self.format.format_map(cpu_usage),
|
||||||
|
'color': self.get_gradient(cpu_usage[self.cpu], self.colors, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
from i3pystatus import IntervalModule
|
from i3pystatus import IntervalModule
|
||||||
from psutil import virtual_memory
|
from psutil import virtual_memory
|
||||||
|
from i3pystatus.core.color import ColorRangeModule
|
||||||
from i3pystatus.core.util import make_bar
|
from i3pystatus.core.util import make_bar
|
||||||
|
|
||||||
|
|
||||||
class MemBar(IntervalModule):
|
class MemBar(IntervalModule, ColorRangeModule):
|
||||||
"""
|
"""
|
||||||
Shows memory load as a bar.
|
Shows memory load as a bar.
|
||||||
|
|
||||||
Available formatters:
|
Available formatters:
|
||||||
* {used_mem_bar}
|
* {used_mem_bar}
|
||||||
|
|
||||||
Requires psutil (from PyPI)
|
Requires psutil and colour (from PyPI)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
format = "{used_mem_bar}"
|
format = "{used_mem_bar}"
|
||||||
@ -19,6 +20,10 @@ class MemBar(IntervalModule):
|
|||||||
alert_color = "#FF0000"
|
alert_color = "#FF0000"
|
||||||
warn_percentage = 50
|
warn_percentage = 50
|
||||||
alert_percentage = 80
|
alert_percentage = 80
|
||||||
|
multi_colors = False
|
||||||
|
|
||||||
|
def init(self):
|
||||||
|
self.colors = self.get_hex_color_range(self.color, self.alert_color, 100)
|
||||||
|
|
||||||
settings = (
|
settings = (
|
||||||
("format", "format string used for output."),
|
("format", "format string used for output."),
|
||||||
@ -29,14 +34,16 @@ class MemBar(IntervalModule):
|
|||||||
"defines the color used wann warn percentage ist exceeded"),
|
"defines the color used wann warn percentage ist exceeded"),
|
||||||
("alert_color",
|
("alert_color",
|
||||||
"defines the color used when alert percentage is exceeded"),
|
"defines the color used when alert percentage is exceeded"),
|
||||||
|
("multi_colors", "whether to use range of colors from 'color' to 'alert_color' based on memory usage."),
|
||||||
)
|
)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
memory_usage = virtual_memory()
|
memory_usage = virtual_memory()
|
||||||
|
|
||||||
if memory_usage.percent >= self.alert_percentage:
|
if self.multi_colors:
|
||||||
|
color = self.get_gradient(memory_usage.percent, self.colors)
|
||||||
|
elif memory_usage.percent >= self.alert_percentage:
|
||||||
color = self.alert_color
|
color = self.alert_color
|
||||||
|
|
||||||
elif memory_usage.percent >= self.warn_percentage:
|
elif memory_usage.percent >= self.warn_percentage:
|
||||||
color = self.warn_color
|
color = self.warn_color
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user