Remove placeholder and use escaping instead
This commit is contained in:
parent
a42f9b6e2f
commit
d20df5a382
|
@ -117,25 +117,25 @@ class Renderer(object):
|
||||||
segment_hl = self.hl(**segment['highlight'][mode])
|
segment_hl = self.hl(**segment['highlight'][mode])
|
||||||
|
|
||||||
if segment['type'] == 'filler':
|
if segment['type'] == 'filler':
|
||||||
rendered_highlighted += segment['contents'] or ''
|
rendered_highlighted += self.escape(segment['contents'] or '')
|
||||||
elif segment['draw_divider'] or divider_type == 'hard':
|
elif segment['draw_divider'] or divider_type == 'hard':
|
||||||
# Draw divider if specified, or if it's a hard divider
|
# Draw divider if specified, or if it's a hard divider
|
||||||
# Note: Hard dividers are always drawn, regardless of
|
# Note: Hard dividers are always drawn, regardless of
|
||||||
# the draw_divider option
|
# the draw_divider option
|
||||||
if segment['side'] == 'left':
|
if segment['side'] == 'left':
|
||||||
segment['rendered_raw'] += outer_padding + segment['contents'] + ' ' + divider + ' '
|
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:
|
else:
|
||||||
segment['rendered_raw'] += ' ' + divider + ' ' + segment['contents'] + outer_padding
|
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']:
|
elif segment['contents']:
|
||||||
# Segments without divider
|
# Segments without divider
|
||||||
if segment['side'] == 'left':
|
if segment['side'] == 'left':
|
||||||
segment['rendered_raw'] += outer_padding + segment['contents']
|
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:
|
else:
|
||||||
segment['rendered_raw'] += segment['contents'] + outer_padding
|
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:
|
else:
|
||||||
raise ValueError('Unknown segment type')
|
raise ValueError('Unknown segment type')
|
||||||
rendered_highlighted += self.hl()
|
rendered_highlighted += self.hl()
|
||||||
|
@ -150,6 +150,10 @@ class Renderer(object):
|
||||||
'''
|
'''
|
||||||
return len(''.join([segment['rendered_raw'] for segment in segments]))
|
return len(''.join([segment['rendered_raw'] for segment in segments]))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def escape(string):
|
||||||
|
return string
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _int_to_rgb(int):
|
def _int_to_rgb(int):
|
||||||
r = (int >> 16) & 0xff
|
r = (int >> 16) & 0xff
|
||||||
|
|
|
@ -15,7 +15,6 @@ vim_setwinvar = vim_get_func('setwinvar')
|
||||||
|
|
||||||
class VimRenderer(Renderer):
|
class VimRenderer(Renderer):
|
||||||
'''Powerline vim segment renderer.'''
|
'''Powerline vim segment renderer.'''
|
||||||
_PERCENT_PLACEHOLDER = u''
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(VimRenderer, self).__init__(*args, **kwargs)
|
super(VimRenderer, self).__init__(*args, **kwargs)
|
||||||
|
@ -34,18 +33,18 @@ class VimRenderer(Renderer):
|
||||||
if current:
|
if current:
|
||||||
mode = vim_mode()
|
mode = vim_mode()
|
||||||
theme = self.get_theme()
|
theme = self.get_theme()
|
||||||
segments = []
|
segments = [segment for segment in theme.get_segments()]
|
||||||
for segment in theme.get_segments():
|
|
||||||
segment['contents'] = segment['contents'].replace('%', self._PERCENT_PLACEHOLDER)
|
|
||||||
segments.append(segment)
|
|
||||||
self.window_cache[window_id] = (theme, segments)
|
self.window_cache[window_id] = (theme, segments)
|
||||||
else:
|
else:
|
||||||
mode = 'nc'
|
mode = 'nc'
|
||||||
theme, segments = self.window_cache.get(window_id, (None, None))
|
theme, segments = self.window_cache.get(window_id, (None, None))
|
||||||
statusline = super(VimRenderer, self).render(mode, winwidth, theme, segments)
|
statusline = super(VimRenderer, self).render(mode, winwidth, theme, segments)
|
||||||
statusline = statusline.replace(self._PERCENT_PLACEHOLDER, '%%')
|
|
||||||
return statusline
|
return statusline
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def escape(string):
|
||||||
|
return string.replace('%', '%%')
|
||||||
|
|
||||||
def hl(self, fg=None, bg=None, attr=None):
|
def hl(self, fg=None, bg=None, attr=None):
|
||||||
'''Highlight a segment.
|
'''Highlight a segment.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue