mirror of
https://github.com/dylanaraps/pywal.git
synced 2024-11-25 09:23:08 +01:00
added features for saving user themes and loading random themes
This commit is contained in:
parent
53740712a6
commit
788533e5c2
@ -45,7 +45,7 @@ def get_args():
|
||||
|
||||
arg.add_argument("--theme", "-f", metavar="/path/to/file or theme_name",
|
||||
help="Which colorscheme file to use. \
|
||||
Use 'wal --theme' to list builtin themes.",
|
||||
Use 'wal --theme' to list builtin and user themes.",
|
||||
const="list_themes", nargs="?")
|
||||
|
||||
arg.add_argument("--iterative", action="store_true",
|
||||
@ -77,6 +77,11 @@ def get_args():
|
||||
arg.add_argument("-o", metavar="\"script_name\"", action="append",
|
||||
help="External script to run after \"wal\".")
|
||||
|
||||
arg.add_argument("-p", metavar="\"theme_name\"",
|
||||
help="permanently save theme to "
|
||||
"$XDG_CONFIG_HOME/wal/colorschemes with "
|
||||
"the specified name")
|
||||
|
||||
arg.add_argument("-q", action="store_true",
|
||||
help="Quiet mode, don\'t print anything.")
|
||||
|
||||
@ -177,6 +182,9 @@ def parse_args(parser):
|
||||
if not args.n:
|
||||
wallpaper.change(colors_plain["wallpaper"])
|
||||
|
||||
if args.p:
|
||||
theme.save(colors_plain, args.p, args.l)
|
||||
|
||||
sequences.send(colors_plain, to_send=not args.s, vte_fix=args.vte)
|
||||
|
||||
if sys.stdout.isatty():
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user