colors: Add json support to exported files.

This commit is contained in:
Dylan Araps 2017-06-29 11:16:15 +10:00
parent 1734129dea
commit 950400ef7d
2 changed files with 41 additions and 28 deletions

View File

@ -103,7 +103,6 @@ def process_args(args):
elif 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

@ -6,20 +6,21 @@ from pywal import util
def plain(colors):
"""Convert colors to plain hex."""
return [f"{color}\n" for color in colors]
return [f"{color}\n" for color in colors["colors"].values()]
def shell(colors):
"""Convert colors to shell variables."""
return [f"color{index}='{color}'\n"
for index, color in enumerate(colors)]
for index, color in enumerate(colors["colors"].values())]
def css(colors):
"""Convert colors to css variables."""
css_colors = [":root {\n"]
css_colors.extend([f"\t--color{index}: {color};\n"
for index, color in enumerate(colors)])
for index, color in
enumerate(colors["colors"].values())])
css_colors.append("}\n")
return css_colors
@ -27,7 +28,7 @@ def css(colors):
def scss(colors):
"""Convert colors to scss variables."""
return [f"$color{index}: {color};\n"
for index, color in enumerate(colors)]
for index, color in enumerate(colors["colors"].values())]
def putty(colors):
@ -38,7 +39,8 @@ def putty(colors):
"[HKEY_CURRENT_USER\\Software\\SimonTatham\\PuTTY\\Sessions\\Wal]\n",
]
putty_colors.extend([f"\"colour{index}\"=\"{rgb(color)}\"\n"
for index, color in enumerate(colors)])
for index, color in
enumerate(colors["colors"].values())])
return putty_colors
@ -46,33 +48,45 @@ def putty(colors):
def xrdb(colors):
"""Convert colors to xrdb format."""
x_colors = []
x_colors.append(f"URxvt*foreground: {colors[15]}\n")
x_colors.append(f"XTerm*foreground: {colors[15]}\n")
x_colors.append(f"URxvt*background: {colors[0]}\n")
x_colors.append(f"XTerm*background: {colors[0]}\n")
x_colors.append(f"URxvt*cursorColor: {colors[15]}\n")
x_colors.append(f"XTerm*cursorColor: {colors[15]}\n")
x_colors.append(f"URxvt*foreground: {colors['special']['foreground']}\n")
x_colors.append(f"XTerm*foreground: {colors['special']['foreground']}\n")
x_colors.append(f"URxvt*background: {colors['special']['background']}\n")
x_colors.append(f"XTerm*background: {colors['special']['background']}\n")
x_colors.append(f"URxvt*cursorColor: {colors['special']['cursor']}\n")
x_colors.append(f"XTerm*cursorColor: {colors['special']['cursor']}\n")
# Colors 0-15.
x_colors.extend([f"*.color{index}: {color}\n*color{index}: {color}\n"
for index, color in enumerate(colors)])
x_colors.extend([f"*.color{index}: {color}\n*color{index}: {color}\n"
for index, color in enumerate(colors["colors"].values())])
x_colors.append(f"*.color66: {colors[0]}\n*color66: {colors[0]}\n")
x_colors.append(f"*.color66: {colors['special']['background']}\n"
f"*color66: {colors['special']['background']}\n")
# Rofi colors.
x_colors.append(f"rofi.color-window: {colors[0]}, "
f"{colors[0]}, {colors[10]}\n")
x_colors.append(f"rofi.color-normal: {colors[0]}, "
f"{colors[15]}, {colors[0]}, "
f"{colors[10]}, {colors[0]}\n")
x_colors.append(f"rofi.color-active: {colors[0]}, "
f"{colors[15]}, {colors[0]}, "
f"{colors[10]}, {colors[0]}\n")
x_colors.append(f"rofi.color-urgent: {colors[0]}, "
f"{colors[9]}, {colors[0]}, "
f"{colors[9]}, {colors[15]}\n")
x_colors.append(f"rofi.color-window: "
f"{colors['special']['background']}, "
f"{colors['special']['background']}, "
f"{colors['colors']['color10']}\n")
x_colors.append(f"rofi.color-normal: "
f"{colors['special']['background']}, "
f"{colors['special']['foreground']}, "
f"{colors['special']['background']}, "
f"{colors['colors']['color10']}, "
f"{colors['special']['background']}\n")
x_colors.append(f"rofi.color-active: "
f"{colors['special']['background']}, "
f"{colors['special']['foreground']}, "
f"{colors['special']['background']}, "
f"{colors['colors']['color10']}, "
f"{colors['special']['background']}\n")
x_colors.append(f"rofi.color-urgent: "
f"{colors['special']['background']}, "
f"{colors['colors']['color9']}, "
f"{colors['special']['background']}, "
f"{colors['colors']['color9']}, "
f"{colors['special']['foreground']}\n")
# Emacs colors.
x_colors.append(f"emacs*background: {colors[0]}\n")
x_colors.append(f"emacs*foreground: {colors[15]}\n")
x_colors.append(f"emacs*background: {colors['special']['background']}\n")
x_colors.append(f"emacs*foreground: {colors['special']['foreground']}\n")
return x_colors