feat: add ACTIVE_THEME global and set_active_theme() to config

This commit is contained in:
2026-03-16 02:50:36 -07:00
parent 9acd7b6fd0
commit 7b1481e7b0
2 changed files with 77 additions and 0 deletions

View File

@@ -104,3 +104,26 @@ def set_font_selection(font_path=None, font_index=None):
FONT_PATH = _resolve_font_path(font_path) FONT_PATH = _resolve_font_path(font_path)
if font_index is not None: if font_index is not None:
FONT_INDEX = max(0, int(font_index)) FONT_INDEX = max(0, int(font_index))
# ─── THEME MANAGEMENT ─────────────────────────────────────────
ACTIVE_THEME = None
def set_active_theme(theme_id: str = "green"):
"""Set the active theme by ID.
Args:
theme_id: Theme identifier ("green", "orange", or "purple")
Defaults to "green"
Raises:
KeyError: If theme_id is not in the theme registry
Side Effects:
Sets the ACTIVE_THEME global variable
"""
global ACTIVE_THEME
from engine import themes
ACTIVE_THEME = themes.get_theme(theme_id)

View File

@@ -7,6 +7,8 @@ import tempfile
from pathlib import Path from pathlib import Path
from unittest.mock import patch from unittest.mock import patch
import pytest
from engine import config from engine import config
@@ -160,3 +162,55 @@ class TestSetFontSelection:
config.set_font_selection(font_path=None, font_index=None) config.set_font_selection(font_path=None, font_index=None)
assert original_path == config.FONT_PATH assert original_path == config.FONT_PATH
assert original_index == config.FONT_INDEX assert original_index == config.FONT_INDEX
class TestActiveTheme:
"""Tests for ACTIVE_THEME global and set_active_theme function."""
def test_active_theme_initially_none(self):
"""ACTIVE_THEME should be None at module start."""
# Reset to None to test initial state
original = config.ACTIVE_THEME
config.ACTIVE_THEME = None
try:
assert config.ACTIVE_THEME is None
finally:
config.ACTIVE_THEME = original
def test_set_active_theme_green(self):
"""Setting green theme works correctly."""
config.set_active_theme("green")
assert config.ACTIVE_THEME is not None
assert config.ACTIVE_THEME.name == "green"
assert len(config.ACTIVE_THEME.main_gradient) == 12
assert len(config.ACTIVE_THEME.message_gradient) == 12
def test_set_active_theme_default(self):
"""Default theme is green when not specified."""
config.set_active_theme()
assert config.ACTIVE_THEME is not None
assert config.ACTIVE_THEME.name == "green"
def test_set_active_theme_invalid(self):
"""Invalid theme_id raises KeyError."""
with pytest.raises(KeyError):
config.set_active_theme("nonexistent")
def test_set_active_theme_all_themes(self):
"""Verify orange and purple themes work."""
# Test orange
config.set_active_theme("orange")
assert config.ACTIVE_THEME.name == "orange"
# Test purple
config.set_active_theme("purple")
assert config.ACTIVE_THEME.name == "purple"
def test_set_active_theme_idempotent(self):
"""Calling set_active_theme multiple times works."""
config.set_active_theme("green")
first_theme = config.ACTIVE_THEME
config.set_active_theme("green")
second_theme = config.ACTIVE_THEME
assert first_theme.name == second_theme.name
assert first_theme.name == "green"