@@ -33,6 +33,7 @@ def list_out():
3333 print (" - random (select a random dark theme)" )
3434 print (" - random_dark (select a random dark theme)" )
3535 print (" - random_light (select a random light theme)" )
36+ print (" - random_user (select a random user theme)" )
3637
3738
3839def list_themes (dark = True ):
@@ -88,6 +89,13 @@ def get_random_theme(dark=True):
8889 return themes [0 ]
8990
9091
92+ def get_random_theme_user ():
93+ """Get a random theme file from user theme directories."""
94+ themes = [theme .path for theme in list_themes_user ()]
95+ random .shuffle (themes )
96+ return themes [0 ]
97+
98+
9199def file (input_file , light = False ):
92100 """Import colorscheme from json file."""
93101 util .create_dir (os .path .join (CONF_DIR , "colorschemes/light/" ))
@@ -106,6 +114,9 @@ def file(input_file, light=False):
106114 elif input_file == "random_light" :
107115 theme_file = get_random_theme (light )
108116
117+ elif input_file == "random_user" :
118+ theme_file = get_random_theme_user ()
119+
109120 elif os .path .isfile (user_theme_file ):
110121 theme_file = user_theme_file
111122
@@ -122,3 +133,11 @@ def file(input_file, light=False):
122133 logging .error ("Try adding '-l' to set light themes." )
123134 logging .error ("Try removing '-l' to set dark themes." )
124135 sys .exit (1 )
136+
137+
138+ def save (colors , theme_name , light = False ):
139+ """Save colors to a theme file."""
140+ theme_file = theme_name + ".json"
141+ theme_path = os .path .join (CONF_DIR , "colorschemes" ,
142+ "light" if light else "dark" , theme_file )
143+ util .save_file_json (colors , theme_path )
0 commit comments