From 3b6475be1aad86ac57445c53fca3814ea1d390ce Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 29 Jun 2017 11:54:04 +1000 Subject: [PATCH] colors: Use json for all wal generated colors. --- pywal/__main__.py | 1 - pywal/gen_colors.py | 9 +++++++-- pywal/util.py | 6 ++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pywal/__main__.py b/pywal/__main__.py index 2d22f3f..c5a4bb8 100755 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -90,7 +90,6 @@ def process_args(args): # Create a list of hex colors. colors_plain = gen_colors.get_colors(image, args.q) - # colors_plain[8] = set_colors.set_grey(colors_plain) if not args.n: wallpaper.set_wallpaper(image) diff --git a/pywal/gen_colors.py b/pywal/gen_colors.py index 3814819..593875f 100755 --- a/pywal/gen_colors.py +++ b/pywal/gen_colors.py @@ -9,6 +9,7 @@ import shutil import subprocess from pywal.settings import CACHE_DIR, COLOR_COUNT +from pywal import set_colors from pywal import util @@ -96,9 +97,10 @@ def get_colors(img, quiet): # Cache the sequences file. cache_file = pathlib.Path(CACHE_DIR / "schemes" / img.replace("/", "_")) + cache_file = pathlib.Path(cache_file.with_suffix(".json")) if cache_file.is_file(): - colors = util.read_file(cache_file) + colors = util.read_file_json(cache_file) print("colors: Found cached colorscheme.") else: @@ -111,7 +113,7 @@ def get_colors(img, quiet): colors = sort_colors(colors) # Cache the colorscheme. - util.save_file("\n".join(colors), cache_file) + util.save_file_json(colors, cache_file) print("colors: Generated colorscheme") if not quiet: @@ -135,6 +137,9 @@ def sort_colors(colors): [colors_hex.update({f"color{index}": color}) # pylint: disable=W0106 for index, color in enumerate(raw_colors)] + # Color 8 + colors_hex["color8"] = set_colors.set_grey(raw_colors) + # Add the colors to a dict. colors = {} colors["special"] = colors_special diff --git a/pywal/util.py b/pywal/util.py index 415b612..69a9d9d 100755 --- a/pywal/util.py +++ b/pywal/util.py @@ -27,6 +27,12 @@ def save_file(colors, export_file): file.write(colors) +def save_file_json(colors, export_file): + """Write the colors to a json file.""" + with open(export_file, "w") as file: + json.dump(colors, file, indent=4) + + def create_dir(directory): """Alias to create the cache dir.""" pathlib.Path(directory).mkdir(parents=True, exist_ok=True)