mirror of
https://github.com/Benexl/FastAnime.git
synced 2026-01-04 00:37:04 -08:00
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from ...core.config import AppConfig
|
|
|
|
from .base import BaseSelector
|
|
|
|
SELECTORS = ["fzf", "rofi", "default"]
|
|
|
|
|
|
class SelectorFactory:
|
|
@staticmethod
|
|
def create(config: "AppConfig") -> BaseSelector:
|
|
"""
|
|
Factory to create a selector instance based on the configuration.
|
|
"""
|
|
from ...core.plugins.manager import plugin_manager
|
|
|
|
selector_name = config.general.selector
|
|
|
|
# Check if it's a plugin first
|
|
if plugin_manager.is_plugin("selector", selector_name):
|
|
try:
|
|
return plugin_manager.load_component("selector", selector_name)
|
|
except Exception as e:
|
|
raise ValueError(f"Could not load plugin selector '{selector_name}': {e}") from e
|
|
|
|
# Handle built-in selectors
|
|
if selector_name not in SELECTORS:
|
|
raise ValueError(
|
|
f"Unsupported selector: '{selector_name}'.Available selectors are: {SELECTORS}"
|
|
)
|
|
|
|
# Instantiate the class, passing the relevant config section
|
|
if selector_name == "fzf":
|
|
from .fzf import FzfSelector
|
|
|
|
return FzfSelector(config.fzf)
|
|
if selector_name == "rofi":
|
|
from .rofi import RofiSelector
|
|
|
|
return RofiSelector(config.rofi)
|
|
|
|
from .inquirer import InquirerSelector
|
|
|
|
return InquirerSelector()
|
|
|
|
|
|
# Simple alias for ease of use
|
|
create_selector = SelectorFactory.create
|