Private
Public Access
0
0

refactor(theme_2): remove top-level NERV theme imports; use _require_warmed

Phase 5B of startup_speedup_20260606 track.

src/theme_2.py had 3 top-level NERV imports:
  from src import theme_nerv
  from src.theme_nerv import DATA_GREEN
  from src.theme_nerv_fx import CRTFilter, AlertPulsing, StatusFlicker

And 3 module-level FX object instantiations:
  _crt_filter     = CRTFilter()
  _alert_pulsing  = AlertPulsing()
  _status_flicker = StatusFlicker()

ALL removed. The 3 use sites now lookup via _require_warmed:
- apply() NERV branch: theme_nerv = _require_warmed('src.theme_nerv')
- ai_text_color(): theme_nerv = _require_warmed('src.theme_nerv')
  (then uses theme_nerv.DATA_GREEN)
- render_post_fx(): theme_nerv_fx = _require_warmed('src.theme_nerv_fx')
  (then creates FX objects locally per-call)

The _status_flicker was instantiated but never used (dead code path;
the StatusFlicker class is still importable via theme_nerv_fx but not
auto-constructed in theme_2.py).

TESTS:
- tests/test_theme_2_no_top_level_nerv.py: 4/4 PASS (all RED -> GREEN)
- tests/test_theme.py, test_theme_nerv.py, test_theme_nerv_fx.py,
  test_theme_models.py: 21/21 PASS (no breakage)

EFFECTIVENESS: import src.theme_2 no longer triggers src.theme_nerv or
src.theme_nerv_fx (~485ms combined). For users on default theme, these
are NEVER loaded. For NERV users, the warmup pre-loads on _io_pool and
the lookup is O(1).

NEXT: Phase 5C (markdown table) follows same TDD pattern.
This commit is contained in:
2026-06-06 16:55:20 -04:00
parent 494f68f9d9
commit 69d098baaa
2 changed files with 126 additions and 12 deletions
+19 -12
View File
@@ -14,14 +14,16 @@ from contextlib import nullcontext
from imgui_bundle import imgui, hello_imgui
from typing import Any, Optional
from src import theme_nerv
from src import imgui_scopes as imscope
from src.theme_nerv import DATA_GREEN
from src.theme_nerv_fx import CRTFilter, AlertPulsing, StatusFlicker
from src.module_loader import _require_warmed
from src.paths import get_global_themes_path
from src.theme_models import ThemeFile, load_themes_from_dir, load_themes_from_toml
# Removed top-level NERV imports (startup_speedup_20260606 Phase 5B).
# src.theme_nerv and src.theme_nerv_fx are warmed on AppController's _io_pool
# and accessed via _require_warmed() at the use sites below (NERV palette
# branch of apply(), ai_text_color() when is_nerv_active(), and render_post_fx()).
# ------------------------------------------------------------------ palettes
@@ -106,9 +108,9 @@ def _tone_map(rgb: tuple[float, float, float, float], palette: str) -> tuple[flo
r = max(0, r)**(1.0/g); g_val = max(0, g_val)**(1.0/g); bl = max(0, bl)**(1.0/g)
return (max(0.0, min(1.0, r)), max(0.0, min(1.0, g_val)), max(0.0, min(1.0, bl)), a)
_crt_filter = CRTFilter()
_alert_pulsing = AlertPulsing()
_status_flicker = StatusFlicker()
# NERV FX objects (CRTFilter, AlertPulsing, StatusFlicker) are now created
# lazily in render_post_fx() so the src.theme_nerv_fx import is deferred
# to first use. The static-level instantiations were removed in Phase 5B.
# ------------------------------------------------------------------ public API
@@ -213,6 +215,7 @@ def apply(palette_name: str) -> None:
global _current_palette
_current_palette = palette_name
if palette_name == 'NERV':
theme_nerv = _require_warmed("src.theme_nerv")
theme_nerv.apply_nerv()
apply_syntax_palette(get_syntax_palette_for_theme(palette_name))
return
@@ -386,7 +389,8 @@ def get_tweaked_theme() -> hello_imgui.ImGuiTweakedTheme:
def ai_text_color() -> imgui.ImVec4:
if is_nerv_active():
return imgui.ImVec4(*DATA_GREEN)
theme_nerv = _require_warmed("src.theme_nerv")
return imgui.ImVec4(*theme_nerv.DATA_GREEN)
return imgui.get_style().color_(imgui.Col_.text)
def ai_text_style():
@@ -395,10 +399,13 @@ def ai_text_style():
"""Returns a subtle background tint color based on the message role."""
def render_post_fx(width: float, height: float, ai_status: str, crt_enabled: bool) -> None:
"""Updates and renders the alert and CRT filters."""
_alert_pulsing.update(ai_status)
_alert_pulsing.render(width, height)
_crt_filter.enabled = crt_enabled
_crt_filter.render(width, height)
theme_nerv_fx = _require_warmed("src.theme_nerv_fx")
alert_pulsing = theme_nerv_fx.AlertPulsing()
crt_filter = theme_nerv_fx.CRTFilter()
alert_pulsing.update(ai_status)
alert_pulsing.render(width, height)
crt_filter.enabled = crt_enabled
crt_filter.render(width, height)
# ------------------------------------------------------------------ init
load_themes_from_disk()