mirror of
https://github.com/b-ryan/powerline-shell.git
synced 2026-09-10 07:26:28 -04:00
feature/truecolor: TrueColor Theming Support
Adds the ability to use (R,G,B) tuples in theme files to more accurately specify the colors desired for each segment. Not all terminals have TrueColor support, so in the case that a theme uses (R,G,B) tuples that cannot be supported by the current terminal, the colors are approximated using colortrans.rgb2short to bring them to the nearest xterm-256 color.
This commit is contained in:
parent
a9b8c9bb39
commit
c29afdb83e
|
|
@ -6,6 +6,7 @@ import os
|
|||
import sys
|
||||
import importlib
|
||||
import json
|
||||
from . import colortrans
|
||||
from .utils import warn, py3, import_file
|
||||
import re
|
||||
|
||||
|
|
@ -86,6 +87,10 @@ class Powerline(object):
|
|||
def __init__(self, args, config, theme):
|
||||
self.args = args
|
||||
self.config = config
|
||||
theme_wants_truecolor = hasattr(theme, "use_truecolor") and theme.use_truecolor
|
||||
|
||||
env_colorterm = os.getenv("COLORTERM")
|
||||
self.truecolor_supported = env_colorterm is not None and "truecolor" in env_colorterm
|
||||
self.theme = theme
|
||||
self.cwd = get_valid_cwd()
|
||||
mode = config.get("mode", "patched")
|
||||
|
|
@ -105,6 +110,12 @@ class Powerline(object):
|
|||
return ''
|
||||
elif code == self.theme.RESET:
|
||||
return self.reset
|
||||
elif isinstance(code, tuple):
|
||||
# Do we support TrueColor? If not, supply the closest possible xterm-256 color.
|
||||
if self.truecolor_supported:
|
||||
return self.color_template % ('[%s;2;%s;%s;%sm' % (prefix, *code))
|
||||
else:
|
||||
return self.color_template % ('[%s;5;%sm' % (prefix, colortrans.rgb2short(*code)))
|
||||
else:
|
||||
return self.color_template % ('[%s;5;%sm' % (prefix, code))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue