feat: render screenshots using session theme palettes
Pass per-theme background, foreground, and 16-color palettes into the SVG exporter so screenshots match the active session theme (including ANSI colors). Adds theme palette mappings and updates screenshot tests to validate themed backgrounds and palette-aware color conversion.
This commit is contained in:
@@ -183,6 +183,14 @@ class TestLocalServerHelpers:
|
||||
|
||||
screen_buffer = screen_buffer_factory(["hello", ""])
|
||||
mock_session.get_screen_snapshot = AsyncMock(return_value=(80, 2, screen_buffer, True))
|
||||
server.session_manager.apps_by_slug["rk"] = App(
|
||||
name="Test",
|
||||
slug="rk",
|
||||
path="./",
|
||||
command="echo test",
|
||||
terminal=True,
|
||||
theme="dracula",
|
||||
)
|
||||
|
||||
monkeypatch.setattr(
|
||||
server.session_manager, "get_session_by_route_key", lambda _rk: mock_session
|
||||
@@ -191,6 +199,7 @@ class TestLocalServerHelpers:
|
||||
response = await server._handle_screenshot(request)
|
||||
assert response.content_type == "image/svg+xml"
|
||||
assert "<svg" in response.text
|
||||
assert "#282a36" in response.text
|
||||
|
||||
out = capsys.readouterr()
|
||||
assert out.out == ""
|
||||
|
||||
@@ -55,6 +55,30 @@ class TestColorToHex:
|
||||
"""Color conversion covers named/hex/default cases."""
|
||||
assert _color_to_hex(color, is_foreground=is_foreground) == expected
|
||||
|
||||
def test_color_to_hex_uses_palette_defaults(self) -> None:
|
||||
palette = {"red": "#123456"}
|
||||
assert _color_to_hex(
|
||||
"default",
|
||||
is_foreground=True,
|
||||
palette=palette,
|
||||
default_fg="#111111",
|
||||
default_bg="#222222",
|
||||
) == "#111111"
|
||||
assert _color_to_hex(
|
||||
"default",
|
||||
is_foreground=False,
|
||||
palette=palette,
|
||||
default_fg="#111111",
|
||||
default_bg="#222222",
|
||||
) == "#222222"
|
||||
assert _color_to_hex(
|
||||
"red",
|
||||
is_foreground=True,
|
||||
palette=palette,
|
||||
default_fg="#111111",
|
||||
default_bg="#222222",
|
||||
) == "#123456"
|
||||
|
||||
|
||||
class TestEscapeXml:
|
||||
"""Tests for XML escaping."""
|
||||
|
||||
Reference in New Issue
Block a user