diff options
| author | Dylan Araps <[email protected]> | 2017-06-29 17:25:16 +1000 |
|---|---|---|
| committer | Dylan Araps <[email protected]> | 2017-06-29 17:25:16 +1000 |
| commit | c0ee7985f3c9ad5414f9eac56143c3dedcdc32cd (patch) | |
| tree | 1bfeea141b94ad906259a71ded85b43d9c3c2248 | |
| parent | colors: Figured out what the escape sequences do. (diff) | |
| download | pywal-c0ee7985f3c9ad5414f9eac56143c3dedcdc32cd.tar.xz pywal-c0ee7985f3c9ad5414f9eac56143c3dedcdc32cd.zip | |
colors: Use templates.
| -rwxr-xr-x | pywal/__main__.py | 4 | ||||
| -rwxr-xr-x | pywal/export_colors.py | 66 | ||||
| -rwxr-xr-x | pywal/format_colors.py | 92 | ||||
| -rwxr-xr-x | pywal/settings.py | 2 | ||||
| -rw-r--r-- | pywal/templates/colors.css | 20 |
5 files changed, 46 insertions, 138 deletions
diff --git a/pywal/__main__.py b/pywal/__main__.py index c5a4bb8..7b516aa 100755 --- a/pywal/__main__.py +++ b/pywal/__main__.py @@ -96,13 +96,13 @@ def process_args(args): # Set the colors. set_colors.send_sequences(colors_plain, args.t) - export_colors.export_colors(colors_plain) + export_colors.export_all_templates(colors_plain) # -f elif args.f: colors_plain = util.read_file_json(args.f) set_colors.send_sequences(colors_plain, args.t) - export_colors.export_colors(colors_plain) + export_colors.export_all_templates(colors_plain) # -o if args.o: diff --git a/pywal/export_colors.py b/pywal/export_colors.py index 3a89d22..6d51ca6 100755 --- a/pywal/export_colors.py +++ b/pywal/export_colors.py @@ -1,56 +1,34 @@ """ Export colors in various formats. """ -import shutil -import subprocess +import os +import pathlib -from pywal.settings import CACHE_DIR -from pywal import util -from pywal import format_colors +from pywal.settings import CACHE_DIR, TEMPLATE_DIR -def save_colors(colors, export_file, message): - """Export colors to var format.""" - colors = "".join(colors) - util.save_file(colors, CACHE_DIR / export_file) - print(f"export: exported {message}.") +def template(colors, input_file): + """Read template file, substitute markers and + save the file elsewhere.""" + template_file = pathlib.Path(TEMPLATE_DIR).joinpath(input_file) + export_file = pathlib.Path(CACHE_DIR).joinpath(input_file) + # Import the template. + with open(template_file) as file: + template_data = file.readlines() -def reload_xrdb(export_file): - """Merge the colors into the X db so new terminals use them.""" - if shutil.which("xrdb"): - subprocess.call(["xrdb", "-merge", CACHE_DIR / export_file]) + # Merge both dicts. + colors["colors"].update(colors["special"]) + # Format the markers. + template_data = "".join(template_data).format(**colors["colors"]) -def reload_i3(): - """Reload i3 colors.""" - if shutil.which("i3-msg"): - util.disown("i3-msg", "reload") + # Export the template. + with open(export_file, "w") as file: + file.write(template_data) -def export_colors(colors): - """Export colors in various formats.""" - plain_colors = format_colors.plain(colors) - save_colors(plain_colors, "colors", "plain hex colors") - - # Shell based colors. - shell_colors = format_colors.shell(colors) - save_colors(shell_colors, "colors.sh", "shell variables") - - # Web based colors. - css_colors = format_colors.css(colors) - save_colors(css_colors, "colors.css", "css variables") - scss_colors = format_colors.scss(colors) - save_colors(scss_colors, "colors.scss", "scss variables") - - # Text editor based colors. - putty_colors = format_colors.putty(colors) - save_colors(putty_colors, "colors-putty.reg", "putty theme") - - # X based colors. - xrdb_colors = format_colors.xrdb(colors) - save_colors(xrdb_colors, "xcolors", "xrdb colors") - - # i3 colors. - reload_xrdb("xcolors") - reload_i3() +def export_all_templates(colors): + """Export all template files.""" + # pylint: disable=W0106 + [template(colors, file.name) for file in os.scandir(TEMPLATE_DIR)] diff --git a/pywal/format_colors.py b/pywal/format_colors.py deleted file mode 100755 index 1d0439b..0000000 --- a/pywal/format_colors.py +++ /dev/null @@ -1,92 +0,0 @@ -""" -Convert colors to various formats. -""" -from pywal import util - - -def plain(colors): - """Convert colors to plain hex.""" - 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["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["colors"].values())]) - css_colors.append("}\n") - return css_colors - - -def scss(colors): - """Convert colors to scss variables.""" - return [f"$color{index}: {color};\n" - for index, color in enumerate(colors["colors"].values())] - - -def putty(colors): - """Convert colors to putty theme.""" - rgb = util.hex_to_rgb - putty_colors = [ - "Windows Registry Editor Version 5.00\n\n", - "[HKEY_CURRENT_USER\\Software\\SimonTatham\\PuTTY\\Sessions\\Wal]\n", - ] - putty_colors.extend([f"\"colour{index}\"=\"{rgb(color)}\"\n" - for index, color in - enumerate(colors["colors"].values())]) - - return putty_colors - - -def xrdb(colors): - """Convert colors to xrdb format.""" - x_colors = [] - 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["colors"].values())]) - - x_colors.append(f"*.color66: {colors['special']['background']}\n" - f"*color66: {colors['special']['background']}\n") - - # Rofi colors. - 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['special']['background']}\n") - x_colors.append(f"emacs*foreground: {colors['special']['foreground']}\n") - return x_colors diff --git a/pywal/settings.py b/pywal/settings.py index d94b7eb..d920103 100755 --- a/pywal/settings.py +++ b/pywal/settings.py @@ -1,6 +1,7 @@ """ Global Constants. """ +import os import pathlib @@ -10,3 +11,4 @@ __version__ = "0.2.6" # Internal variables. COLOR_COUNT = 16 CACHE_DIR = pathlib.Path.home() / ".cache/wal/" +TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), "templates") diff --git a/pywal/templates/colors.css b/pywal/templates/colors.css new file mode 100644 index 0000000..439bbad --- /dev/null +++ b/pywal/templates/colors.css @@ -0,0 +1,20 @@ +/* CSS variables + Generated by 'wal' */ +:root {{ + --color0: {color0}; + --color1: {color1}; + --color2: {color2}; + --color3: {color3}; + --color4: {color4}; + --color5: {color5}; + --color6: {color6}; + --color7: {color7}; + --color8: {color8}; + --color9: {color9}; + --color10: {color10}; + --color11: {color11}; + --color12: {color12}; + --color13: {color13}; + --color14: {color14}; + --color15: {color15}; +}} |