mirror of
https://github.com/powerline/powerline.git
synced 2025-07-25 23:05:32 +02:00
Add support for display option
This commit is contained in:
parent
90f3ca5afb
commit
16c01e8d64
@ -325,13 +325,14 @@ Themes
|
|||||||
A dict where keys are segment names or strings ``{module}.{name}``. Used to
|
A dict where keys are segment names or strings ``{module}.{name}``. Used to
|
||||||
specify default values for various keys:
|
specify default values for various keys:
|
||||||
:ref:`after <config-theme-seg-after>`,
|
:ref:`after <config-theme-seg-after>`,
|
||||||
|
:ref:`args <config-themes-seg-args>` (only for function segments),
|
||||||
:ref:`before <config-theme-seg-before>`,
|
:ref:`before <config-theme-seg-before>`,
|
||||||
:ref:`contents <config-theme-seg-contents>` (only for string segments
|
:ref:`contents <config-theme-seg-contents>` (only for string segments
|
||||||
if :ref:`name <config-themes-seg-name>` is defined),
|
if :ref:`name <config-themes-seg-name>` is defined),
|
||||||
:ref:`args <config-themes-seg-args>` (only for function segments). When
|
:ref:`display <config-theme-seg-display`.
|
||||||
using :ref:`local themes <config-ext-local_themes>` values of these keys are
|
When using :ref:`local themes <config-ext-local_themes>` values of these
|
||||||
first searched in the segment description, then in ``segment_data`` key of
|
keys are first searched in the segment description, then in ``segment_data``
|
||||||
a local theme, then in ``segment_data`` key of a :ref:`default theme
|
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
|
<config-ext-theme>`. For the :ref:`default theme <config-ext-theme>` itself
|
||||||
step 2 is obviously avoided.
|
step 2 is obviously avoided.
|
||||||
|
|
||||||
@ -455,6 +456,12 @@ Themes
|
|||||||
A list of modes where this segment will be included: The segment is
|
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.
|
*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
|
Segments
|
||||||
========
|
========
|
||||||
|
|
||||||
|
@ -668,17 +668,25 @@ shell_colorscheme_spec = (Spec(
|
|||||||
).context_message('Error while loading shell colorscheme'))
|
).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 = {
|
type_keys = {
|
||||||
'function': set(('args', 'module', 'draw_inner_divider')),
|
'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')),
|
||||||
}
|
}
|
||||||
required_keys = {
|
required_keys = {
|
||||||
'function': set(),
|
'function': set(),
|
||||||
'string': set(('contents',)),
|
'string': set(('contents',)),
|
||||||
'filler': set(),
|
'filler': set(),
|
||||||
}
|
}
|
||||||
function_keys = set(('args', 'module'))
|
function_keys = set(('args', 'module'))
|
||||||
highlight_keys = set(('highlight_group', 'name'))
|
highlight_keys = set(('highlight_group', 'name'))
|
||||||
|
|
||||||
@ -1071,6 +1079,7 @@ segments_spec = Spec().optional().list(
|
|||||||
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(),
|
draw_inner_divider=Spec().type(bool).optional(),
|
||||||
|
display=Spec().type(bool).optional(),
|
||||||
module=segment_module_spec(),
|
module=segment_module_spec(),
|
||||||
priority=Spec().type(int, float, type(None)).optional(),
|
priority=Spec().type(int, float, type(None)).optional(),
|
||||||
after=Spec().type(unicode).optional(),
|
after=Spec().type(unicode).optional(),
|
||||||
@ -1101,6 +1110,7 @@ theme_spec = (Spec(
|
|||||||
Spec(
|
Spec(
|
||||||
after=Spec().type(unicode).optional(),
|
after=Spec().type(unicode).optional(),
|
||||||
before=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)),
|
args=args_spec().func(lambda *args, **kwargs: check_args(get_all_possible_segments, *args, **kwargs)),
|
||||||
contents=Spec().type(unicode).optional(),
|
contents=Spec().type(unicode).optional(),
|
||||||
),
|
),
|
||||||
|
@ -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')
|
pl.exception('Failed to generate segment from {0!r}: {1}', segment, str(e), prefix='segment_generator')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if not get_key(segment, module, 'display', True):
|
||||||
|
return None
|
||||||
|
|
||||||
if segment_type == 'function':
|
if segment_type == 'function':
|
||||||
highlight_group = [module + '.' + segment['name'], segment['name']]
|
highlight_group = [module + '.' + segment['name'], segment['name']]
|
||||||
else:
|
else:
|
||||||
|
@ -49,14 +49,15 @@ class Theme(object):
|
|||||||
for side in ['left', 'right']:
|
for side in ['left', 'right']:
|
||||||
for segment in segdict.get(side, []):
|
for segment in segdict.get(side, []):
|
||||||
segment = get_segment(segment, side)
|
segment = get_segment(segment, side)
|
||||||
if not run_once:
|
if segment:
|
||||||
if segment['startup']:
|
if not run_once:
|
||||||
try:
|
if segment['startup']:
|
||||||
segment['startup'](pl, shutdown_event)
|
try:
|
||||||
except Exception as e:
|
segment['startup'](pl, shutdown_event)
|
||||||
pl.error('Exception during {0} startup: {1}', segment['name'], str(e))
|
except Exception as e:
|
||||||
continue
|
pl.error('Exception during {0} startup: {1}', segment['name'], str(e))
|
||||||
self.segments[-1][side].append(segment)
|
continue
|
||||||
|
self.segments[-1][side].append(segment)
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
for line in self.segments:
|
for line in self.segments:
|
||||||
|
@ -171,6 +171,16 @@ class TestLines(TestRender):
|
|||||||
], width=10)
|
], 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):
|
class TestColorschemesHierarchy(TestRender):
|
||||||
@add_p_arg
|
@add_p_arg
|
||||||
def test_group_redirects(self, p):
|
def test_group_redirects(self, p):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user