efficient vim config
[dotfiles/.git] / .local / lib / python3.9 / site-packages / pywal / backends / haishoku.py
1 """
2 Generate a colorscheme using Haishoku.
3 """
4 import logging
5 import sys
6
7 try:
8     from haishoku.haishoku import Haishoku
9
10 except ImportError:
11     logging.error("Haishoku wasn't found on your system.")
12     logging.error("Try another backend. (wal --backend)")
13     sys.exit(1)
14
15 from .. import colors
16 from .. import util
17
18
19 def gen_colors(img):
20     """Generate a colorscheme using Colorz."""
21     palette = Haishoku.getPalette(img)
22     return [util.rgb_to_hex(col[1]) for col in palette]
23
24
25 def adjust(cols, light):
26     """Create palette."""
27     cols.sort(key=util.rgb_to_yiq)
28     raw_colors = [*cols, *cols]
29     raw_colors[0] = util.lighten_color(cols[0], 0.40)
30
31     return colors.generic_adjust(raw_colors, light)
32
33
34 def get(img, light=False):
35     """Get colorscheme."""
36     cols = gen_colors(img)
37     return adjust(cols, light)