diff --git a/powerline/segments/common/sys.py b/powerline/segments/common/sys.py index f53e2c7d..a83025bf 100644 --- a/powerline/segments/common/sys.py +++ b/powerline/segments/common/sys.py @@ -13,7 +13,8 @@ from powerline.segments import with_docstring cpu_count = None -def system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2, track_cpu_count=False): +def system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2, + track_cpu_count=False, short=False): '''Return system load average. Highlights using ``system_load_good``, ``system_load_bad`` and @@ -35,6 +36,8 @@ def system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2, track :param bool track_cpu_count: if True powerline will continuously poll the system to detect changes in the number of CPUs. + :param bool short: + if True only the sys load over last 1 minute will be displayed. Divider highlight group used: ``background:divider``. @@ -61,6 +64,10 @@ def system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2, track 'divider_highlight_group': 'background:divider', 'gradient_level': gradient_level, }) + + if short: + return ret + ret[0]['contents'] += ' ' ret[1]['contents'] += ' ' return ret diff --git a/tests/test_segments.py b/tests/test_segments.py index 027d6227..0a7adcbf 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -811,6 +811,12 @@ class TestSys(TestCommon): {'contents': '4 ', 'highlight_groups': ['system_load_gradient', 'system_load'], 'divider_highlight_group': 'background:divider', 'gradient_level': 100}, {'contents': '2', 'highlight_groups': ['system_load_gradient', 'system_load'], 'divider_highlight_group': 'background:divider', 'gradient_level': 75.0} ]) + self.assertEqual(self.module.system_load(pl=pl, short=True), [ + {'contents': '7.5', 'highlight_groups': ['system_load_gradient', 'system_load'], 'divider_highlight_group': 'background:divider', 'gradient_level': 100}, + ]) + self.assertEqual(self.module.system_load(pl=pl, format='{avg:.0f}', threshold_good=0, threshold_bad=1, short=True), [ + {'contents': '8', 'highlight_groups': ['system_load_gradient', 'system_load'], 'divider_highlight_group': 'background:divider', 'gradient_level': 100}, + ]) def test_cpu_load_percent(self): try: