summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-06-29 11:54:04 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-06-29 11:54:04 +1000
commit3b6475be1aad86ac57445c53fca3814ea1d390ce (patch)
treebe1860d4055a9b7e7e9fa5d96860fca741049745
parent8a908de48c5175e5eb41fe7d14a54adb50501405 (diff)
colors: Use json for all wal generated colors.
-rwxr-xr-xpywal/__main__.py1
-rwxr-xr-xpywal/gen_colors.py9
-rwxr-xr-xpywal/util.py6
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)