Split monolithic scroll.py into focused modules: - viewport.py: terminal size (tw/th), ANSI positioning helpers - frame.py: FrameTimer class, scroll step calculation - layers.py: message overlay, ticker zone, firehose rendering - scroll.py: simplified orchestrator, imports from new modules Add stream controller and event types for future event-driven architecture: - controller.py: StreamController for source initialization and stream lifecycle - events.py: EventType enum and event dataclasses (HeadlineEvent, FrameTickEvent, etc.) Added tests for new modules: - test_viewport.py: 8 tests for viewport utilities - test_frame.py: 10 tests for frame timing - test_layers.py: 13 tests for layer compositing - test_events.py: 11 tests for event types - test_controller.py: 6 tests for stream controller This enables: - Testable chunks with clear responsibilities - Reusable viewport utilities across modules - Better separation of concerns in render pipeline - Foundation for future event-driven architecture Also includes Phase 1 documentation updates in code comments.
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""
|
|
Stream controller - manages input sources and orchestrates the render stream.
|
|
"""
|
|
|
|
from engine.config import Config, get_config
|
|
from engine.mic import MicMonitor
|
|
from engine.ntfy import NtfyPoller
|
|
from engine.scroll import stream
|
|
|
|
|
|
class StreamController:
|
|
"""Controls the stream lifecycle - initializes sources and runs the stream."""
|
|
|
|
def __init__(self, config: Config | None = None):
|
|
self.config = config or get_config()
|
|
self.mic: MicMonitor | None = None
|
|
self.ntfy: NtfyPoller | None = None
|
|
|
|
def initialize_sources(self) -> tuple[bool, bool]:
|
|
"""Initialize microphone and ntfy sources.
|
|
|
|
Returns:
|
|
(mic_ok, ntfy_ok) - success status for each source
|
|
"""
|
|
self.mic = MicMonitor(threshold_db=self.config.mic_threshold_db)
|
|
mic_ok = self.mic.start() if self.mic.available else False
|
|
|
|
self.ntfy = NtfyPoller(
|
|
self.config.ntfy_topic,
|
|
reconnect_delay=self.config.ntfy_reconnect_delay,
|
|
display_secs=self.config.message_display_secs,
|
|
)
|
|
ntfy_ok = self.ntfy.start()
|
|
|
|
return bool(mic_ok), ntfy_ok
|
|
|
|
def run(self, items: list) -> None:
|
|
"""Run the stream with initialized sources."""
|
|
if self.mic is None or self.ntfy is None:
|
|
self.initialize_sources()
|
|
stream(items, self.ntfy, self.mic)
|
|
|
|
def cleanup(self) -> None:
|
|
"""Clean up resources."""
|
|
if self.mic:
|
|
self.mic.stop()
|