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.
68 lines
1.4 KiB
Python
68 lines
1.4 KiB
Python
"""
|
|
Event types for the mainline application.
|
|
Defines the core events that flow through the system.
|
|
These types support a future migration to an event-driven architecture.
|
|
"""
|
|
|
|
from dataclasses import dataclass
|
|
from datetime import datetime
|
|
from enum import Enum, auto
|
|
|
|
|
|
class EventType(Enum):
|
|
"""Core event types in the mainline application."""
|
|
|
|
NEW_HEADLINE = auto()
|
|
FRAME_TICK = auto()
|
|
MIC_LEVEL = auto()
|
|
NTFY_MESSAGE = auto()
|
|
STREAM_START = auto()
|
|
STREAM_END = auto()
|
|
|
|
|
|
@dataclass
|
|
class HeadlineEvent:
|
|
"""Event emitted when a new headline is ready for display."""
|
|
|
|
title: str
|
|
source: str
|
|
timestamp: str
|
|
language: str | None = None
|
|
|
|
|
|
@dataclass
|
|
class FrameTickEvent:
|
|
"""Event emitted on each render frame."""
|
|
|
|
frame_number: int
|
|
timestamp: datetime
|
|
delta_seconds: float
|
|
|
|
|
|
@dataclass
|
|
class MicLevelEvent:
|
|
"""Event emitted when microphone level changes significantly."""
|
|
|
|
db_level: float
|
|
excess_above_threshold: float
|
|
timestamp: datetime
|
|
|
|
|
|
@dataclass
|
|
class NtfyMessageEvent:
|
|
"""Event emitted when an ntfy message is received."""
|
|
|
|
title: str
|
|
body: str
|
|
message_id: str | None = None
|
|
timestamp: datetime | None = None
|
|
|
|
|
|
@dataclass
|
|
class StreamEvent:
|
|
"""Event emitted when stream starts or ends."""
|
|
|
|
event_type: EventType
|
|
headline_count: int = 0
|
|
timestamp: datetime | None = None
|