diff options
| author | dylan <dylan.araps@gmail.com> | 2020-01-23 10:36:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-23 10:36:13 +0200 |
| commit | 3537e8cc8f2af2051dd695ef1ca7247e76e0f74f (patch) | |
| tree | 86197b64788395a3c9908c38cdbb31c1f39c6bdb /pywal/theme.py | |
| parent | ca389ce114d73ea9f46f02b3e611fdc1fab26186 (diff) | |
| parent | 85526b657107c8fa08861a6c6ef3790c5bc14fac (diff) | |
Merge pull request #389 from aschey/theme_save
New features- saving user themes and loading random user themes
Diffstat (limited to 'pywal/theme.py')
| -rw-r--r-- | pywal/theme.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/pywal/theme.py b/pywal/theme.py index 706ed31..9dc4f13 100644 --- a/pywal/theme.py +++ b/pywal/theme.py @@ -42,6 +42,7 @@ def list_out(): 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): @@ -97,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/")) @@ -115,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 @@ -133,3 +144,11 @@ def file(input_file, light=False): 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) |
