#!/usr/bin/env python3
"""
Simple REPL Demo - Just shows the REPL effect rendering

This is a simpler version that doesn't require raw terminal mode,
just demonstrates the REPL effect rendering.
"""

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).parent.parent))

from engine.effects.plugins import discover_plugins
from engine.effects.registry import get_registry
from engine.effects.types import EffectContext
from engine.pipeline.hybrid_config import PipelineConfig


def main():
    """Run simple REPL demo."""
    print("Simple REPL Demo")
    print("=" * 50)

    # Discover plugins
    discover_plugins()

    # Create a simple pipeline with REPL
    config = PipelineConfig(
        source="headlines",
        effects=[{"name": "repl", "intensity": 1.0}],
        display={"backend": "null"},
    )

    pipeline = config.to_pipeline(viewport_width=80, viewport_height=24)

    # Initialize pipeline
    if not pipeline.initialize():
        print("Failed to initialize pipeline")
        return

    # Get the REPL effect
    repl_effect = None
    for stage in pipeline._stages.values():
        if hasattr(stage, "_effect") and stage._effect.name == "repl":
            repl_effect = stage._effect
            break

    if not repl_effect:
        print("REPL effect not found")
        return

    # Get the EffectContext for REPL
    # Note: In a real pipeline, the EffectContext is created per-stage
    # For this demo, we'll simulate by adding commands

    # Add some commands to the output
    repl_effect.process_command("help")
    repl_effect.process_command("status")
    repl_effect.process_command("effects")
    repl_effect.process_command("pipeline")

    # Execute pipeline to see REPL output
    result = pipeline.execute([])

    if result.success:
        print("\nPipeline Output:")
        print("-" * 50)
        for line in result.data:
            print(line)
        print("-" * 50)
        print(f"\n✓ Successfully rendered {len(result.data)} lines")
    else:
        print(f"✗ Pipeline error: {result.error}")


if __name__ == "__main__":
    main()
