diff options
Diffstat (limited to 'poezio/colors.py')
-rw-r--r-- | poezio/colors.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/poezio/colors.py b/poezio/colors.py index c1019145..62566c77 100644 --- a/poezio/colors.py +++ b/poezio/colors.py @@ -1,7 +1,6 @@ -from typing import Tuple, Dict, List +from typing import Tuple, Dict, List, Union import curses import hashlib -import math from . import hsluv @@ -15,6 +14,9 @@ K_B = 1 - K_R - K_G def ncurses_color_to_rgb(color: int) -> Tuple[float, float, float]: if color <= 15: + r: Union[int, float] + g: Union[int, float] + b: Union[int, float] try: (r, g, b) = curses.color_content(color) except: # fallback in faulty terminals (e.g. xterm) @@ -37,7 +39,7 @@ def ncurses_color_to_rgb(color: int) -> Tuple[float, float, float]: def generate_ccg_palette(curses_palette: List[int], reference_y: float) -> Palette: - cbcr_palette = {} # type: Dict[float, Tuple[float, int]] + cbcr_palette: Dict[float, Tuple[float, int]] = {} for curses_color in curses_palette: r, g, b = ncurses_color_to_rgb(curses_color) # drop grayscale @@ -83,6 +85,9 @@ def ccg_palette_lookup(palette: Palette, angle: float) -> int: best_metric = metric best = color + if best is None: + raise ValueError("No color in palette") + return best |