Add support for display option

This commit is contained in:
ZyX 2014-07-12 23:39:45 +04:00
parent 90f3ca5afb
commit 16c01e8d64
5 changed files with 52 additions and 21 deletions

View File

@ -325,13 +325,14 @@ Themes
A dict where keys are segment names or strings ``{module}.{name}``. Used to
specify default values for various keys:
:ref:`after <config-theme-seg-after>`,
:ref:`args <config-themes-seg-args>` (only for function segments),
:ref:`before <config-theme-seg-before>`,
:ref:`contents <config-theme-seg-contents>` (only for string segments
if :ref:`name <config-themes-seg-name>` is defined),
:ref:`args <config-themes-seg-args>` (only for function segments). When
using :ref:`local themes <config-ext-local_themes>` values of these keys are
first searched in the segment description, then in ``segment_data`` key of
a local theme, then in ``segment_data`` key of a :ref:`default theme
:ref:`display <config-theme-seg-display`.
When using :ref:`local themes <config-ext-local_themes>` values of these
keys are first searched in the segment description, then in ``segment_data``
key of a local theme, then in ``segment_data`` key of a :ref:`default theme
<config-ext-theme>`. For the :ref:`default theme <config-ext-theme>` itself
step 2 is obviously avoided.
@ -455,6 +456,12 @@ Themes
A list of modes where this segment will be included: The segment is
*not* included in any modes, *except* for the modes in this list.
``display``
.. _config-themes-seg-display:
Boolean. If false disables displaying of the segment.
Defaults to ``True``.
Segments
========

View File

@ -668,17 +668,25 @@ shell_colorscheme_spec = (Spec(
).context_message('Error while loading shell colorscheme'))
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',
'display'
))
type_keys = {
'function': set(('args', 'module', 'draw_inner_divider')),
'string': set(('contents', 'type', 'highlight_group', 'divider_highlight_group')),
'filler': set(('type', 'highlight_group', 'divider_highlight_group')),
}
'function': set(('args', 'module', 'draw_inner_divider')),
'string': set(('contents', 'type', 'highlight_group', 'divider_highlight_group')),
'filler': set(('type', 'highlight_group', 'divider_highlight_group')),
}
required_keys = {
'function': set(),
'string': set(('contents',)),
'filler': set(),
}
'function': set(),
'string': set(('contents',)),
'filler': set(),
}
function_keys = set(('args', 'module'))
highlight_keys = set(('highlight_group', 'name'))
@ -1071,6 +1079,7 @@ segments_spec = Spec().optional().list(
draw_hard_divider=Spec().type(bool).optional(),
draw_soft_divider=Spec().type(bool).optional(),
draw_inner_divider=Spec().type(bool).optional(),
display=Spec().type(bool).optional(),
module=segment_module_spec(),
priority=Spec().type(int, float, type(None)).optional(),
after=Spec().type(unicode).optional(),
@ -1101,6 +1110,7 @@ theme_spec = (Spec(
Spec(
after=Spec().type(unicode).optional(),
before=Spec().type(unicode).optional(),
display=Spec().type(bool).optional(),
args=args_spec().func(lambda *args, **kwargs: check_args(get_all_possible_segments, *args, **kwargs)),
contents=Spec().type(unicode).optional(),
),

View File

@ -82,6 +82,9 @@ def gen_segment_getter(pl, ext, common_config, theme_configs, default_module=Non
pl.exception('Failed to generate segment from {0!r}: {1}', segment, str(e), prefix='segment_generator')
return None
if not get_key(segment, module, 'display', True):
return None
if segment_type == 'function':
highlight_group = [module + '.' + segment['name'], segment['name']]
else:

View File

@ -49,14 +49,15 @@ class Theme(object):
for side in ['left', 'right']:
for segment in segdict.get(side, []):
segment = get_segment(segment, side)
if not run_once:
if segment['startup']:
try:
segment['startup'](pl, shutdown_event)
except Exception as e:
pl.error('Exception during {0} startup: {1}', segment['name'], str(e))
continue
self.segments[-1][side].append(segment)
if segment:
if not run_once:
if segment['startup']:
try:
segment['startup'](pl, shutdown_event)
except Exception as e:
pl.error('Exception during {0} startup: {1}', segment['name'], str(e))
continue
self.segments[-1][side].append(segment)
def shutdown(self):
for line in self.segments:

View File

@ -171,6 +171,16 @@ class TestLines(TestRender):
], width=10)
class TestSegments(TestRender):
@add_p_arg
def test_display(self, p):
with replace_item(globals(), 'config', deepcopy(config)):
config['themes/test/default']['segments']['left'][0]['display'] = False
config['themes/test/default']['segments']['left'][1]['display'] = True
config['themes/test/default']['segments']['right'][0]['display'] = False
self.assertRenderEqual(p, '{344} g{4-}>>{--}')
class TestColorschemesHierarchy(TestRender):
@add_p_arg
def test_group_redirects(self, p):