Skip to content

Commit

Permalink
interactive: fix dark mode (#3582)
Browse files Browse the repository at this point in the history
Fixes crash when switching theme caused by a textual update. Also adds a
test to catch this in the future.
  • Loading branch information
alexarice authored Dec 6, 2024
1 parent dce0898 commit b5acf31
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 18 additions & 0 deletions tests/interactive/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,21 @@ async def test_argument_pass_screen():

arg_screen_str: type[Screen[Any]] = AddArguments
assert isinstance(app.screen, arg_screen_str)


@pytest.mark.asyncio
async def test_dark_mode():
"""Tests that 'd' switches between dark and light mode"""

async with InputApp(tuple(), tuple()).run_test() as pilot:
app = cast(InputApp, pilot.app)

assert app.theme == "textual-dark"

await pilot.press("d")

assert app.theme == "textual-light"

await pilot.press("d")

assert app.theme == "textual-dark"
4 changes: 3 additions & 1 deletion xdsl/interactive/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,9 @@ def watch_diff_operation_count_tuple(self) -> None:

def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark
self.theme = (
"textual-dark" if self.theme == "textual-light" else "textual-light"
)

def action_quit_app(self) -> None:
"""An action to quit the app."""
Expand Down

0 comments on commit b5acf31

Please sign in to comment.