diff --git a/eris/eris/__main__.py b/eris/eris/__main__.py index fc3e89e..00f1b73 100755 --- a/eris/eris/__main__.py +++ b/eris/eris/__main__.py @@ -157,15 +157,6 @@ def fix_paths(root_path, paths): for path in paths) -def blend_color(a_color, b_color, transparency): - a_r, a_g, a_b = a_color - b_r, b_g, b_b = b_color - complement = 1 - transparency - return (int(a_r * transparency + b_r * complement), - int(a_g * transparency + b_g * complement), - int(a_b * transparency + b_b * complement)) - - def highlight_str(line, highlight_color, transparency): @functools.lru_cache() @@ -175,8 +166,8 @@ def highlight_str(line, highlight_color, transparency): bg_color = (style.bg_color if type(style.bg_color) == tuple else termstr.XTERM_COLORS[style.bg_color]) return termstr.CharStyle( - blend_color(fg_color, highlight_color, transparency), - blend_color(bg_color, highlight_color, transparency), is_bold=style.is_bold, + 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) return termstr.TermStr(line).transform_style(blend_style) @@ -927,7 +918,7 @@ class Screen: @functools.lru_cache() def _get_partial_bar_chars(self, bar_transparency): - bar_color = blend_color(termstr.Color.black, termstr.Color.white, bar_transparency) + bar_color = termstr.blend_color(termstr.Color.black, termstr.Color.white, bar_transparency) return [termstr.TermStr(char).fg_color(bar_color).bg_color(termstr.Color.black) for char in fill3.ScrollBar._PARTIAL_CHARS[1]] diff --git a/termstr/termstr.py b/termstr/termstr.py index cdaa7da..59e70ff 100644 --- a/termstr/termstr.py +++ b/termstr/termstr.py @@ -26,6 +26,15 @@ def rgb_color(rgb, is_foreground): return f"[{'38' if is_foreground else '48'};2;" + "%i;%i;%im" % rgb +def blend_color(a_color, b_color, transparency): + a_r, a_g, a_b = a_color + b_r, b_g, b_b = b_color + complement = 1 - transparency + return (int(a_r * transparency + b_r * complement), + int(a_g * transparency + b_g * complement), + int(a_b * transparency + b_b * complement)) + + class Color: # https://en.wikipedia.org/wiki/Natural_Color_System @@ -38,6 +47,7 @@ class Color: lime = (0, 255, 0) yellow = (255, 211, 0) grey_30 = (30, 30, 30) + grey_40 = (40, 40, 40) grey_50 = (50, 50, 50) grey_80 = (80, 80, 80) grey_100 = (100, 100, 100) @@ -378,6 +388,12 @@ class TermStr(collections.UserString): is_italic=style.is_italic, is_underlined=style.is_underlined) return self.transform_style(set_bgcolor) + def invert(self): + def invert_(style): + return CharStyle(style.bg_color, style.fg_color, is_bold=style.is_bold, + is_italic=style.is_italic, is_underlined=style.is_underlined) + return self.transform_style(invert_) + def as_html(self): result = [] styles = set()