From 1734129dea39e7292910553598fa5f751a819085 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 29 Jun 2017 10:54:42 +1000 Subject: colors: Add support for importing colors in a json format. --- pywal/util.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'pywal/util.py') diff --git a/pywal/util.py b/pywal/util.py index 67baa6a..415b612 100755 --- a/pywal/util.py +++ b/pywal/util.py @@ -1,6 +1,7 @@ """ Misc helper functions. """ +import json import os import pathlib import subprocess @@ -13,6 +14,13 @@ def read_file(input_file): return colors +def read_file_json(input_file): + """Read colors from a json file.""" + with open(input_file) as json_file: + colors = json.load(json_file) + return colors + + def save_file(colors, export_file): """Write the colors to the file.""" with open(export_file, "w") as file: -- cgit v1.2.3 From 3b6475be1aad86ac57445c53fca3814ea1d390ce Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 29 Jun 2017 11:54:04 +1000 Subject: colors: Use json for all wal generated colors. --- pywal/util.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'pywal/util.py') 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) -- cgit v1.2.3