refactor: phase 2 - modularization of scroll engine
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.
This commit is contained in:
37
engine/viewport.py
Normal file
37
engine/viewport.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
Viewport utilities — terminal dimensions and ANSI positioning helpers.
|
||||
No internal dependencies.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
def tw() -> int:
|
||||
"""Get terminal width (columns)."""
|
||||
try:
|
||||
return os.get_terminal_size().columns
|
||||
except Exception:
|
||||
return 80
|
||||
|
||||
|
||||
def th() -> int:
|
||||
"""Get terminal height (lines)."""
|
||||
try:
|
||||
return os.get_terminal_size().lines
|
||||
except Exception:
|
||||
return 24
|
||||
|
||||
|
||||
def move_to(row: int, col: int = 1) -> str:
|
||||
"""Generate ANSI escape to move cursor to row, col (1-indexed)."""
|
||||
return f"\033[{row};{col}H"
|
||||
|
||||
|
||||
def clear_screen() -> str:
|
||||
"""Clear screen and move cursor to home."""
|
||||
return "\033[2J\033[H"
|
||||
|
||||
|
||||
def clear_line() -> str:
|
||||
"""Clear current line."""
|
||||
return "\033[K"
|
||||
Reference in New Issue
Block a user