summaryrefslogtreecommitdiff
path: root/pywal/theme.py
diff options
context:
space:
mode:
authordylan <dylan.araps@gmail.com>2020-01-23 10:38:33 +0200
committerGitHub <noreply@github.com>2020-01-23 10:38:33 +0200
commitc1d90676f9074cf4131f8cb94aeb2344d6fc8ecc (patch)
tree63e7fe384b10449fd893b5a2da3e90199df21dae /pywal/theme.py
parent7ecc2ffd39d1c01639da666dd4dbe0aa4789f85c (diff)
parent3537e8cc8f2af2051dd695ef1ca7247e76e0f74f (diff)
Merge branch 'master' into add-vs-code-support
Diffstat (limited to 'pywal/theme.py')
-rw-r--r--pywal/theme.py51
1 files changed, 40 insertions, 11 deletions
diff --git a/pywal/theme.py b/pywal/theme.py
index 5c065a0..9dc4f13 100644
--- a/pywal/theme.py
+++ b/pywal/theme.py
@@ -6,7 +6,7 @@ import os
import random
import sys
-from .settings import CONF_DIR, MODULE_DIR
+from .settings import CACHE_DIR, CONF_DIR, MODULE_DIR
from . import util
@@ -19,20 +19,30 @@ def list_out():
user_themes = [theme.name.replace(".json", "")
for theme in list_themes_user()]
+ try:
+ last_used_theme = util.read_file(os.path.join(
+ CACHE_DIR, "last_used_theme"))[0].replace(".json", "")
+ except FileNotFoundError:
+ last_used_theme = ""
+
if user_themes:
print("\033[1;32mUser Themes\033[0m:")
- print(" -", "\n - ".join(sorted(user_themes)))
+ print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme
+ else t for t in sorted(user_themes)))
print("\033[1;32mDark Themes\033[0m:")
- print(" -", "\n - ".join(sorted(dark_themes)))
+ print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme else t
+ for t in sorted(dark_themes)))
print("\033[1;32mLight Themes\033[0m:")
- print(" -", "\n - ".join(sorted(ligh_themes)))
+ print(" -", "\n - ".join(t + " (last used)" if t == last_used_theme else t
+ for t in sorted(ligh_themes)))
print("\033[1;32mExtra\033[0m:")
print(" - random (select a random dark theme)")
print(" - random_dark (select a random dark theme)")
print(" - random_light (select a random light theme)")
+ print(" - random_user (select a random user theme)")
def list_themes(dark=True):
@@ -72,7 +82,7 @@ def parse(theme_file):
data["wallpaper"] = "None"
if "alpha" not in data:
- data["alpha"] = "100"
+ data["alpha"] = util.Color.alpha_num
# Terminal.sexy format.
if "color" in data:
@@ -88,6 +98,13 @@ def get_random_theme(dark=True):
return themes[0]
+def get_random_theme_user():
+ """Get a random theme file from user theme directories."""
+ themes = [theme.path for theme in list_themes_user()]
+ random.shuffle(themes)
+ return themes[0]
+
+
def file(input_file, light=False):
"""Import colorscheme from json file."""
util.create_dir(os.path.join(CONF_DIR, "colorschemes/light/"))
@@ -100,12 +117,15 @@ def file(input_file, light=False):
theme_file = os.path.join(MODULE_DIR, "colorschemes", bri, theme_name)
# Find the theme file.
- if input_file == "random" or input_file == "random_dark":
+ if input_file in ("random", "random_dark"):
theme_file = get_random_theme()
elif input_file == "random_light":
theme_file = get_random_theme(light)
+ elif input_file == "random_user":
+ theme_file = get_random_theme_user()
+
elif os.path.isfile(user_theme_file):
theme_file = user_theme_file
@@ -116,10 +136,19 @@ def file(input_file, light=False):
if os.path.isfile(theme_file):
logging.info("Set theme to \033[1;37m%s\033[0m.",
os.path.basename(theme_file))
+ util.save_file(os.path.basename(theme_file),
+ os.path.join(CACHE_DIR, "last_used_theme"))
return parse(theme_file)
- else:
- logging.error("No %s colorscheme file found.", bri)
- logging.error("Try adding '-l' to set light themes.")
- logging.error("Try removing '-l' to set dark themes.")
- sys.exit(1)
+ logging.error("No %s colorscheme file found.", bri)
+ logging.error("Try adding '-l' to set light themes.")
+ logging.error("Try removing '-l' to set dark themes.")
+ sys.exit(1)
+
+
+def save(colors, theme_name, light=False):
+ """Save colors to a theme file."""
+ theme_file = theme_name + ".json"
+ theme_path = os.path.join(CONF_DIR, "colorschemes",
+ "light" if light else "dark", theme_file)
+ util.save_file_json(colors, theme_path)