mirror of
https://github.com/powerline/powerline.git
synced 2025-07-21 04:44:55 +02:00
Add gradient for cpu_load_percent
Note: no changes to colorschemes: no cpu_load_percent in colorscheme
This commit is contained in:
parent
14b31eca35
commit
71329cdb5d
@ -572,7 +572,13 @@ try:
|
|||||||
self.exception('Exception while calculating cpu_percent: {0}', str(e))
|
self.exception('Exception while calculating cpu_percent: {0}', str(e))
|
||||||
|
|
||||||
def render(self, cpu_percent, format='{0:.0f}%', **kwargs):
|
def render(self, cpu_percent, format='{0:.0f}%', **kwargs):
|
||||||
return format.format(cpu_percent)
|
if not cpu_percent:
|
||||||
|
return None
|
||||||
|
return [{
|
||||||
|
'contents': format.format(cpu_percent),
|
||||||
|
'gradient_level': cpu_percent,
|
||||||
|
'highlight_group': ['cpu_load_percent_gradient', 'cpu_load_percent'],
|
||||||
|
}]
|
||||||
except ImportError:
|
except ImportError:
|
||||||
def _get_bytes(interface): # NOQA
|
def _get_bytes(interface): # NOQA
|
||||||
with open('/sys/class/net/{interface}/statistics/rx_bytes'.format(interface=interface), 'rb') as file_obj:
|
with open('/sys/class/net/{interface}/statistics/rx_bytes'.format(interface=interface), 'rb') as file_obj:
|
||||||
@ -618,6 +624,8 @@ Requires the ``psutil`` module.
|
|||||||
|
|
||||||
:param str format:
|
:param str format:
|
||||||
Output format. Accepts measured CPU load as the first argument.
|
Output format. Accepts measured CPU load as the first argument.
|
||||||
|
|
||||||
|
Highlight groups used: ``cpu_load_percent_gradient`` (gradient) or ``cpu_load_percent``.
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
|
||||||
|
@ -244,7 +244,16 @@ class TestCommon(TestCase):
|
|||||||
def test_cpu_load_percent(self):
|
def test_cpu_load_percent(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
with replace_module_module(common, 'psutil', cpu_percent=lambda **kwargs: 52.3):
|
with replace_module_module(common, 'psutil', cpu_percent=lambda **kwargs: 52.3):
|
||||||
self.assertEqual(common.cpu_load_percent(pl=pl), '52%')
|
self.assertEqual(common.cpu_load_percent(pl=pl), [{
|
||||||
|
'contents': '52%',
|
||||||
|
'gradient_level': 52.3,
|
||||||
|
'highlight_group': ['cpu_load_percent_gradient', 'cpu_load_percent'],
|
||||||
|
}])
|
||||||
|
self.assertEqual(common.cpu_load_percent(pl=pl, format='{0:.1f}%'), [{
|
||||||
|
'contents': '52.3%',
|
||||||
|
'gradient_level': 52.3,
|
||||||
|
'highlight_group': ['cpu_load_percent_gradient', 'cpu_load_percent'],
|
||||||
|
}])
|
||||||
|
|
||||||
def test_network_load(self):
|
def test_network_load(self):
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
Loading…
x
Reference in New Issue
Block a user