theme: Added random option. -f random

This commit is contained in:
Dylan Araps 2018-03-18 15:23:30 +11:00
parent 1cff79bcc6
commit 7c3e1ad4e8
2 changed files with 14 additions and 4 deletions

View File

@ -106,7 +106,9 @@ def process_args(args):
sys.exit(0)
if args.f == "list_themes":
print("Themes:", ", ".join(theme.index()))
themes = theme.index()
themes = [theme.name.replace(".json", "") for theme in themes]
print("Themes:", ", ".join(themes))
sys.exit(0)
if args.q:

View File

@ -2,6 +2,7 @@
Theme file handling.
"""
import os
import random
import sys
from .settings import CONF_DIR, MODULE_DIR
@ -10,9 +11,11 @@ from . import util
def index():
"""List all installed theme files."""
themes = os.listdir(os.path.join(CONF_DIR, "colorschemes"))
themes += os.listdir(os.path.join(MODULE_DIR, "colorschemes"))
return [theme.replace(".json", "") for theme in themes]
themes = [theme for theme in
os.scandir(os.path.join(CONF_DIR, "colorschemes"))]
themes += [theme for theme in
os.scandir(os.path.join(MODULE_DIR, "colorschemes"))]
return themes
def terminal_sexy_to_wal(data):
@ -46,6 +49,11 @@ def file(input_file):
elif os.path.isfile(theme_file):
theme_file = theme_file
elif input_file == "random":
themes = [theme.path for theme in index()]
random.shuffle(themes)
theme_file = themes[0]
# Parse the theme file.
if os.path.isfile(theme_file):
data = util.read_file_json(theme_file)