Remove placeholder and use escaping instead

This commit is contained in:
ZyX 2013-01-25 22:08:11 +04:00 committed by Kim Silkebækken
parent a42f9b6e2f
commit d20df5a382
2 changed files with 14 additions and 11 deletions

View File

@ -117,25 +117,25 @@ class Renderer(object):
segment_hl = self.hl(**segment['highlight'][mode])
if segment['type'] == 'filler':
rendered_highlighted += segment['contents'] or ''
rendered_highlighted += self.escape(segment['contents'] or '')
elif segment['draw_divider'] or divider_type == 'hard':
# Draw divider if specified, or if it's a hard divider
# Note: Hard dividers are always drawn, regardless of
# the draw_divider option
if segment['side'] == 'left':
segment['rendered_raw'] += outer_padding + segment['contents'] + ' ' + divider + ' '
rendered_highlighted += segment_hl + outer_padding + segment['contents'] + ' ' + divider_hl + divider + ' '
rendered_highlighted += segment_hl + self.escape(outer_padding + segment['contents'] + ' ') + divider_hl + self.escape(divider + ' ')
else:
segment['rendered_raw'] += ' ' + divider + ' ' + segment['contents'] + outer_padding
rendered_highlighted += ' ' + divider_hl + divider + segment_hl + ' ' + segment['contents'] + outer_padding
rendered_highlighted += self.escape(' ') + divider_hl + self.escape(divider) + segment_hl + self.escape(' ' + segment['contents'] + outer_padding)
elif segment['contents']:
# Segments without divider
if segment['side'] == 'left':
segment['rendered_raw'] += outer_padding + segment['contents']
rendered_highlighted += segment_hl + outer_padding + segment['contents']
rendered_highlighted += segment_hl + self.escape(outer_padding + segment['contents'])
else:
segment['rendered_raw'] += segment['contents'] + outer_padding
rendered_highlighted += segment_hl + segment['contents'] + outer_padding
rendered_highlighted += segment_hl + self.escape(segment['contents'] + outer_padding)
else:
raise ValueError('Unknown segment type')
rendered_highlighted += self.hl()
@ -150,6 +150,10 @@ class Renderer(object):
'''
return len(''.join([segment['rendered_raw'] for segment in segments]))
@staticmethod
def escape(string):
return string
@staticmethod
def _int_to_rgb(int):
r = (int >> 16) & 0xff

View File

@ -15,7 +15,6 @@ vim_setwinvar = vim_get_func('setwinvar')
class VimRenderer(Renderer):
'''Powerline vim segment renderer.'''
_PERCENT_PLACEHOLDER = u''
def __init__(self, *args, **kwargs):
super(VimRenderer, self).__init__(*args, **kwargs)
@ -34,18 +33,18 @@ class VimRenderer(Renderer):
if current:
mode = vim_mode()
theme = self.get_theme()
segments = []
for segment in theme.get_segments():
segment['contents'] = segment['contents'].replace('%', self._PERCENT_PLACEHOLDER)
segments.append(segment)
segments = [segment for segment in theme.get_segments()]
self.window_cache[window_id] = (theme, segments)
else:
mode = 'nc'
theme, segments = self.window_cache.get(window_id, (None, None))
statusline = super(VimRenderer, self).render(mode, winwidth, theme, segments)
statusline = statusline.replace(self._PERCENT_PLACEHOLDER, '%%')
return statusline
@staticmethod
def escape(string):
return string.replace('%', '%%')
def hl(self, fg=None, bg=None, attr=None):
'''Highlight a segment.