diff --git a/eris/eris/__main__.py b/eris/eris/__main__.py index 1f1b9d8..b405a0d 100755 --- a/eris/eris/__main__.py +++ b/eris/eris/__main__.py @@ -165,14 +165,10 @@ def highlight_str(line, highlight_color, transparency): @functools.lru_cache(maxsize=500) def blend_style(style): - fg_color = (style.fg_color if type(style.fg_color) == tuple - else termstr.XTERM_COLORS[style.fg_color]) - bg_color = (style.bg_color if type(style.bg_color) == tuple - else termstr.XTERM_COLORS[style.bg_color]) return termstr.CharStyle( - termstr.blend_color(fg_color, highlight_color, transparency), - termstr.blend_color(bg_color, highlight_color, transparency), is_bold=style.is_bold, - is_italic=style.is_italic, is_underlined=style.is_underlined) + termstr.blend_color(style.fg_rgb_color, highlight_color, transparency), + termstr.blend_color(style.bg_rgb_color, highlight_color, transparency), + is_bold=style.is_bold, is_italic=style.is_italic, is_underlined=style.is_underlined) return termstr.TermStr(line).transform_style(blend_style) diff --git a/termstr/termstr.py b/termstr/termstr.py index a82e192..0d390ea 100644 --- a/termstr/termstr.py +++ b/termstr/termstr.py @@ -147,14 +147,20 @@ class CharStyle: return "".join([ESC, NORMAL, fg_termcode, bg_termcode, bold_code, italic_code, underline_code]) + @functools.cached_property + def fg_rgb_color(self): + return self.fg_color if type(self.fg_color) == tuple else XTERM_COLORS[self.fg_color] + + @functools.cached_property + def bg_rgb_color(self): + return self.bg_color if type(self.bg_color) == tuple else XTERM_COLORS[self.bg_color] + def as_html(self): bold_code = "font-weight:bold; " if self.is_bold else "" italic_code = "font-style:italic; " if self.is_italic else "" underline_code = "text-decoration:underline; " if self.is_underlined else "" - fg_color = self.fg_color if type(self.fg_color) == tuple else XTERM_COLORS[self.fg_color] - bg_color = self.bg_color if type(self.bg_color) == tuple else XTERM_COLORS[self.bg_color] - return (f"")