mirror of
https://github.com/powerline/powerline.git
synced 2025-07-23 05:46:01 +02:00
Replace draw_soft_divider setting with draw_inner_divider
If weather or system_load segments were moved to the left draw_soft_divider variant resulted in incorrect renderring. Thus it was replaced by draw_inner_divider.
This commit is contained in:
parent
f15cdd9413
commit
66beaaaa9d
@ -384,8 +384,12 @@ Themes
|
|||||||
adjacent segment is to the *right* for segments on the *left* side, and
|
adjacent segment is to the *right* for segments on the *left* side, and
|
||||||
vice versa. Hard dividers are used between segments with different
|
vice versa. Hard dividers are used between segments with different
|
||||||
background colors, soft ones are used between segments with same
|
background colors, soft ones are used between segments with same
|
||||||
background. These options may be overridden by return value of functions
|
background. Both options default to ``True``.
|
||||||
segments.
|
|
||||||
|
``draw_inner_divider``
|
||||||
|
Determines whether inner soft dividers are to be drawn for function
|
||||||
|
segments. Only applicable for functions returning multiple segments.
|
||||||
|
Defaults to ``False``.
|
||||||
|
|
||||||
``exclude_modes``
|
``exclude_modes``
|
||||||
A list of modes where this segment will be excluded: The segment is
|
A list of modes where this segment will be excluded: The segment is
|
||||||
|
@ -507,7 +507,7 @@ vim_colorscheme_spec = (Spec(
|
|||||||
|
|
||||||
generic_keys = set(('exclude_modes', 'include_modes', 'width', 'align', 'name', 'draw_soft_divider', 'draw_hard_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 = {
|
type_keys = {
|
||||||
'function': set(('args', 'module')),
|
'function': set(('args', 'module', 'draw_inner_divider')),
|
||||||
'string': set(('contents', 'type', 'highlight_group', 'divider_highlight_group')),
|
'string': set(('contents', 'type', 'highlight_group', 'divider_highlight_group')),
|
||||||
'filler': set(('type', 'highlight_group', 'divider_highlight_group')),
|
'filler': set(('type', 'highlight_group', 'divider_highlight_group')),
|
||||||
}
|
}
|
||||||
@ -799,6 +799,7 @@ segments_spec = Spec().optional().list(
|
|||||||
include_modes=Spec().list(vim_mode_spec()).optional(),
|
include_modes=Spec().list(vim_mode_spec()).optional(),
|
||||||
draw_hard_divider=Spec().type(bool).optional(),
|
draw_hard_divider=Spec().type(bool).optional(),
|
||||||
draw_soft_divider=Spec().type(bool).optional(),
|
draw_soft_divider=Spec().type(bool).optional(),
|
||||||
|
draw_inner_divider=Spec().type(bool).optional(),
|
||||||
module=segment_module_spec(),
|
module=segment_module_spec(),
|
||||||
priority=Spec().cmp('ge', -1).optional(),
|
priority=Spec().cmp('ge', -1).optional(),
|
||||||
after=Spec().type(unicode).optional(),
|
after=Spec().type(unicode).optional(),
|
||||||
|
@ -76,6 +76,7 @@ def gen_segment_getter(ext, path, theme_configs, default_module=None):
|
|||||||
'priority': segment.get('priority', -1),
|
'priority': segment.get('priority', -1),
|
||||||
'draw_hard_divider': segment.get('draw_hard_divider', True),
|
'draw_hard_divider': segment.get('draw_hard_divider', True),
|
||||||
'draw_soft_divider': segment.get('draw_soft_divider', True),
|
'draw_soft_divider': segment.get('draw_soft_divider', True),
|
||||||
|
'draw_inner_divider': segment.get('draw_inner_divider', False),
|
||||||
'side': side,
|
'side': side,
|
||||||
'exclude_modes': segment.get('exclude_modes', []),
|
'exclude_modes': segment.get('exclude_modes', []),
|
||||||
'include_modes': segment.get('include_modes', []),
|
'include_modes': segment.get('include_modes', []),
|
||||||
|
@ -438,7 +438,6 @@ class WeatherSegment(ThreadedSegment):
|
|||||||
{
|
{
|
||||||
'contents': temp_format.format(temp=converted_temp),
|
'contents': temp_format.format(temp=converted_temp),
|
||||||
'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'],
|
'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'],
|
||||||
'draw_soft_divider': False,
|
|
||||||
'divider_highlight_group': 'background:divider',
|
'divider_highlight_group': 'background:divider',
|
||||||
'gradient_level': gradient_level,
|
'gradient_level': gradient_level,
|
||||||
},
|
},
|
||||||
@ -521,11 +520,9 @@ def system_load(pl, format='{avg:.1f}', threshold_good=1, threshold_bad=2):
|
|||||||
ret.append({
|
ret.append({
|
||||||
'contents': format.format(avg=avg),
|
'contents': format.format(avg=avg),
|
||||||
'highlight_group': ['system_load_gradient', 'system_load'],
|
'highlight_group': ['system_load_gradient', 'system_load'],
|
||||||
'draw_soft_divider': False,
|
|
||||||
'divider_highlight_group': 'background:divider',
|
'divider_highlight_group': 'background:divider',
|
||||||
'gradient_level': gradient_level,
|
'gradient_level': gradient_level,
|
||||||
})
|
})
|
||||||
ret[0]['draw_soft_divider'] = True
|
|
||||||
ret[0]['contents'] += ' '
|
ret[0]['contents'] += ' '
|
||||||
ret[1]['contents'] += ' '
|
ret[1]['contents'] += ' '
|
||||||
return ret
|
return ret
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
# vim:fileencoding=utf-8:noet
|
# vim:fileencoding=utf-8:noet
|
||||||
|
|
||||||
from copy import copy
|
|
||||||
|
|
||||||
from .segment import gen_segment_getter
|
from .segment import gen_segment_getter
|
||||||
|
|
||||||
|
|
||||||
@ -91,19 +89,35 @@ class Theme(object):
|
|||||||
if contents is None:
|
if contents is None:
|
||||||
continue
|
continue
|
||||||
if isinstance(contents, list):
|
if isinstance(contents, list):
|
||||||
segment_base = copy(segment)
|
segment_base = segment.copy()
|
||||||
if contents:
|
if contents:
|
||||||
for key in ('before', 'after'):
|
draw_divider_position = -1 if side == 'left' else 0
|
||||||
|
for key, i, newval in (
|
||||||
|
('before', 0, ''),
|
||||||
|
('after', -1, ''),
|
||||||
|
('draw_soft_divider', draw_divider_position, True),
|
||||||
|
('draw_hard_divider', draw_divider_position, True),
|
||||||
|
):
|
||||||
try:
|
try:
|
||||||
contents[0][key] = segment_base.pop(key)
|
contents[i][key] = segment_base.pop(key)
|
||||||
segment_base[key] = ''
|
segment_base[key] = newval
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
for subsegment in contents:
|
draw_inner_divider = None
|
||||||
segment_copy = copy(segment_base)
|
if side == 'right':
|
||||||
|
append = parsed_segments.append
|
||||||
|
else:
|
||||||
|
pslen = len(parsed_segments)
|
||||||
|
append = lambda item: parsed_segments.insert(pslen, item)
|
||||||
|
|
||||||
|
for subsegment in (contents if side == 'right' else reversed(contents)):
|
||||||
|
segment_copy = segment_base.copy()
|
||||||
segment_copy.update(subsegment)
|
segment_copy.update(subsegment)
|
||||||
parsed_segments.append(segment_copy)
|
if draw_inner_divider is not None:
|
||||||
|
segment_copy['draw_soft_divider'] = draw_inner_divider
|
||||||
|
draw_inner_divider = segment_copy.pop('draw_inner_divider', None)
|
||||||
|
append(segment_copy)
|
||||||
else:
|
else:
|
||||||
segment['contents'] = contents
|
segment['contents'] = contents
|
||||||
parsed_segments.append(segment)
|
parsed_segments.append(segment)
|
||||||
@ -124,4 +138,4 @@ class Theme(object):
|
|||||||
# We need to yield a copy of the segment, or else mode-dependent
|
# We need to yield a copy of the segment, or else mode-dependent
|
||||||
# segment contents can't be cached correctly e.g. when caching
|
# segment contents can't be cached correctly e.g. when caching
|
||||||
# non-current window contents for vim statuslines
|
# non-current window contents for vim statuslines
|
||||||
yield copy(segment)
|
yield segment.copy()
|
||||||
|
@ -175,35 +175,35 @@ class TestCommon(TestCase):
|
|||||||
with replace_attr(common, 'urllib_read', urllib_read):
|
with replace_attr(common, 'urllib_read', urllib_read):
|
||||||
self.assertEqual(common.weather(pl=pl), [
|
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': '☁ '},
|
{'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '},
|
||||||
{'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 30.0}
|
{'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), [
|
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': '☁ '},
|
{'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '},
|
||||||
{'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 0}
|
{'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), [
|
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': '☁ '},
|
{'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '},
|
||||||
{'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 100}
|
{'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'}), [
|
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 '},
|
{'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': 'o '},
|
||||||
{'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 30.0}
|
{'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'}), [
|
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 '},
|
{'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': 'x '},
|
||||||
{'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '-9°C', 'gradient_level': 30.0}
|
{'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'), [
|
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': '☁ '},
|
{'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '},
|
||||||
{'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '16°F', 'gradient_level': 30.0}
|
{'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'), [
|
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': '☁ '},
|
{'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '},
|
||||||
{'draw_soft_divider': False, 'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '264K', 'gradient_level': 30.0}
|
{'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'), [
|
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': '☁ '},
|
{'divider_highlight_group': 'background:divider', 'highlight_group': ['weather_condition_partly_cloudy_day', 'weather_condition_cloudy', 'weather_conditions', 'weather'], 'contents': '☁ '},
|
||||||
{'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}
|
{'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):
|
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_module_module(common, 'os', getloadavg=lambda: (7.5, 3.5, 1.5)):
|
||||||
with replace_attr(common, 'cpu_count', lambda: 2):
|
with replace_attr(common, 'cpu_count', lambda: 2):
|
||||||
self.assertEqual(common.system_load(pl=pl),
|
self.assertEqual(common.system_load(pl=pl),
|
||||||
[{'contents': '7.5 ', 'highlight_group': ['system_load_gradient', 'system_load'], 'draw_soft_divider': True, 'divider_highlight_group': 'background:divider', 'gradient_level': 100},
|
[{'contents': '7.5 ', 'highlight_group': ['system_load_gradient', 'system_load'], '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': '3.5 ', 'highlight_group': ['system_load_gradient', 'system_load'], '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}])
|
{'contents': '1.5', 'highlight_group': ['system_load_gradient', 'system_load'], 'divider_highlight_group': 'background:divider', 'gradient_level': 0}])
|
||||||
self.assertEqual(common.system_load(pl=pl, format='{avg:.0f}', threshold_good=0, threshold_bad=1),
|
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_soft_divider': True, 'divider_highlight_group': 'background:divider', 'gradient_level': 100},
|
[{'contents': '8 ', 'highlight_group': ['system_load_gradient', 'system_load'], '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': '4 ', 'highlight_group': ['system_load_gradient', 'system_load'], '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}])
|
{'contents': '2', 'highlight_group': ['system_load_gradient', 'system_load'], 'divider_highlight_group': 'background:divider', 'gradient_level': 75.0}])
|
||||||
|
|
||||||
def test_cpu_load_percent(self):
|
def test_cpu_load_percent(self):
|
||||||
pl = Pl()
|
pl = Pl()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user