Skip identical highlighting

Fixes #1049
This commit is contained in:
ZyX 2014-09-05 08:13:35 +04:00
parent 1a5bbbea96
commit d569c0b3dd
3 changed files with 40 additions and 35 deletions

View File

@ -360,50 +360,46 @@ class Renderer(object):
contents_highlighted = ''
draw_divider = segment['draw_' + divider_type + '_divider']
# Pad segments first
contents_raw = contents_raw.translate(self.np_character_translations)
# XXX Make sure self.hl() calls are called in the same order
# segments are displayed. This is needed for Vim renderer to work.
if draw_divider:
divider_raw = self.escape(theme.get_divider(side, divider_type))
if side == 'left':
contents_raw = outer_padding + contents_raw + (divider_spaces * ' ')
else:
contents_raw = (divider_spaces * ' ') + contents_raw + outer_padding
if divider_type == 'soft':
divider_highlight_group_key = 'highlight' if segment['divider_highlight_group'] is None else 'divider_highlight'
divider_fg = segment[divider_highlight_group_key]['fg']
divider_bg = segment[divider_highlight_group_key]['bg']
else:
divider_fg = segment['highlight']['bg']
divider_bg = compare_segment['highlight']['bg']
if side == 'left':
if render_highlighted:
contents_highlighted = self.hl(self.escape(contents_raw), **segment['highlight'])
divider_highlighted = self.hl(divider_raw, divider_fg, divider_bg, False)
segment['_rendered_raw'] = contents_raw + divider_raw
segment['_rendered_hl'] = contents_highlighted + divider_highlighted
else:
if render_highlighted:
divider_highlighted = self.hl(divider_raw, divider_fg, divider_bg, False)
contents_highlighted = self.hl(self.escape(contents_raw), **segment['highlight'])
segment['_rendered_raw'] = divider_raw + contents_raw
segment['_rendered_hl'] = divider_highlighted + contents_highlighted
else:
if side == 'left':
contents_raw = outer_padding + contents_raw
else:
contents_raw = contents_raw + outer_padding
# Replace spaces with no-break spaces
contents_raw = contents_raw.translate(self.np_character_translations)
# Apply highlighting to padded dividers and contents
if render_highlighted:
if draw_divider:
if divider_type == 'soft':
divider_highlight_group_key = 'highlight' if segment['divider_highlight_group'] is None else 'divider_highlight'
divider_fg = segment[divider_highlight_group_key]['fg']
divider_bg = segment[divider_highlight_group_key]['bg']
else:
divider_fg = segment['highlight']['bg']
divider_bg = compare_segment['highlight']['bg']
divider_highlighted = self.hl(divider_raw, divider_fg, divider_bg, False)
contents_highlighted = self.hl(self.escape(contents_raw), **segment['highlight'])
# Append padded raw and highlighted segments to the rendered segment variables
if draw_divider:
if side == 'left':
segment['_rendered_raw'] = contents_raw + divider_raw
segment['_rendered_hl'] = contents_highlighted + divider_highlighted
else:
segment['_rendered_raw'] = divider_raw + contents_raw
segment['_rendered_hl'] = divider_highlighted + contents_highlighted
else:
if side == 'left':
segment['_rendered_raw'] = contents_raw
segment['_rendered_hl'] = contents_highlighted
else:
segment['_rendered_raw'] = contents_raw
segment['_rendered_hl'] = contents_highlighted
segment['_rendered_raw'] = contents_raw
segment['_rendered_hl'] = contents_highlighted
yield segment
def escape(self, string):

View File

@ -40,6 +40,7 @@ class VimRenderer(Renderer):
kwargs['ambigious'] = 2
super(VimRenderer, self).__init__(*args, **kwargs)
self.hl_groups = {}
self.prev_highlight = None
def shutdown(self):
self.theme.shutdown()
@ -126,7 +127,15 @@ class VimRenderer(Renderer):
False, the argument is reset to the terminal defaults. If an argument
is a valid color or attribute, it's added to the vim highlight group.
'''
# We don't need to explicitly reset attributes in vim, so skip those calls
# In order not to hit E541 two consequent identical highlighting
# specifiers may be squashed into one.
attr = attr or 0 # Normalize `attr`
if (fg, bg, attr) == self.prev_highlight:
return ''
self.prev_highlight = (fg, bg, attr)
# We don't need to explicitly reset attributes in vim, so skip those
# calls
if not attr and not bg and not fg:
return ''

View File

@ -16,7 +16,7 @@ catch
cquit
endtry
if result isnot# '%#Pl_247_10395294_236_3158064_NONE# 1 %#Pl_247_10395294_236_3158064_NONE#./%#Pl_247_10395294_236_3158064_NONE#abc %#Pl_247_10395294_236_3158064_NONE# %#Pl_247_10395294_236_3158064_NONE#2 %#Pl_247_10395294_236_3158064_NONE#./%#Pl_247_10395294_236_3158064_NONE#def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                           %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Tabs '
if result isnot# '%#Pl_247_10395294_236_3158064_NONE# 1 ./abc  2 ./def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                           %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Tabs '
call writefile(['Unexpected tabline', result], 'message.fail')
cquit
endif
@ -30,7 +30,7 @@ catch
cquit
endtry
if result isnot# '%#Pl_247_10395294_236_3158064_NONE# 1 %#Pl_247_10395294_236_3158064_NONE#./%#Pl_247_10395294_236_3158064_NONE#abc %#Pl_247_10395294_236_3158064_NONE# %#Pl_247_10395294_236_3158064_NONE#2 %#Pl_247_10395294_236_3158064_NONE#./%#Pl_247_10395294_236_3158064_NONE#def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                           %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
if result isnot# '%#Pl_247_10395294_236_3158064_NONE# 1 ./abc  2 ./def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                           %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
call writefile(['Unexpected tabline (2)', result], 'message.fail')
cquit
endif
@ -42,7 +42,7 @@ catch
call writefile(['Exception while evaluating &tabline (3)', v:exception], 'message.fail')
endtry
if result isnot# '%#Pl_247_10395294_236_3158064_NONE# 1 %#Pl_247_10395294_236_3158064_NONE#./%#Pl_247_10395294_236_3158064_NONE#abc %#Pl_247_10395294_236_3158064_NONE# %#Pl_247_10395294_236_3158064_NONE#2 %#Pl_247_10395294_236_3158064_NONE#./%#Pl_247_10395294_236_3158064_NONE#def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                           %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
if result isnot# '%#Pl_247_10395294_236_3158064_NONE# 1 ./abc  2 ./def %#Pl_236_3158064_240_5789784_NONE# %#Pl_250_12369084_240_5789784_NONE#./%#Pl_231_16777215_240_5789784_bold#ghi %#Pl_240_5789784_236_3158064_NONE# %#Pl_231_16777215_236_3158064_NONE#                                           %#Pl_252_13684944_236_3158064_NONE# %#Pl_235_2500134_252_13684944_bold# Bufs '
call writefile(['Unexpected tabline (3)', result], 'message.fail')
cquit
endif