Special-case None priority in place of -1

This extends priorities in both directions, uses slightly faster `is None`
check, makes it consistent with `interval` special-casing also to `None` and
makes lint able to use one simple `.type()` check in place of `.either()` one.
This commit is contained in:
ZyX 2013-04-09 08:18:37 +04:00
parent 49618fc4e3
commit a8eb0a2471
4 changed files with 8 additions and 9 deletions

View File

@ -377,14 +377,13 @@ Themes
can be aligned with the ``align`` property. can be aligned with the ``align`` property.
``priority`` ``priority``
Optional segment priority. Segments with priority ``-1`` (the Optional segment priority. Segments with priority ``None`` (the default
default priority) will always be included, regardless of the width priority, represented by ``null`` in json) will always be included,
of the prompt/statusline. regardless of the width of the prompt/statusline.
If the priority is ``0`` or more, the segment may be removed if the If the priority is any number, the segment may be removed if the
prompt/statusline width is too small for all the segments to be prompt/statusline width is too small for all the segments to be
rendered. A lower number means that the segment has a higher rendered. A lower number means that the segment has a higher priority.
priority.
Segments are removed according to their priority, with low priority Segments are removed according to their priority, with low priority
segments being removed first. segments being removed first.

View File

@ -818,7 +818,7 @@ segments_spec = Spec().optional().list(
draw_soft_divider=Spec().type(bool).optional(), draw_soft_divider=Spec().type(bool).optional(),
draw_inner_divider=Spec().type(bool).optional(), draw_inner_divider=Spec().type(bool).optional(),
module=segment_module_spec(), module=segment_module_spec(),
priority=Spec().either(Spec().cmp('eq', -1), Spec().cmp('ge', 0.0)).optional(), priority=Spec().type(int, float, type(None)).optional(),
after=Spec().type(unicode).optional(), after=Spec().type(unicode).optional(),
before=Spec().type(unicode).optional(), before=Spec().type(unicode).optional(),
width=Spec().either(Spec().unsigned(), Spec().cmp('eq', 'auto')).optional(), width=Spec().either(Spec().unsigned(), Spec().cmp('eq', 'auto')).optional(),

View File

@ -195,7 +195,7 @@ class Renderer(object):
return construct_returned_value(''.join([segment['_rendered_hl'] for segment in segments]) + self.hlstyle(), segments, output_raw) return construct_returned_value(''.join([segment['_rendered_hl'] for segment in segments]) + self.hlstyle(), segments, output_raw)
# Create an ordered list of segments that can be dropped # Create an ordered list of segments that can be dropped
segments_priority = [segment for segment in sorted(segments, key=lambda segment: segment['priority'], reverse=True) if segment['priority'] > 0] segments_priority = [segment for segment in sorted(segments, key=lambda segment: segment['priority'], reverse=True) if segment['priority'] is not None]
while sum([segment['_len'] for segment in segments]) > width and len(segments_priority): while sum([segment['_len'] for segment in segments]) > width and len(segments_priority):
segments.remove(segments_priority[0]) segments.remove(segments_priority[0])
segments_priority.pop(0) segments_priority.pop(0)

View File

@ -73,7 +73,7 @@ def gen_segment_getter(ext, path, theme_configs, default_module=None):
'contents_func': contents_func, 'contents_func': contents_func,
'contents': contents, 'contents': contents,
'args': get_key(segment, module, 'args', {}) if segment_type == 'function' else {}, 'args': get_key(segment, module, 'args', {}) if segment_type == 'function' else {},
'priority': segment.get('priority', -1), 'priority': segment.get('priority', None),
'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), 'draw_inner_divider': segment.get('draw_inner_divider', False),