mirror of
https://github.com/Benexl/FastAnime.git
synced 2026-07-01 18:44:35 -07:00
feat: improve config logic
This commit is contained in:
@@ -33,6 +33,12 @@ from ...core.config import AppConfig
|
||||
@click.option(
|
||||
"--view", "-v", help="View the current contents of your config", is_flag=True
|
||||
)
|
||||
@click.option(
|
||||
"--view-json",
|
||||
"-vj",
|
||||
help="View the current contents of your config in json format",
|
||||
is_flag=True,
|
||||
)
|
||||
@click.option(
|
||||
"--desktop-entry",
|
||||
"-d",
|
||||
@@ -52,7 +58,9 @@ from ...core.config import AppConfig
|
||||
help="Start the interactive configuration wizard.",
|
||||
)
|
||||
@click.pass_obj
|
||||
def config(user_config: AppConfig, path, view, desktop_entry, update, interactive):
|
||||
def config(
|
||||
user_config: AppConfig, path, view, view_json, desktop_entry, update, interactive
|
||||
):
|
||||
from ...core.constants import USER_CONFIG_PATH
|
||||
from ..config.generate import generate_config_ini_from_app_model
|
||||
from ..config.interactive_editor import InteractiveConfigEditor
|
||||
@@ -60,7 +68,23 @@ def config(user_config: AppConfig, path, view, desktop_entry, update, interactiv
|
||||
if path:
|
||||
print(USER_CONFIG_PATH)
|
||||
elif view:
|
||||
print(generate_config_ini_from_app_model(user_config))
|
||||
from rich.console import Console
|
||||
from rich.syntax import Syntax
|
||||
|
||||
console = Console()
|
||||
config_ini = generate_config_ini_from_app_model(user_config)
|
||||
syntax = Syntax(
|
||||
config_ini,
|
||||
"ini",
|
||||
theme=user_config.general.pygment_style,
|
||||
line_numbers=True,
|
||||
word_wrap=True,
|
||||
)
|
||||
console.print(syntax)
|
||||
elif view_json:
|
||||
import json
|
||||
|
||||
print(json.dumps(user_config.model_dump(mode="json")))
|
||||
elif desktop_entry:
|
||||
_generate_desktop_entry()
|
||||
elif interactive:
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any, Literal, get_args, get_origin
|
||||
|
||||
@@ -97,9 +97,6 @@ class MpvConfig(OtherConfig):
|
||||
default=True,
|
||||
description="Disable using subprocess.Popen for MPV, which can be unstable on some systems.",
|
||||
)
|
||||
force_window: str = Field(
|
||||
default="immediate", description="Value for MPV's --force-window option."
|
||||
)
|
||||
use_python_mpv: bool = Field(
|
||||
default=False,
|
||||
description="Use the python-mpv library for enhanced player control.",
|
||||
@@ -152,6 +149,9 @@ class JikanConfig(OtherConfig):
|
||||
class GeneralConfig(BaseModel):
|
||||
"""Configuration for general application behavior and integrations."""
|
||||
|
||||
pygment_style: str = Field(
|
||||
default="github-dark", description="The pygment style to use"
|
||||
)
|
||||
api_client: Literal["anilist", "jikan"] = Field(
|
||||
default="anilist",
|
||||
description="The media database API to use (e.g., 'anilist', 'jikan').",
|
||||
|
||||
+12
-25
@@ -8,39 +8,26 @@ APP_NAME = os.environ.get("FASTANIME_APP_NAME", "fastanime")
|
||||
PROJECT_NAME = "FASTANIME"
|
||||
|
||||
try:
|
||||
APP_DIR = Path(str(resources.files("fastanime")))
|
||||
|
||||
ASSETS_DIR = APP_DIR / "assets"
|
||||
DEFAULTS = ASSETS_DIR / "defaults"
|
||||
ICONS_DIR = ASSETS_DIR / "icons"
|
||||
|
||||
# rofi files
|
||||
ROFI_THEME_MAIN = DEFAULTS / "rofi" / "main.rasi"
|
||||
ROFI_THEME_INPUT = DEFAULTS / "rofi" / "input.rasi"
|
||||
ROFI_THEME_CONFIRM = DEFAULTS / "rofi" / "confirm.rasi"
|
||||
ROFI_THEME_PREVIEW = DEFAULTS / "rofi" / "preview.rasi"
|
||||
|
||||
# fzf
|
||||
FZF_DEFAULT_OPTS = DEFAULTS / "fzf-opts"
|
||||
|
||||
APP_DIR = Path(str(resources.files(PROJECT_NAME.lower())))
|
||||
|
||||
except ModuleNotFoundError:
|
||||
from pathlib import Path
|
||||
|
||||
APP_DIR = Path(__file__).resolve().parent.parent
|
||||
ASSETS_DIR = APP_DIR / "assets"
|
||||
DEFAULTS = ASSETS_DIR / "defaults"
|
||||
ICONS_DIR = ASSETS_DIR / "icons"
|
||||
|
||||
# rofi files
|
||||
ROFI_THEME_MAIN = DEFAULTS / "rofi" / "main.rasi"
|
||||
ROFI_THEME_INPUT = DEFAULTS / "rofi" / "input.rasi"
|
||||
ROFI_THEME_CONFIRM = DEFAULTS / "rofi" / "confirm.rasi"
|
||||
ROFI_THEME_PREVIEW = DEFAULTS / "rofi" / "preview.rasi"
|
||||
ASSETS_DIR = APP_DIR / "assets"
|
||||
DEFAULTS = ASSETS_DIR / "defaults"
|
||||
ICONS_DIR = ASSETS_DIR / "icons"
|
||||
|
||||
# fzf
|
||||
FZF_DEFAULT_OPTS = DEFAULTS / "fzf-opts"
|
||||
# rofi files
|
||||
_ROFI_THEMES_DIR = DEFAULTS / "rofi-themes"
|
||||
ROFI_THEME_MAIN = _ROFI_THEMES_DIR / "main.rasi"
|
||||
ROFI_THEME_INPUT = _ROFI_THEMES_DIR / "input.rasi"
|
||||
ROFI_THEME_CONFIRM = _ROFI_THEMES_DIR / "confirm.rasi"
|
||||
ROFI_THEME_PREVIEW = _ROFI_THEMES_DIR / "preview.rasi"
|
||||
|
||||
# fzf
|
||||
FZF_DEFAULT_OPTS = DEFAULTS / "fzf-opts"
|
||||
|
||||
USER_NAME = os.environ.get("USERNAME", "Anime Fan")
|
||||
|
||||
|
||||
@@ -13,10 +13,28 @@ class RofiSelector(BaseSelector):
|
||||
raise FileNotFoundError("rofi executable not found in PATH.")
|
||||
|
||||
def choose(self, prompt, choices, *, preview=None, header=None):
|
||||
# This maps directly to your existing `run` method
|
||||
# ... (logic from your `Rofi.run` method) ...
|
||||
# It should use self.config.theme_main, etc.
|
||||
pass
|
||||
rofi_input = "\n".join(choices)
|
||||
|
||||
args = [
|
||||
self.executable,
|
||||
"-no-config",
|
||||
"-theme",
|
||||
self.config.theme_main,
|
||||
"-p",
|
||||
prompt,
|
||||
"-i",
|
||||
"-dmenu",
|
||||
]
|
||||
result = subprocess.run(
|
||||
args,
|
||||
input=rofi_input,
|
||||
stdout=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
|
||||
if result:
|
||||
choice = result.stdout.strip()
|
||||
return choice
|
||||
|
||||
def confirm(self, prompt, *, default=False):
|
||||
# Maps directly to your existing `confirm` method
|
||||
|
||||
@@ -2,7 +2,6 @@ from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from fastanime.cli.config.loader import ConfigLoader
|
||||
from fastanime.cli.config.model import AppConfig, GeneralConfig
|
||||
from fastanime.core.exceptions import ConfigError
|
||||
@@ -76,7 +75,6 @@ theme_input = /path/to/input.rasi
|
||||
args = --fullscreen
|
||||
pre_args =
|
||||
disable_popen = false
|
||||
force_window = no
|
||||
use_python_mpv = true
|
||||
"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user