diff --git a/CHANGELOG.md b/CHANGELOG.md
index be188afcd3..dae30d7d3d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Issue with parsing action strings whose arguments contained quoted closing parenthesis https://github.com/Textualize/textual/pull/2112
- Issues with parsing action strings with tuple arguments https://github.com/Textualize/textual/pull/2112
+- Issue with watching for CSS file changes https://github.com/Textualize/textual/pull/2128
- Fix for tabs not invalidating https://github.com/Textualize/textual/issues/2125
- Fixed scrollbar layers issue https://github.com/Textualize/textual/issues/1358
- Fix for interaction between pseudo-classes and widget-level render caches https://github.com/Textualize/textual/pull/2155
diff --git a/src/textual/_doc.py b/src/textual/_doc.py
index 391c85d128..f6928186d5 100644
--- a/src/textual/_doc.py
+++ b/src/textual/_doc.py
@@ -1,10 +1,11 @@
from __future__ import annotations
import hashlib
+import inspect
import os
import shlex
from pathlib import Path
-from typing import Iterable, cast
+from typing import Awaitable, Callable, Iterable, cast
from textual._import_app import import_app
from textual.app import App
@@ -54,6 +55,7 @@ def take_svg_screenshot(
press: Iterable[str] = (),
title: str | None = None,
terminal_size: tuple[int, int] = (80, 24),
+ run_before: Callable[[Pilot], Awaitable[None] | None] | None = None,
) -> str:
"""
@@ -63,11 +65,13 @@ def take_svg_screenshot(
press: Key presses to run before taking screenshot. "_" is a short pause.
title: The terminal title in the output image.
terminal_size: A pair of integers (rows, columns), representing terminal size.
+ run_before: An arbitrary callable that runs arbitrary code before taking the
+ screenshot. Use this to simulate complex user interactions with the app
+ that cannot be simulated by key presses.
Returns:
An SVG string, showing the content of the terminal window at the time
the screenshot was taken.
-
"""
if app is None:
@@ -90,7 +94,7 @@ def get_cache_key(app: App) -> str:
cache_key = f"{hash.hexdigest()}.svg"
return cache_key
- if app_path is not None:
+ if app_path is not None and run_before is None:
screenshot_cache = Path(SCREENSHOT_CACHE)
screenshot_cache.mkdir(exist_ok=True)
@@ -100,6 +104,10 @@ def get_cache_key(app: App) -> str:
async def auto_pilot(pilot: Pilot) -> None:
app = pilot.app
+ if run_before is not None:
+ result = run_before(pilot)
+ if inspect.isawaitable(result):
+ await result
await pilot.press(*press)
await pilot.wait_for_scheduled_animations()
await pilot.pause()
@@ -116,7 +124,7 @@ async def auto_pilot(pilot: Pilot) -> None:
),
)
- if app_path is not None:
+ if app_path is not None and run_before is None:
screenshot_path.write_text(svg)
assert svg is not None
diff --git a/src/textual/app.py b/src/textual/app.py
index 9496c64c67..85695409e5 100644
--- a/src/textual/app.py
+++ b/src/textual/app.py
@@ -1081,7 +1081,6 @@ async def _on_css_change(self) -> None:
self.bell()
else:
self.stylesheet = stylesheet
- self.reset_styles()
self.stylesheet.update(self)
self.screen.refresh(layout=True)
diff --git a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr
index 0f3d41b3e4..42c7fd18a1 100644
--- a/tests/snapshot_tests/__snapshots__/test_snapshots.ambr
+++ b/tests/snapshot_tests/__snapshots__/test_snapshots.ambr
@@ -1985,6 +1985,161 @@
'''
# ---
+# name: test_css_hot_reloading
+ '''
+
+
+ '''
+# ---
# name: test_css_property[align.py]
'''