diff --git a/docs/changelog.rst b/docs/changelog.rst index 2b2e7279b..a7eb8da4b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -71,6 +71,8 @@ To update |kitty|, :doc:`follow the instructions `. executing any command specified on the command line via the users' shell just as ssh does (:iss:`3638`) +- Tab bar: Use a lower contrast color for tab separators (:pull:`3666`) + 0.20.3 [2021-05-06] ---------------------- diff --git a/kitty/rgb.py b/kitty/rgb.py index edfb40be4..351bdd392 100644 --- a/kitty/rgb.py +++ b/kitty/rgb.py @@ -12,6 +12,16 @@ class Color(NamedTuple): green: int blue: int + def luminance(self) -> float: + return 0.299 * self.red + 0.587 * self.green + 0.114 * self.blue + + def contrast(self, other: 'Color') -> float: + a = self.luminance() + b = other.luminance() + if a < b: + a, b = b, a + return (a + 0.05) / (b + 0.05) + def alpha_blend_channel(top_color: int, bottom_color: int, alpha: float) -> int: return int(alpha * top_color + (1 - alpha) * bottom_color) diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index 53116faac..90990f682 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -234,7 +234,16 @@ def draw_tab_with_powerline(draw_data: DrawData, screen: Screen, tab: TabBarData screen.cursor.bg = inactive_bg screen.draw(separator_symbol) else: + prev_fg = screen.cursor.fg + if tab_bg == tab_fg: + screen.cursor.fg = default_bg + elif tab_bg != default_bg: + c1 = draw_data.inactive_bg.contrast(draw_data.default_bg) + c2 = draw_data.inactive_bg.contrast(draw_data.inactive_fg) + if c1 < c2: + screen.cursor.fg = default_bg screen.draw(f' {separator_alt_symbol}') + screen.cursor.fg = prev_fg end = screen.cursor.x if end < screen.columns: