summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-06-09 20:50:59 +1000
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-06-09 20:50:59 +1000
commit3110197e423b2248a0304e5f714463bbef9fd61c (patch)
treeb59a7713c20288fae5dd615b3f2bcc6e431722fa /src
parentinstall: add imagemagick dep to shell (diff)
downloadcaelestia-cli-3110197e423b2248a0304e5f714463bbef9fd61c.tar.gz
caelestia-cli-3110197e423b2248a0304e5f714463bbef9fd61c.tar.bz2
caelestia-cli-3110197e423b2248a0304e5f714463bbef9fd61c.zip
feat: create parser
Diffstat (limited to 'src')
-rw-r--r--src/data.py120
-rw-r--r--src/main.py4
-rw-r--r--src/parser.py95
3 files changed, 219 insertions, 0 deletions
diff --git a/src/data.py b/src/data.py
new file mode 100644
index 0000000..f5fbe6e
--- /dev/null
+++ b/src/data.py
@@ -0,0 +1,120 @@
+import os
+from pathlib import Path
+
+config_dir = Path(os.getenv("XDG_CONFIG_HOME", Path.home() / ".config"))
+data_dir = Path(os.getenv("XDG_DATA_HOME", Path.home() / ".local/share"))
+state_dir = Path(os.getenv("XDG_STATE_HOME", Path.home() / ".local/state"))
+
+c_config_dir = config_dir / "caelestia"
+c_data_dir = data_dir / "caelestia"
+c_state_dir = state_dir / "caelestia"
+
+scheme_name_path = c_state_dir / "scheme/name.txt"
+scheme_flavour_path = c_state_dir / "scheme/flavour.txt"
+scheme_colours_path = c_state_dir / "scheme/colours.txt"
+scheme_mode_path = c_state_dir / "scheme/mode.txt"
+scheme_variant_path = c_state_dir / "scheme/variant.txt"
+
+scheme_data_path = Path(__file__).parent.parent / "data/schemes"
+
+scheme_variants = [
+ "tonalspot",
+ "vibrant",
+ "expressive",
+ "fidelity",
+ "fruitsalad",
+ "monochrome",
+ "neutral",
+ "rainbow",
+ "content",
+]
+
+scheme_names: list[str] = None
+scheme_flavours: list[str] = None
+scheme_modes: list[str] = None
+
+scheme_name: str = None
+scheme_flavour: str = None
+scheme_colours: dict[str, str] = None
+scheme_mode: str = None
+scheme_variant: str = None
+
+
+def get_scheme_path() -> Path:
+ return (scheme_data_path / get_scheme_name() / get_scheme_flavour() / get_scheme_mode()).with_suffix(".txt")
+
+
+def get_scheme_names() -> list[str]:
+ global scheme_names
+
+ if scheme_names is None:
+ scheme_names = [f.name for f in scheme_data_path.iterdir() if f.is_dir()]
+
+ return scheme_names
+
+
+def get_scheme_flavours() -> list[str]:
+ global scheme_flavours
+
+ if scheme_flavours is None:
+ scheme_flavours = [f.name for f in (scheme_data_path / get_scheme_name()).iterdir() if f.is_dir()]
+
+ return scheme_flavours
+
+
+def get_scheme_modes() -> list[str]:
+ global scheme_modes
+
+ if scheme_modes is None:
+ scheme_modes = [
+ f.stem for f in (scheme_data_path / get_scheme_name() / get_scheme_flavour()).iterdir() if f.is_file()
+ ]
+
+ return scheme_modes
+
+
+def get_scheme_name() -> str:
+ global scheme_name
+
+ if scheme_name is None:
+ scheme_name = scheme_name_path.read_text().strip() if scheme_name_path.exists() else "catppuccin"
+
+ return scheme_name
+
+
+def get_scheme_flavour() -> str:
+ global scheme_flavour
+
+ if scheme_flavour is None:
+ scheme_flavour = scheme_flavour_path.read_text().strip() if scheme_flavour_path.exists() else "mocha"
+
+ return scheme_flavour
+
+
+def get_scheme_colours() -> dict[str, str]:
+ global scheme_colours
+
+ if scheme_colours is None:
+ scheme_colours = {
+ k.strip(): v.strip() for k, v in (line.split(" ") for line in get_scheme_path().read_text().split("\n"))
+ }
+
+ return scheme_colours
+
+
+def get_scheme_mode() -> str:
+ global scheme_mode
+
+ if scheme_mode is None:
+ scheme_mode = scheme_mode_path.read_text().strip() if scheme_mode_path.exists() else "dark"
+
+ return scheme_mode
+
+
+def get_scheme_variant() -> str:
+ global scheme_variant
+
+ if scheme_variant is None:
+ scheme_variant = scheme_variant_path.read_text().strip() if scheme_variant_path.exists() else "tonalspot"
+
+ return scheme_variant
diff --git a/src/main.py b/src/main.py
new file mode 100644
index 0000000..e206a79
--- /dev/null
+++ b/src/main.py
@@ -0,0 +1,4 @@
+from parser import parse_args
+
+if __name__ == "__main__":
+ parse_args()
diff --git a/src/parser.py b/src/parser.py
new file mode 100644
index 0000000..5629c63
--- /dev/null
+++ b/src/parser.py
@@ -0,0 +1,95 @@
+import argparse
+
+from data import get_scheme_names, scheme_variants
+
+
+def parse_args() -> argparse.Namespace:
+ parser = argparse.ArgumentParser(prog="caelestia", description="Main control script for the Caelestia dotfiles")
+
+ # Add subcommand parsers
+ command_parser = parser.add_subparsers(
+ title="subcommands", description="valid subcommands", metavar="COMMAND", help="the subcommand to run"
+ )
+
+ # Create parser for shell opts
+ shell_parser = command_parser.add_parser("shell", help="start or message the shell")
+ # TODO: use set_defaults to set func and run
+ shell_parser.add_argument("message", nargs="*", help="a message to send to the shell")
+ shell_parser.add_argument("-s", "--show", action="store_true", help="print all shell IPC commands")
+ shell_parser.add_argument("-l", "--log", action="store_true", help="print the shell log")
+
+ # Create parser for toggle opts
+ toggle_parser = command_parser.add_parser("toggle", help="toggle a special workspace")
+ toggle_parser.add_argument(
+ "workspace", choices=["communication", "music", "sysmon", "specialws", "todo"], help="the workspace to toggle"
+ )
+
+ # Create parser for workspace-action opts
+ ws_action_parser = command_parser.add_parser(
+ "workspace-action", help="execute a Hyprland workspace dispatcher in the current group"
+ )
+ ws_action_parser.add_argument(
+ "-g", "--group", action="store_true", help="whether to execute the dispatcher on a group"
+ )
+ ws_action_parser.add_argument(
+ "dispatcher", choices=["workspace", "movetoworkspace"], help="the dispatcher to execute"
+ )
+ ws_action_parser.add_argument("workspace", type=int, help="the workspace to pass to the dispatcher")
+
+ # Create parser for scheme opts
+ scheme_parser = command_parser.add_parser("scheme", help="manage the colour scheme")
+ scheme_parser.add_argument("-g", "--get", action="store_true", help="print the current scheme")
+ scheme_parser.add_argument("-r", "--random", action="store_true", help="switch to a random scheme")
+ scheme_parser.add_argument("-n", "--name", choices=get_scheme_names(), help="the name of the scheme to switch to")
+ scheme_parser.add_argument("-f", "--flavour", help="the flavour to switch to")
+ scheme_parser.add_argument("-m", "--mode", choices=["dark", "light"], help="the mode to switch to")
+
+ # Create parser for variant opts
+ variant_parser = command_parser.add_parser("variant", help="manage the dynamic scheme variant")
+ variant_parser.add_argument("-g", "--get", action="store_true", help="print the current dynamic scheme variant")
+ variant_parser.add_argument("-s", "--set", choices=scheme_variants, help="set the current dynamic scheme variant")
+ variant_parser.add_argument("-r", "--random", action="store_true", help="switch to a random variant")
+
+ # Create parser for screenshot opts
+ screenshot_parser = command_parser.add_parser("screenshot", help="take a screenshot")
+ screenshot_parser.add_argument("-r", "--region", help="take a screenshot of a region")
+ screenshot_parser.add_argument(
+ "-f", "--freeze", action="store_true", help="freeze the screen while selecting a region"
+ )
+
+ # Create parser for record opts
+ record_parser = command_parser.add_parser("record", help="start a screen recording")
+ record_parser.add_argument("-r", "--region", action="store_true", help="record a region")
+ record_parser.add_argument("-s", "--sound", action="store_true", help="record audio")
+
+ # Create parser for clipboard opts
+ clipboard_parser = command_parser.add_parser("clipboard", help="open clipboard history")
+ clipboard_parser.add_argument("-d", "--delete", action="store_true", help="delete from clipboard history")
+
+ # Create parser for emoji-picker opts
+ emoji_parser = command_parser.add_parser("emoji-picker", help="toggle the emoji picker")
+
+ # Create parser for wallpaper opts
+ wallpaper_parser = command_parser.add_parser("wallpaper", help="manage the wallpaper")
+ wallpaper_parser.add_argument("-g", "--get", action="store_true", help="print the current wallpaper")
+ wallpaper_parser.add_argument("-r", "--random", action="store_true", help="switch to a random wallpaper")
+ wallpaper_parser.add_argument("-f", "--file", help="the path to the wallpaper to switch to")
+ wallpaper_parser.add_argument("-n", "--no-filter", action="store_true", help="do not filter by size")
+ wallpaper_parser.add_argument(
+ "-t",
+ "--threshold",
+ default=80,
+ help="the minimum percentage of the largest monitor size the image must be greater than to be selected",
+ )
+ wallpaper_parser.add_argument(
+ "-N",
+ "--no-smart",
+ action="store_true",
+ help="do not automatically change the scheme mode based on wallpaper colour",
+ )
+
+ # Create parser for pip opts
+ pip_parser = command_parser.add_parser("pip", help="picture in picture utilities")
+ pip_parser.add_argument("-d", "--daemon", action="store_true", help="start the daemon")
+
+ return parser.parse_args()