summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2017-06-20 14:36:00 +1000
committerDylan Araps <dylan.araps@gmail.com>2017-06-20 14:36:00 +1000
commit137d986742a8b2381f320180a9fc0dcc4c545614 (patch)
treed359f8eac12e01e73499e3e895a315927606bc84
parentb7fff265d04d1882e5d7662cc089f5de8bc448b0 (diff)
General: Add all export functions
-rwxr-xr-xwal62
1 files changed, 54 insertions, 8 deletions
diff --git a/wal b/wal
index 7966ab3..164dc90 100755
--- a/wal
+++ b/wal
@@ -335,11 +335,31 @@ def set_wallpaper(img):
# EXPORT COLORS {{{
+def export_generic(colors, col_format):
+ """Export colors to var format."""
+ # Loop over the colors and format them.
+ colors = [col_format % (num, color) for num, color in enumerate(colors)]
+ colors = ''.join(colors)
+
+ return colors
+
+
def export_plain(colors):
"""Export colors to a plain text file."""
with open(CACHE_DIR / "colors", 'w') as file:
file.write('\n'.join(colors))
+ print("export: Exported plain colors")
+
+
+def export_shell(colors, export_file):
+ """Export colors to shell format."""
+ col_format = "color%s='%s'\n"
+ colors = export_generic(colors, col_format)
+ save_file(colors, export_file)
+
+ print("export: Exported shell colors.")
+
def export_rofi(colors):
"""Append rofi colors to the x_colors list."""
@@ -362,28 +382,48 @@ def export_emacs(colors):
ColorFormats.x_colors.append("emacs*foreground: %s\n" % (colors[15]))
-def export_xrdb(colors):
+def export_xrdb(colors, export_file):
"""Export colors to xrdb."""
- x_colors = ''.join(colors)
-
- # Write the colors to the file.
- with open(CACHE_DIR / "xcolors", 'w') as file:
- file.write(x_colors)
+ colors = ''.join(colors)
+ save_file(colors, export_file)
# Merge the colors into the X db so new terminals use them.
- subprocess.Popen(["xrdb", "-merge", CACHE_DIR / "xcolors"])
+ subprocess.Popen(["xrdb", "-merge", export_file])
print("export: Exported xrdb colors.")
+def export_css(colors, export_file):
+ """Export colors as css variables."""
+ col_format = "\t--color%s: %s;\n"
+ colors = ":root {\n%s}\n" % str(export_generic(colors, col_format))
+ save_file(colors, export_file)
+
+ print("export: Exported css colors.")
+
+
+def export_scss(colors, export_file):
+ """Export colors as scss variables."""
+ col_format = "$color%s: %s;\n"
+ colors = export_generic(colors, col_format)
+ save_file(colors, export_file)
+
+ print("export: Exported scss colors.")
+
+
def export_colors(colors):
"""Export colors in various formats."""
export_plain(colors)
+ export_shell(colors, CACHE_DIR / "colors.sh")
# X based colors.
export_rofi(colors)
export_emacs(colors)
- export_xrdb(ColorFormats.x_colors)
+ export_xrdb(ColorFormats.x_colors, CACHE_DIR / "xcolors")
+
+ # Web based colors.
+ export_css(colors, CACHE_DIR / "colors.css")
+ export_scss(colors, CACHE_DIR / "colors.scss")
# }}}
@@ -419,6 +459,12 @@ def reload_colors(vte):
quit()
+def save_file(colors, export_file):
+ """Write the colors to the file."""
+ with open(export_file, 'w') as file:
+ file.write(colors)
+
+
# }}}