Replace draw_divider setting with draw_(soft|hard)_divider
Previous variant was bad because 1. draw_divider only applied to soft dividers. Hard dividers were always drawn 2. But there was a hack with width=auto segments: for this segments draw_divider setting applied always. Now there are no additional dependencies: draw_*_divider applies no matter what other properties of the segment are.
This commit is contained in:
parent
fcc009a6f5
commit
f15cdd9413
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
{
|
||||
"type": "string",
|
||||
"highlight_group": ["background"],
|
||||
"draw_divider": false,
|
||||
"draw_soft_divider": false,
|
||||
"draw_hard_divider": false,
|
||||
"width": "auto"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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', []),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue