diff options
| author | Dylan Araps <dylan.araps@gmail.com> | 2020-01-24 08:26:06 +0200 |
|---|---|---|
| committer | Dylan Araps <dylan.araps@gmail.com> | 2020-01-24 08:26:06 +0200 |
| commit | 42ad8f014dfe11defe094a3ce33b60f7ec27b83b (patch) | |
| tree | dcfb8a63a7e23a8bcf6bbdbc4c18bed563459148 /pywal/theme.py | |
| parent | 11758b4548c3b696769f307d132348eaf17d5efe (diff) | |
| parent | db48957bde740e68dc64ceafef4e62ddc7018c6a (diff) | |
Merge branch 'master' of github.com:dylanaraps/pywal
Diffstat (limited to 'pywal/theme.py')
| -rw-r--r-- | pywal/theme.py | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/pywal/theme.py b/pywal/theme.py index fcd1dd1..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): @@ -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/")) @@ -106,6 +123,9 @@ def file(input_file, light=False): 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,9 +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) 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) |
