diff options
| author | Dylan Araps <dylan.araps@gmail.com> | 2017-06-29 10:54:42 +1000 |
|---|---|---|
| committer | Dylan Araps <dylan.araps@gmail.com> | 2017-06-29 10:54:42 +1000 |
| commit | 1734129dea39e7292910553598fa5f751a819085 (patch) | |
| tree | 0cbf02f6287b9e76bff0b5df07bbdff74fd55ad8 /pywal | |
| parent | 06d726a66cec0c5626c31975397ab340349ff39b (diff) | |
colors: Add support for importing colors in a json format.
Diffstat (limited to 'pywal')
| -rwxr-xr-x | pywal/__main__.py | 3 | ||||
| -rwxr-xr-x | pywal/set_colors.py | 23 | ||||
| -rwxr-xr-x | pywal/util.py | 8 |
3 files changed, 25 insertions, 9 deletions
diff --git a/pywal/__main__.py b/pywal/__main__.py index f9341a5..33a8ee7 100755 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -101,8 +101,9 @@ def process_args(args): # -f elif args.f: - colors_plain = util.read_file(args.f) + colors_plain = util.read_file_json(args.f) set_colors.send_sequences(colors_plain, args.t) + quit() export_colors.export_colors(colors_plain) # -o diff --git a/pywal/set_colors.py b/pywal/set_colors.py index 05b217c..b5da855 100755 --- a/pywal/set_colors.py +++ b/pywal/set_colors.py @@ -37,19 +37,26 @@ def set_grey(colors): def send_sequences(colors, vte): """Send colors to all open terminals.""" - sequences = [set_color(num, color) for num, color in enumerate(colors)] - sequences.append(set_special(10, colors[15])) - sequences.append(set_special(11, colors[0])) - sequences.append(set_special(12, colors[15])) - sequences.append(set_special(13, colors[15])) - sequences.append(set_special(14, colors[0])) + + # Colors 0-15. + sequences = [set_color(num, color) + for num, color in enumerate(colors["colors"].values())] + + # Special colors. + sequences.append(set_special(10, colors["special"]["foreground"])) + sequences.append(set_special(11, colors["special"]["background"])) + sequences.append(set_special(12, colors["special"]["cursor"])) + + # TODO: Figure out what these change. + # sequences.append(set_special(13, colors["foreground"])) + # sequences.append(set_special(14, colors["background"])) # Set a blank color that isn"t affected by bold highlighting. - sequences.append(set_color(66, colors[0])) + sequences.append(set_color(66, colors["special"]["background"])) # This escape sequence doesn"t work in VTE terminals. if not vte: - sequences.append(set_special(708, colors[0])) + sequences.append(set_special(708, colors["special"]["background"])) # Get a list of terminals. terminals = [f"/dev/pts/{term}" for term in os.listdir("/dev/pts/") 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: |
