mirror of
https://github.com/powerline/powerline.git
synced 2025-07-12 00:14:54 +02:00
This change joins the fg/bg/attr methods into a single hl method in the renderers. This provides the same functionality, and it simplifies the terminal rendering by being able to join all the attributes into one escape sequence. It's also a necessary change for the vim renderer, as this renderer needs to log all the highlighting and create separate highlighting classes for every single color and attribute combination. The only way to do this is to have a single highlighting method.
39 lines
862 B
Python
39 lines
862 B
Python
#!/usr/bin/env python
|
||
|
||
from lib.core import Segment
|
||
from lib.renderers import SegmentRenderer
|
||
|
||
|
||
class TerminalSegmentRenderer(SegmentRenderer):
|
||
'''Powerline terminal segment renderer.
|
||
'''
|
||
def hl(self, fg=None, bg=None, attr=None):
|
||
'''Highlight a segment.
|
||
|
||
If an argument is None, the argument is ignored. If an argument is
|
||
False, the argument is reset to the terminal defaults. If an argument
|
||
is a valid color or attribute, it's added to the ANSI escape code.
|
||
'''
|
||
ansi = []
|
||
|
||
if fg is not None:
|
||
if fg is False:
|
||
ansi += [39]
|
||
else:
|
||
ansi += [38, 5, fg[0]]
|
||
|
||
if bg is not None:
|
||
if bg is False:
|
||
ansi += [49]
|
||
else:
|
||
ansi += [48, 5, bg[0]]
|
||
|
||
if attr is not None:
|
||
if attr is False:
|
||
ansi += [22]
|
||
else:
|
||
if attr & Segment.ATTR_BOLD:
|
||
ansi += [1]
|
||
|
||
return '[{0}m'.format(';'.join(str(attr) for attr in ansi))
|