diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 4651e5ac..0d75df51 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -379,10 +379,13 @@ Themes Segments are removed according to their priority, with low priority segments being removed first. - ``draw_divider`` + ``draw_hard_divider``, ``draw_soft_divider`` Whether to draw a divider between this and the adjacent segment. The - adjacent segment is to the *right* for segments on the *left* side, - and vice versa. + adjacent segment is to the *right* for segments on the *left* side, and + vice versa. Hard dividers are used between segments with different + background colors, soft ones are used between segments with same + background. These options may be overridden by return value of functions + segments. ``exclude_modes`` A list of modes where this segment will be excluded: The segment is diff --git a/powerline/config_files/themes/ipython/in.json b/powerline/config_files/themes/ipython/in.json index bf6be670..ac979c5f 100644 --- a/powerline/config_files/themes/ipython/in.json +++ b/powerline/config_files/themes/ipython/in.json @@ -8,13 +8,13 @@ { "type": "string", "contents": "In[", - "draw_divider": false, + "draw_soft_divider": false, "highlight_group": ["prompt"] }, { "name": "prompt_count", "module": "powerline.segments.ipython", - "draw_divider": false + "draw_soft_divider": false }, { "type": "string", diff --git a/powerline/config_files/themes/ipython/out.json b/powerline/config_files/themes/ipython/out.json index 6d4eac53..11a63234 100644 --- a/powerline/config_files/themes/ipython/out.json +++ b/powerline/config_files/themes/ipython/out.json @@ -5,7 +5,7 @@ { "type": "string", "contents": "Out[", - "draw_divider": false, + "draw_soft_divider": false, "width": "auto", "align": "r", "highlight_group": ["prompt"] @@ -13,7 +13,7 @@ { "name": "prompt_count", "module": "powerline.segments.ipython", - "draw_divider": false + "draw_soft_divider": false }, { "type": "string", diff --git a/powerline/config_files/themes/ipython/rewrite.json b/powerline/config_files/themes/ipython/rewrite.json index 4616769a..47d8de0d 100644 --- a/powerline/config_files/themes/ipython/rewrite.json +++ b/powerline/config_files/themes/ipython/rewrite.json @@ -4,14 +4,14 @@ { "type": "string", "contents": "", - "draw_divider": false, + "draw_soft_divider": false, "width": "auto", "highlight_group": ["prompt"] }, { "name": "prompt_count", "module": "powerline.segments.ipython", - "draw_divider": false + "draw_soft_divider": false }, { "type": "string", diff --git a/powerline/config_files/themes/vim/cmdwin.json b/powerline/config_files/themes/vim/cmdwin.json index cffd9e1c..c300d948 100644 --- a/powerline/config_files/themes/vim/cmdwin.json +++ b/powerline/config_files/themes/vim/cmdwin.json @@ -9,7 +9,8 @@ { "type": "string", "highlight_group": ["background"], - "draw_divider": false, + "draw_soft_divider": false, + "draw_hard_divider": false, "width": "auto" } ] diff --git a/powerline/config_files/themes/vim/default.json b/powerline/config_files/themes/vim/default.json index 3eeae293..40268a3f 100644 --- a/powerline/config_files/themes/vim/default.json +++ b/powerline/config_files/themes/vim/default.json @@ -32,22 +32,22 @@ }, { "name": "readonly_indicator", - "draw_divider": false, + "draw_soft_divider": false, "after": " " }, { "name": "file_directory", "priority": 40, - "draw_divider": false + "draw_soft_divider": false }, { "name": "file_name", - "draw_divider": false + "draw_soft_divider": false }, { "name": "file_vcs_status", "before": " ", - "draw_divider": false + "draw_soft_divider": false }, { "name": "modified_indicator", @@ -56,14 +56,15 @@ { "type": "string", "highlight_group": ["background"], - "draw_divider": false, + "draw_soft_divider": false, + "draw_hard_divider": false, "width": "auto" } ], "right": [ { "name": "file_format", - "draw_divider": false, + "draw_soft_divider": false, "exclude_modes": ["nc"], "priority": 50 }, @@ -90,13 +91,13 @@ }, { "name": "line_current", - "draw_divider": false, + "draw_soft_divider": false, "width": 3, "align": "r" }, { "name": "virtcol_current", - "draw_divider": false, + "draw_soft_divider": false, "priority": 30, "before": ":", "width": 3, diff --git a/powerline/config_files/themes/vim/help.json b/powerline/config_files/themes/vim/help.json index 9fb5320c..74071057 100644 --- a/powerline/config_files/themes/vim/help.json +++ b/powerline/config_files/themes/vim/help.json @@ -3,12 +3,13 @@ "left": [ { "name": "file_name", - "draw_divider": false + "draw_soft_divider": false }, { "type": "string", "highlight_group": ["background"], - "draw_divider": false, + "draw_soft_divider": false, + "draw_hard_divider": false, "width": "auto" } ], @@ -26,7 +27,7 @@ }, { "name": "line_current", - "draw_divider": false, + "draw_soft_divider": false, "width": 3, "align": "r" } diff --git a/powerline/lint/__init__.py b/powerline/lint/__init__.py index 31d70798..67de84ce 100644 --- a/powerline/lint/__init__.py +++ b/powerline/lint/__init__.py @@ -505,7 +505,7 @@ vim_colorscheme_spec = (Spec( ).context_message('Error while loading vim colorscheme')) -generic_keys = set(('exclude_modes', 'include_modes', 'width', 'align', 'name', 'draw_divider', 'priority', 'after', 'before')) +generic_keys = set(('exclude_modes', 'include_modes', 'width', 'align', 'name', 'draw_soft_divider', 'draw_hard_divider', 'priority', 'after', 'before')) type_keys = { 'function': set(('args', 'module')), 'string': set(('contents', 'type', 'highlight_group', 'divider_highlight_group')), @@ -797,7 +797,8 @@ segments_spec = Spec().optional().list( name=Spec().re('^[a-zA-Z_]\w+$').func(check_segment_name).optional(), exclude_modes=Spec().list(vim_mode_spec()).optional(), include_modes=Spec().list(vim_mode_spec()).optional(), - draw_divider=Spec().type(bool).optional(), + draw_hard_divider=Spec().type(bool).optional(), + draw_soft_divider=Spec().type(bool).optional(), module=segment_module_spec(), priority=Spec().cmp('ge', -1).optional(), after=Spec().type(unicode).optional(), diff --git a/powerline/renderer.py b/powerline/renderer.py index 6a2a62c4..324aa982 100644 --- a/powerline/renderer.py +++ b/powerline/renderer.py @@ -144,9 +144,10 @@ class Renderer(object): divider_highlighted = '' contents_raw = segment['contents'] contents_highlighted = '' + draw_divider = segment['draw_' + divider_type + '_divider'] # Pad segments first - if segment['draw_divider'] or (divider_type == 'hard' and segment['width'] != 'auto'): + if draw_divider: if segment['side'] == 'left': contents_raw = outer_padding + (segment['_space_left'] * ' ') + contents_raw + ((divider_spaces + segment['_space_right']) * ' ') else: @@ -174,7 +175,7 @@ class Renderer(object): contents_highlighted = self.hl(self.escape(contents_raw), **segment['highlight']) # Append padded raw and highlighted segments to the rendered segment variables - if segment['draw_divider'] or (divider_type == 'hard' and segment['width'] != 'auto'): + if draw_divider: if segment['side'] == 'left': segment['_rendered_raw'] += contents_raw + divider_raw segment['_rendered_hl'] += contents_highlighted + divider_highlighted diff --git a/powerline/segment.py b/powerline/segment.py index 8f166013..8d3c7623 100644 --- a/powerline/segment.py +++ b/powerline/segment.py @@ -74,7 +74,8 @@ def gen_segment_getter(ext, path, theme_configs, default_module=None): 'contents': contents, 'args': get_key(segment, module, 'args', {}) if segment_type == 'function' else {}, 'priority': segment.get('priority', -1), - 'draw_divider': segment.get('draw_divider', True), + 'draw_hard_divider': segment.get('draw_hard_divider', True), + 'draw_soft_divider': segment.get('draw_soft_divider', True), 'side': side, 'exclude_modes': segment.get('exclude_modes', []), 'include_modes': segment.get('include_modes', []), diff --git a/powerline/segments/common.py b/powerline/segments/common.py index d1a30d9b..7b7d79d9 100644 --- a/powerline/segments/common.py +++ b/powerline/segments/common.py @@ -438,7 +438,7 @@ class WeatherSegment(ThreadedSegment): { 'contents': temp_format.format(temp=converted_temp), 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], - 'draw_divider': False, + 'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'gradient_level': gradient_level, }, @@ -521,11 +521,11 @@ def system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2): ret.append({ 'contents': format.format(avg=avg), 'highlight_group': ['system_load_gradient', 'system_load'], - 'draw_divider': False, + 'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'gradient_level': gradient_level, }) - ret[0]['draw_divider'] = True + ret[0]['draw_soft_divider'] = True ret[0]['contents'] += ' ' ret[1]['contents'] += ' ' return ret diff --git a/tests/test_segments.py b/tests/test_segments.py index 40cc7cd0..74e5e966 100644 --- a/tests/test_segments.py +++ b/tests/test_segments.py @@ -175,35 +175,35 @@ class TestCommon(TestCase): with replace_attr(common, 'urllib_read', urllib_read): self.assertEqual(common.weather(pl=pl), [ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '}, - {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 30.0} + {'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 30.0} ]) self.assertEqual(common.weather(pl=pl, temp_coldest=0, temp_hottest=100), [ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '}, - {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 0} + {'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 0} ]) self.assertEqual(common.weather(pl=pl, temp_coldest=-100, temp_hottest=-50), [ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '}, - {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 100} + {'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 100} ]) self.assertEqual(common.weather(pl=pl, icons={'cloudy': 'o'}), [ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': 'o '}, - {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 30.0} + {'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 30.0} ]) self.assertEqual(common.weather(pl=pl, icons={'partly_cloudy_day': 'x'}), [ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': 'x '}, - {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 30.0} + {'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 30.0} ]) self.assertEqual(common.weather(pl=pl, unit='F'), [ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '}, - {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '16°F', 'gradient_level': 30.0} + {'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '16°F', 'gradient_level': 30.0} ]) self.assertEqual(common.weather(pl=pl, unit='K'), [ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '}, - {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '264K', 'gradient_level': 30.0} + {'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '264K', 'gradient_level': 30.0} ]) self.assertEqual(common.weather(pl=pl, temp_format='{temp:.1e}C'), [ {'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '}, - {'draw_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9.0e+00C', 'gradient_level': 30.0} + {'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9.0e+00C', 'gradient_level': 30.0} ]) def test_system_load(self): @@ -211,13 +211,13 @@ class TestCommon(TestCase): with replace_module_module(common, 'os', getloadavg=lambda: (7.5, 3.5, 1.5)): with replace_attr(common, 'cpu_count', lambda: 2): self.assertEqual(common.system_load(pl=pl), - [{'contents': '7.5 ', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_divider': True, 'divider_highlight_group': 'background:divider', 'gradient_level': 100}, - {'contents': '3.5 ', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_divider': False, 'divider_highlight_group': 'background:divider', 'gradient_level': 75.0}, - {'contents': '1.5', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_divider': False, 'divider_highlight_group': 'background:divider', 'gradient_level': 0}]) + [{'contents': '7.5 ', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_soft_divider': True, 'divider_highlight_group': 'background:divider', 'gradient_level': 100}, + {'contents': '3.5 ', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'gradient_level': 75.0}, + {'contents': '1.5', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'gradient_level': 0}]) self.assertEqual(common.system_load(pl=pl, format='{avg:.0f}', threshold_good=0, threshold_bad=1), - [{'contents': '8 ', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_divider': True, 'divider_highlight_group': 'background:divider', 'gradient_level': 100}, - {'contents': '4 ', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_divider': False, 'divider_highlight_group': 'background:divider', 'gradient_level': 100}, - {'contents': '2', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_divider': False, 'divider_highlight_group': 'background:divider', 'gradient_level': 75.0}]) + [{'contents': '8 ', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_soft_divider': True, 'divider_highlight_group': 'background:divider', 'gradient_level': 100}, + {'contents': '4 ', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'gradient_level': 100}, + {'contents': '2', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'gradient_level': 75.0}]) def test_cpu_load_percent(self): pl = Pl()