diff --git a/engine/pipeline/presets.py b/engine/pipeline/presets.py index 2c2be77..ceda711 100644 --- a/engine/pipeline/presets.py +++ b/engine/pipeline/presets.py @@ -1,16 +1,35 @@ """ Pipeline presets - Pre-configured pipeline configurations. -Provides PipelinePreset as a unified preset system that wraps -the existing Preset class from animation.py for backwards compatibility. +Provides PipelinePreset as a unified preset system. +Presets can be loaded from TOML files (presets.toml) or defined in code. + +Loading order: +1. Built-in presets.toml in the package +2. User config ~/.config/mainline/presets.toml +3. Local ./presets.toml (overrides earlier) """ from dataclasses import dataclass, field +from typing import Any -from engine.animation import Preset as AnimationPreset from engine.pipeline.params import PipelineParams +def _load_toml_presets() -> dict[str, Any]: + """Load presets from TOML file.""" + try: + from engine.pipeline.preset_loader import load_presets + + return load_presets() + except Exception: + return {} + + +# Pre-load TOML presets +_YAML_PRESETS = _load_toml_presets() + + @dataclass class PipelinePreset: """Pre-configured pipeline with stages and animation. @@ -18,7 +37,6 @@ class PipelinePreset: A PipelinePreset packages: - Initial params: Starting configuration - Stages: List of stage configurations to create - - Animation: Optional animation controller This is the new unified preset that works with the Pipeline class. """ @@ -29,13 +47,9 @@ class PipelinePreset: display: str = "terminal" camera: str = "vertical" effects: list[str] = field(default_factory=list) - initial_params: PipelineParams | None = None - animation_preset: AnimationPreset | None = None def to_params(self) -> PipelineParams: """Convert to PipelineParams.""" - if self.initial_params: - return self.initial_params.copy() params = PipelineParams() params.source = self.source params.display = self.display @@ -44,26 +58,17 @@ class PipelinePreset: return params @classmethod - def from_animation_preset(cls, preset: AnimationPreset) -> "PipelinePreset": - """Create a PipelinePreset from an existing animation Preset.""" - params = preset.initial_params + def from_yaml(cls, name: str, data: dict[str, Any]) -> "PipelinePreset": + """Create a PipelinePreset from YAML data.""" return cls( - name=preset.name, - description=preset.description, - source=params.source, - display=params.display, - camera=params.camera_mode, - effects=params.effect_order.copy(), - initial_params=params, - animation_preset=preset, + name=name, + description=data.get("description", ""), + source=data.get("source", "headlines"), + display=data.get("display", "terminal"), + camera=data.get("camera", "vertical"), + effects=data.get("effects", []), ) - def create_animation_controller(self): - """Create an AnimationController from this preset.""" - if self.animation_preset: - return self.animation_preset.create_controller() - return None - # Built-in presets DEMO_PRESET = PipelinePreset( @@ -121,14 +126,34 @@ FIREHOSE_PRESET = PipelinePreset( ) -PRESETS: dict[str, PipelinePreset] = { - "demo": DEMO_PRESET, - "poetry": POETRY_PRESET, - "pipeline": PIPELINE_VIZ_PRESET, - "websocket": WEBSOCKET_PRESET, - "sixel": SIXEL_PRESET, - "firehose": FIREHOSE_PRESET, -} +# Build presets from YAML data +def _build_presets() -> dict[str, PipelinePreset]: + """Build preset dictionary from all sources.""" + result = {} + + # Add YAML presets + yaml_presets = _YAML_PRESETS.get("presets", {}) + for name, data in yaml_presets.items(): + result[name] = PipelinePreset.from_yaml(name, data) + + # Add built-in presets as fallback (if not in YAML) + builtins = { + "demo": DEMO_PRESET, + "poetry": POETRY_PRESET, + "pipeline": PIPELINE_VIZ_PRESET, + "websocket": WEBSOCKET_PRESET, + "sixel": SIXEL_PRESET, + "firehose": FIREHOSE_PRESET, + } + + for name, preset in builtins.items(): + if name not in result: + result[name] = preset + + return result + + +PRESETS: dict[str, PipelinePreset] = _build_presets() def get_preset(name: str) -> PipelinePreset | None: @@ -150,6 +175,5 @@ def create_preset_from_params( source=params.source, display=params.display, camera=params.camera_mode, - effects=params.effect_order.copy(), - initial_params=params, + effects=params.effect_order.copy() if hasattr(params, "effect_order") else [], )