begin subparser integration

This commit is contained in:
2024-05-18 15:35:10 -07:00
parent d2c9ff9c06
commit 888bb52d23
10 changed files with 173 additions and 56 deletions

0
autoconf/__init__.py Normal file
View File

23
autoconf/__main__.py Normal file
View File

@@ -0,0 +1,23 @@
import argparse
from gen_theme import add_gen_subparser
from set_theme import add_set_subparser
parser = argparse.ArgumentParser(
'autoconf',
description='Generate theme files for various applications. Uses a template (in TOML ' \
+ 'format) to map application-specific config keywords to colors (in JSON ' \
+ 'format).'
)
subparsers = parser.get_subparsers()
add_gen_subparser(subparsers)
add_set_subparser(subparsers)
args = parser.parse_args()
if __name__ == '__main__':
if 'func' in args:
args.func(args)
else:
parser.print_help()

View File

@@ -1,42 +0,0 @@
# App registry -- apps eligible for theme switching
#
# Each app must be register under the "app" directive, i.e., as "[app.<app-name>]"
#
# Option details:
# - external_theme: if False (default), indicates an app of type 1 as per the README. That
# is, an external theme file cannot be used, and theme switching will involve switch the
# canonical config setting. If True, the app's theme can be set through an external theme
# file.
# - support_os: OSes that support theme switching according to the implemented paths.
# Accepts a list of `uname -s` strings to match system.
# - refresh_cmd: a command to run for live refreshing the application's color scheme after
# it's been set for running instances.
#
# Default example
# [app.default]
# external_theme = False
# config_dir = '~/.config/default/'
# config_file = 'default.conf'
# refresh_cmd = 'app reload-config'
#
[app.kitty]
external_theme = true
config_dir = '~/.config/kitty/'
config_file = 'kitty.conf'
supported_oses = ['Linux', 'Darwin']
refresh_cmd = 'kill -s USR1 $(pgrep kitty)'
[app.sway]
external_theme = false
config_dir = '~/.config/sway/'
config_file = 'config'
supported_oses = ['Linux']
#refresh_cmd = 'swaymsg reload'
[app.waybar]
external_theme = false
config_dir = '~/.config/waybar/'
config_file = 'style.css'
supported_oses = ['Linux']
refresh_cmd = 'swaymsg reload'

View File

@@ -9,33 +9,36 @@ def get_running_path():
return Path(calling_module.__file__).parent
parser = argparse.ArgumentParser(
description='Generate theme files for various applications. Uses a template (in TOML ' \
+ 'format) to map application-specific config keywords to colors (in JSON ' \
+ 'format).'
)
parser.add_argument(
'-a', '--app',
required=True,
help='Application target for theme. Supported: ["kitty"]'
)
parser.add_argument(
'-p', '--palette',
required=True,
help='Palette to use for template mappings. Uses local "theme/<palette>/colors.json".'
)
parser.add_argument(
'-t', '--template',
default=None,
help='Path to TOML template file. If omitted, app\'s default template path is used.' \
+ 'If a directory is provided, all TOML files in the folder will be used.'
)
parser.add_argument(
'-o', '--output',
default=None,
help='Output file path for theme. If omitted, app\'s default theme output path is used.'
)
args = parser.parse_args()
def add_gen_subparser(subparsers):
parser = subparsers.add_parser(
'gen',
description='Generate theme files for various applications. Uses a template (in TOML ' \
+ 'format) to map application-specific config keywords to colors (in JSON ' \
+ 'format).'
)
parser.add_argument(
'-a', '--app',
required=True,
help='Application target for theme. Supported: ["kitty"]'
)
parser.add_argument(
'-p', '--palette',
required=True,
help='Palette to use for template mappings. Uses local "theme/<palette>/colors.json".'
)
parser.add_argument(
'-t', '--template',
default=None,
help='Path to TOML template file. If omitted, app\'s default template path is used.' \
+ 'If a directory is provided, all TOML files in the folder will be used.'
)
parser.add_argument(
'-o', '--output',
default=None,
help='Output file path for theme. If omitted, app\'s default theme output path is used.'
)
parser.set_defaults(func=generate_theme_files)
# separation sequences to use base on app
app_sep_map = {
@@ -104,5 +107,3 @@ def generate_theme_files():
output_file.write_text('\n'.join(output_lines))
print(f'[{len(output_lines)}] lines written to [{output_file}] for app [{theme_app}]')
if __name__ == '__main__':
generate_theme_files()

View File

@@ -8,29 +8,30 @@ from pathlib import Path
from colorama import Fore
parser = argparse.ArgumentParser(
description='Generate theme files for various applications. Uses a template (in TOML ' \
+ 'format) to map application-specific config keywords to colors (in JSON ' \
+ 'format).'
)
parser.add_argument(
'-p', '--palette',
required=True,
help='Palette name, must match a folder in themes/'
)
parser.add_argument(
'-s', '--scheme',
required=True,
help='Preferred lightness scheme, either "light" or "dark".'
)
parser.add_argument(
'-a', '--app',
required=True,
help='Application target for theme. App must be present in the registry. ' \
+ 'Use "*" to apply to all registered apps'
)
args = parser.parse_args()
def add_set_subparser(subparsers):
parser = subparsers.add_parser(
'set',
description='Generate theme files for various applications. Uses a template (in TOML ' \
+ 'format) to map application-specific config keywords to colors (in JSON ' \
+ 'format).'
)
parser.add_argument(
'-p', '--palette',
required=True,
help='Palette name, must match a folder in themes/'
)
parser.add_argument(
'-s', '--scheme',
required=True,
help='Preferred lightness scheme, either "light" or "dark".'
)
parser.add_argument(
'-a', '--app',
required=True,
help='Application target for theme. App must be present in the registry. ' \
+ 'Use "*" to apply to all registered apps'
)
parser.set_defaults(func=update_theme_settings)
def get_running_path():