Coding style.
- Move blend_color into termstr. - Add invert method to termstr.
This commit is contained in:
parent
1ee92346b5
commit
2bb586c862
2 changed files with 19 additions and 12 deletions
|
|
@ -157,15 +157,6 @@ def fix_paths(root_path, paths):
|
||||||
for path in 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):
|
def highlight_str(line, highlight_color, transparency):
|
||||||
|
|
||||||
@functools.lru_cache()
|
@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
|
bg_color = (style.bg_color if type(style.bg_color) == tuple
|
||||||
else termstr.XTERM_COLORS[style.bg_color])
|
else termstr.XTERM_COLORS[style.bg_color])
|
||||||
return termstr.CharStyle(
|
return termstr.CharStyle(
|
||||||
blend_color(fg_color, highlight_color, transparency),
|
termstr.blend_color(fg_color, highlight_color, transparency),
|
||||||
blend_color(bg_color, highlight_color, transparency), is_bold=style.is_bold,
|
termstr.blend_color(bg_color, highlight_color, transparency), is_bold=style.is_bold,
|
||||||
is_italic=style.is_italic, is_underlined=style.is_underlined)
|
is_italic=style.is_italic, is_underlined=style.is_underlined)
|
||||||
return termstr.TermStr(line).transform_style(blend_style)
|
return termstr.TermStr(line).transform_style(blend_style)
|
||||||
|
|
||||||
|
|
@ -927,7 +918,7 @@ class Screen:
|
||||||
|
|
||||||
@functools.lru_cache()
|
@functools.lru_cache()
|
||||||
def _get_partial_bar_chars(self, bar_transparency):
|
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)
|
return [termstr.TermStr(char).fg_color(bar_color).bg_color(termstr.Color.black)
|
||||||
for char in fill3.ScrollBar._PARTIAL_CHARS[1]]
|
for char in fill3.ScrollBar._PARTIAL_CHARS[1]]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,15 @@ def rgb_color(rgb, is_foreground):
|
||||||
return f"[{'38' if is_foreground else '48'};2;" + "%i;%i;%im" % rgb
|
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:
|
class Color:
|
||||||
|
|
||||||
# https://en.wikipedia.org/wiki/Natural_Color_System
|
# https://en.wikipedia.org/wiki/Natural_Color_System
|
||||||
|
|
@ -38,6 +47,7 @@ class Color:
|
||||||
lime = (0, 255, 0)
|
lime = (0, 255, 0)
|
||||||
yellow = (255, 211, 0)
|
yellow = (255, 211, 0)
|
||||||
grey_30 = (30, 30, 30)
|
grey_30 = (30, 30, 30)
|
||||||
|
grey_40 = (40, 40, 40)
|
||||||
grey_50 = (50, 50, 50)
|
grey_50 = (50, 50, 50)
|
||||||
grey_80 = (80, 80, 80)
|
grey_80 = (80, 80, 80)
|
||||||
grey_100 = (100, 100, 100)
|
grey_100 = (100, 100, 100)
|
||||||
|
|
@ -378,6 +388,12 @@ class TermStr(collections.UserString):
|
||||||
is_italic=style.is_italic, is_underlined=style.is_underlined)
|
is_italic=style.is_italic, is_underlined=style.is_underlined)
|
||||||
return self.transform_style(set_bgcolor)
|
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):
|
def as_html(self):
|
||||||
result = []
|
result = []
|
||||||
styles = set()
|
styles = set()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue