1# vim:fileencoding=utf-8:noet 2from __future__ import (unicode_literals, division, absolute_import, print_function) 3 4from xml.sax.saxutils import escape as _escape 5 6from powerline.renderer import Renderer 7from powerline.colorscheme import ATTR_BOLD, ATTR_ITALIC, ATTR_UNDERLINE 8 9 10class PangoMarkupRenderer(Renderer): 11 '''Powerline Pango markup segment renderer.''' 12 13 @staticmethod 14 def hlstyle(*args, **kwargs): 15 # We don’t need to explicitly reset attributes, so skip those calls 16 return '' 17 18 def hl(self, contents, fg=None, bg=None, attrs=None, **kwargs): 19 '''Highlight a segment.''' 20 awesome_attr = [] 21 if fg is not None: 22 if fg is not False and fg[1] is not False: 23 awesome_attr += ['foreground="#{0:06x}"'.format(fg[1])] 24 if bg is not None: 25 if bg is not False and bg[1] is not False: 26 awesome_attr += ['background="#{0:06x}"'.format(bg[1])] 27 if attrs is not None and attrs is not False: 28 if attrs & ATTR_BOLD: 29 awesome_attr += ['font_weight="bold"'] 30 if attrs & ATTR_ITALIC: 31 awesome_attr += ['font_style="italic"'] 32 if attrs & ATTR_UNDERLINE: 33 awesome_attr += ['underline="single"'] 34 return '<span ' + ' '.join(awesome_attr) + '>' + contents + '</span>' 35 36 escape = staticmethod(_escape) 37 38 39renderer = PangoMarkupRenderer 40