colors: Add support for importing colors in a json format.

This commit is contained in:
Dylan Araps 2017-06-29 10:54:42 +10:00
parent 06d726a66c
commit 1734129dea
3 changed files with 25 additions and 9 deletions

View File

@ -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

View File

@ -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/")

View File

@ -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: