From acb7c27a88aebc2c188952e9c1f8987927a7c503 Mon Sep 17 00:00:00 2001 From: Foo Date: Sun, 17 May 2015 11:35:27 +0300 Subject: [PATCH] Use different highlight group for network_load divider Fixes #1368 --- .../config_files/colorschemes/default.json | 1 + .../config_files/colorschemes/solarized.json | 1 + powerline/segments/common/net.py | 4 +-- tests/test_segments.py | 27 +++++++++---------- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/powerline/config_files/colorschemes/default.json b/powerline/config_files/colorschemes/default.json index 53ea5b0a..61b8cc36 100644 --- a/powerline/config_files/colorschemes/default.json +++ b/powerline/config_files/colorschemes/default.json @@ -27,6 +27,7 @@ "internal_ip": { "fg": "gray8", "bg": "gray0", "attrs": [] }, "network_load": { "fg": "gray8", "bg": "gray0", "attrs": [] }, "network_load_gradient": { "fg": "green_yellow_orange_red", "bg": "gray0", "attrs": [] }, + "network_load:divider": "background:divider", "system_load": { "fg": "gray8", "bg": "gray0", "attrs": [] }, "system_load_gradient": { "fg": "green_yellow_orange_red", "bg": "gray0", "attrs": [] }, "environment": { "fg": "gray8", "bg": "gray0", "attrs": [] }, diff --git a/powerline/config_files/colorschemes/solarized.json b/powerline/config_files/colorschemes/solarized.json index 4c90706e..e858e68c 100644 --- a/powerline/config_files/colorschemes/solarized.json +++ b/powerline/config_files/colorschemes/solarized.json @@ -21,6 +21,7 @@ "cwd:current_folder": "information:regular", "cwd:divider": { "fg": "solarized:base1", "bg": "solarized:base01", "attrs": [] }, "network_load": { "fg": "solarized:base1", "bg": "solarized:base03", "attrs": [] }, + "network_load:divider": { "fg": "solarized:base1", "bg": "solarized:base03", "attrs": [] }, "hostname": { "fg": "solarized:base3", "bg": "solarized:base01", "attrs": [] }, "environment": { "fg": "solarized:base3", "bg": "solarized:green", "attrs": [] }, "attached_clients": { "fg": "solarized:base3", "bg": "solarized:green", "attrs": [] }, diff --git a/powerline/segments/common/net.py b/powerline/segments/common/net.py index 46a294db..46243c66 100644 --- a/powerline/segments/common/net.py +++ b/powerline/segments/common/net.py @@ -247,7 +247,7 @@ class NetworkLoadSegment(KwThreadedSegment): hl_groups[:0] = (group + '_gradient' for group in hl_groups) r.append({ 'contents': format.format(value=humanize_bytes(value, suffix, si_prefix)), - 'divider_highlight_group': 'background:divider', + 'divider_highlight_group': 'network_load:divider', 'highlight_groups': hl_groups, }) if is_gradient: @@ -287,7 +287,7 @@ falls back to reading Maximum number of sent bytes per second. Is only used to compute gradient level. -Divider highlight group used: ``background:divider``. +Divider highlight group used: ``network_load:divider``. Highlight groups used: ``network_load_sent_gradient`` (gradient) or ``network_load_recv_gradient`` (gradient) or ``network_load_gradient`` (gradient), ``network_load_sent`` or ``network_load_recv`` or ``network_load``. ''') diff --git a/tests/test_segments.py b/tests/test_segments.py index 08fc520b..45aee72d 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -6,6 +6,7 @@ import os from functools import partial from collections import namedtuple +from time import sleep from powerline.segments import shell, tmux, pdb from powerline.lib.vcs import get_fallback_create_watcher @@ -397,8 +398,6 @@ class TestNet(TestCommon): self.assertEqual(self.module.internal_ip(pl=pl, ipv=6), None) def test_network_load(self): - from time import sleep - def gb(interface): return None @@ -430,24 +429,24 @@ class TestNet(TestCommon): while not self.module.network_load.interfaces.get('eth0', {}).get('prev', (None, None))[1]: sleep(0.1) self.assertEqual(self.module.network_load(pl=pl, interface='eth0'), [ - {'divider_highlight_group': 'background:divider', 'contents': 'DL 1 KiB/s', 'highlight_groups': ['network_load_recv', 'network_load']}, - {'divider_highlight_group': 'background:divider', 'contents': 'UL 2 KiB/s', 'highlight_groups': ['network_load_sent', 'network_load']}, + {'divider_highlight_group': 'network_load:divider', 'contents': 'DL 1 KiB/s', 'highlight_groups': ['network_load_recv', 'network_load']}, + {'divider_highlight_group': 'network_load:divider', 'contents': 'UL 2 KiB/s', 'highlight_groups': ['network_load_sent', 'network_load']}, ]) self.assertEqual(self.module.network_load(pl=pl, interface='eth0', recv_format='r {value}', sent_format='s {value}'), [ - {'divider_highlight_group': 'background:divider', 'contents': 'r 1 KiB/s', 'highlight_groups': ['network_load_recv', 'network_load']}, - {'divider_highlight_group': 'background:divider', 'contents': 's 2 KiB/s', 'highlight_groups': ['network_load_sent', 'network_load']}, + {'divider_highlight_group': 'network_load:divider', 'contents': 'r 1 KiB/s', 'highlight_groups': ['network_load_recv', 'network_load']}, + {'divider_highlight_group': 'network_load:divider', 'contents': 's 2 KiB/s', 'highlight_groups': ['network_load_sent', 'network_load']}, ]) self.assertEqual(self.module.network_load(pl=pl, recv_format='r {value}', sent_format='s {value}', suffix='bps', interface='eth0'), [ - {'divider_highlight_group': 'background:divider', 'contents': 'r 1 Kibps', 'highlight_groups': ['network_load_recv', 'network_load']}, - {'divider_highlight_group': 'background:divider', 'contents': 's 2 Kibps', 'highlight_groups': ['network_load_sent', 'network_load']}, + {'divider_highlight_group': 'network_load:divider', 'contents': 'r 1 Kibps', 'highlight_groups': ['network_load_recv', 'network_load']}, + {'divider_highlight_group': 'network_load:divider', 'contents': 's 2 Kibps', 'highlight_groups': ['network_load_sent', 'network_load']}, ]) self.assertEqual(self.module.network_load(pl=pl, recv_format='r {value}', sent_format='s {value}', si_prefix=True, interface='eth0'), [ - {'divider_highlight_group': 'background:divider', 'contents': 'r 1 kB/s', 'highlight_groups': ['network_load_recv', 'network_load']}, - {'divider_highlight_group': 'background:divider', 'contents': 's 2 kB/s', 'highlight_groups': ['network_load_sent', 'network_load']}, + {'divider_highlight_group': 'network_load:divider', 'contents': 'r 1 kB/s', 'highlight_groups': ['network_load_recv', 'network_load']}, + {'divider_highlight_group': 'network_load:divider', 'contents': 's 2 kB/s', 'highlight_groups': ['network_load_sent', 'network_load']}, ]) self.assertEqual(self.module.network_load(pl=pl, recv_format='r {value}', sent_format='s {value}', recv_max=0, interface='eth0'), [ - {'divider_highlight_group': 'background:divider', 'contents': 'r 1 KiB/s', 'highlight_groups': ['network_load_recv_gradient', 'network_load_gradient', 'network_load_recv', 'network_load'], 'gradient_level': 100}, - {'divider_highlight_group': 'background:divider', 'contents': 's 2 KiB/s', 'highlight_groups': ['network_load_sent', 'network_load']}, + {'divider_highlight_group': 'network_load:divider', 'contents': 'r 1 KiB/s', 'highlight_groups': ['network_load_recv_gradient', 'network_load_gradient', 'network_load_recv', 'network_load'], 'gradient_level': 100}, + {'divider_highlight_group': 'network_load:divider', 'contents': 's 2 KiB/s', 'highlight_groups': ['network_load_sent', 'network_load']}, ]) class ApproxEqual(object): @@ -455,8 +454,8 @@ class TestNet(TestCommon): return abs(i - 50.0) < 1 self.assertEqual(self.module.network_load(pl=pl, recv_format='r {value}', sent_format='s {value}', sent_max=4800, interface='eth0'), [ - {'divider_highlight_group': 'background:divider', 'contents': 'r 1 KiB/s', 'highlight_groups': ['network_load_recv', 'network_load']}, - {'divider_highlight_group': 'background:divider', 'contents': 's 2 KiB/s', 'highlight_groups': ['network_load_sent_gradient', 'network_load_gradient', 'network_load_sent', 'network_load'], 'gradient_level': ApproxEqual()}, + {'divider_highlight_group': 'network_load:divider', 'contents': 'r 1 KiB/s', 'highlight_groups': ['network_load_recv', 'network_load']}, + {'divider_highlight_group': 'network_load:divider', 'contents': 's 2 KiB/s', 'highlight_groups': ['network_load_sent_gradient', 'network_load_gradient', 'network_load_sent', 'network_load'], 'gradient_level': ApproxEqual()}, ]) finally: self.module.network_load.shutdown()