From 9aaf45ad33b3e0161ac07d5dfcb169651ffd622e Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Tue, 15 Oct 2024 15:44:47 +0100 Subject: [PATCH 1/2] feat(app): add is_web property Add `App.is_web` property to indicate if the app is running via a web browser. --- CHANGELOG.md | 1 + src/textual/app.py | 5 +++++ src/textual/driver.py | 5 +++++ src/textual/drivers/web_driver.py | 4 ++++ 4 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35395ba0ef..c726e666f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - Added `background-tint` CSS rule https://github.com/Textualize/textual/pull/5117 +- Added `App.is_web` property to indicate if the app is running via a web browser ## [0.83.0] - 2024-10-10 diff --git a/src/textual/app.py b/src/textual/app.py index b49cca30d8..0be742e2a8 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -993,6 +993,11 @@ def is_inline(self) -> bool: """Is the app running in 'inline' mode?""" return False if self._driver is None else self._driver.is_inline + @property + def is_web(self) -> bool: + """Is the app running in 'web' mode via a browser?""" + return False if self._driver is None else self._driver.is_web + @property def screen_stack(self) -> list[Screen[Any]]: """A snapshot of the current screen stack. diff --git a/src/textual/driver.py b/src/textual/driver.py index 6a4f2e5f6b..3a48f7d59d 100644 --- a/src/textual/driver.py +++ b/src/textual/driver.py @@ -54,6 +54,11 @@ def is_inline(self) -> bool: """Is the driver 'inline' (not full-screen)?""" return False + @property + def is_web(self) -> bool: + """Is the driver 'web' (running via a browser)?""" + return False + @property def can_suspend(self) -> bool: """Can this driver be suspended?""" diff --git a/src/textual/drivers/web_driver.py b/src/textual/drivers/web_driver.py index 3b67c0981e..7e1e0ff0b4 100644 --- a/src/textual/drivers/web_driver.py +++ b/src/textual/drivers/web_driver.py @@ -69,6 +69,10 @@ def __init__( """Maps delivery keys to file-like objects, used for delivering files to the browser.""" + @property + def is_web(self) -> bool: + return True + def write(self, data: str) -> None: """Write string data to the output device, which may be piped to the parent process (i.e. textual-web/textual-serve). From 6d220b30f663d5c855208c94853bf1d82ada36e2 Mon Sep 17 00:00:00 2001 From: TomJGooding <101601846+TomJGooding@users.noreply.github.com> Date: Tue, 15 Oct 2024 16:02:34 +0100 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c726e666f9..d3ec487c39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added - Added `background-tint` CSS rule https://github.com/Textualize/textual/pull/5117 -- Added `App.is_web` property to indicate if the app is running via a web browser +- Added `App.is_web` property to indicate if the app is running via a web browser https://github.com/Textualize/textual/pull/5128 ## [0.83.0] - 2024-10-10