From 788533e5c20132c727e2f287dce6ada64ebd5872 Mon Sep 17 00:00:00 2001 From: Austin Schey Date: Sun, 3 Mar 2019 11:13:44 -0600 Subject: added features for saving user themes and loading random themes --- pywal/theme.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'pywal/theme.py') diff --git a/pywal/theme.py b/pywal/theme.py index fcd1dd1..62695b5 100644 --- a/pywal/theme.py +++ b/pywal/theme.py @@ -33,6 +33,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): @@ -88,6 +89,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 +114,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 @@ -122,3 +133,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) -- cgit v1.2.3