efficient vim config
[dotfiles/.git] / .local / lib / python3.9 / site-packages / pywal / backends / schemer2.py
1 """
2 Generate a colorscheme using Schemer2.
3 """
4 import logging
5 import shutil
6 import subprocess
7 import sys
8
9 from .. import colors
10 from .. import util
11
12
13 def gen_colors(img):
14     """Generate a colorscheme using Colorz."""
15     cmd = ["schemer2", "-format", "img::colors", "-minBright", "75", "-in"]
16     return subprocess.check_output([*cmd, img]).splitlines()
17
18
19 def adjust(cols, light):
20     """Create palette."""
21     cols.sort(key=util.rgb_to_yiq)
22     raw_colors = [*cols[8:], *cols[8:]]
23
24     return colors.generic_adjust(raw_colors, light)
25
26
27 def get(img, light=False):
28     """Get colorscheme."""
29     if not shutil.which("schemer2"):
30         logging.error("Schemer2 wasn't found on your system.")
31         logging.error("Try another backend. (wal --backend)")
32         sys.exit(1)
33
34     cols = [col.decode('UTF-8') for col in gen_colors(img)]
35     return adjust(cols, light)