Filter segments using mode in Theme.get_segments
This commit is contained in:
parent
6481f1b65e
commit
974ec17bae
|
@ -147,10 +147,17 @@ class Renderer(object):
|
|||
'''
|
||||
self.theme.shutdown()
|
||||
|
||||
def _get_highlighting(self, segment, mode):
|
||||
segment['highlight'] = self.colorscheme.get_highlighting(segment['highlight_group'], mode, segment.get('gradient_level'))
|
||||
def _set_highlighting(self, segment):
|
||||
segment['highlight'] = self.colorscheme.get_highlighting(
|
||||
segment['highlight_group'],
|
||||
segment['mode'],
|
||||
segment.get('gradient_level')
|
||||
)
|
||||
if segment['divider_highlight_group']:
|
||||
segment['divider_highlight'] = self.colorscheme.get_highlighting(segment['divider_highlight_group'], mode)
|
||||
segment['divider_highlight'] = self.colorscheme.get_highlighting(
|
||||
segment['divider_highlight_group'],
|
||||
segment['mode']
|
||||
)
|
||||
else:
|
||||
segment['divider_highlight'] = None
|
||||
return segment
|
||||
|
@ -254,19 +261,10 @@ class Renderer(object):
|
|||
def do_render(self, mode, width, side, line, output_raw, output_width, segment_info, theme):
|
||||
'''Like Renderer.render(), but accept theme in place of matcher_info
|
||||
'''
|
||||
segments = theme.get_segments(side, line, self.get_segment_info(segment_info, mode))
|
||||
# Handle excluded/included segments for the current mode
|
||||
segments = [
|
||||
self._get_highlighting(segment, segment_mode)
|
||||
for segment, segment_mode in (
|
||||
(segment, segment['mode'] or mode)
|
||||
for segment in segments
|
||||
) if (
|
||||
segment_mode not in segment['exclude_modes']
|
||||
and (
|
||||
not segment['include_modes']
|
||||
or segment_mode in segment['include_modes']
|
||||
)
|
||||
self._set_highlighting(segment)
|
||||
for segment in (
|
||||
theme.get_segments(side, line, self.get_segment_info(segment_info, mode), mode)
|
||||
)
|
||||
]
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ class Theme(object):
|
|||
def get_line_number(self):
|
||||
return len(self.segments)
|
||||
|
||||
def get_segments(self, side=None, line=0, segment_info=None):
|
||||
def get_segments(self, side=None, line=0, segment_info=None, mode=None):
|
||||
'''Return all segments.
|
||||
|
||||
Function segments are called, and all segments get their before/after
|
||||
|
@ -103,8 +103,21 @@ class Theme(object):
|
|||
for side in [side] if side else ['left', 'right']:
|
||||
parsed_segments = []
|
||||
for segment in self.segments[line][side]:
|
||||
process_segment(self.pl, side, segment_info, parsed_segments, segment)
|
||||
# No segment-local modes at this point
|
||||
if mode not in segment['exclude_modes'] and (
|
||||
not segment['include_modes'] or mode in segment['include_modes']
|
||||
):
|
||||
process_segment(self.pl, side, segment_info, parsed_segments, segment)
|
||||
for segment in parsed_segments:
|
||||
segment_mode = segment['mode']
|
||||
if segment_mode and (
|
||||
segment_mode in segment['exclude_modes']
|
||||
or (
|
||||
segment['include_modes']
|
||||
and segment_mode not in segment['include_modes']
|
||||
)
|
||||
):
|
||||
continue
|
||||
segment['contents'] = segment['before'] + u(segment['contents'] if segment['contents'] is not None else '') + segment['after']
|
||||
# Align segment contents
|
||||
if segment['width'] and segment['width'] != 'auto':
|
||||
|
@ -117,4 +130,6 @@ class Theme(object):
|
|||
# We need to yield a copy of the segment, or else mode-dependent
|
||||
# segment contents can't be cached correctly e.g. when caching
|
||||
# non-current window contents for vim statuslines
|
||||
yield segment.copy()
|
||||
segment = segment.copy()
|
||||
segment['mode'] = segment_mode or mode
|
||||
yield segment
|
||||
|
|
Loading…
Reference in New Issue