Skip to content

Commit 9aaf45a

Browse files
committed
feat(app): add is_web property
Add `App.is_web` property to indicate if the app is running via a web browser.
1 parent 4a822bc commit 9aaf45a

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1414
### Added
1515

1616
- Added `background-tint` CSS rule https://github.com/Textualize/textual/pull/5117
17+
- Added `App.is_web` property to indicate if the app is running via a web browser
1718

1819
## [0.83.0] - 2024-10-10
1920

src/textual/app.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,11 @@ def is_inline(self) -> bool:
993993
"""Is the app running in 'inline' mode?"""
994994
return False if self._driver is None else self._driver.is_inline
995995

996+
@property
997+
def is_web(self) -> bool:
998+
"""Is the app running in 'web' mode via a browser?"""
999+
return False if self._driver is None else self._driver.is_web
1000+
9961001
@property
9971002
def screen_stack(self) -> list[Screen[Any]]:
9981003
"""A snapshot of the current screen stack.

src/textual/driver.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ def is_inline(self) -> bool:
5454
"""Is the driver 'inline' (not full-screen)?"""
5555
return False
5656

57+
@property
58+
def is_web(self) -> bool:
59+
"""Is the driver 'web' (running via a browser)?"""
60+
return False
61+
5762
@property
5863
def can_suspend(self) -> bool:
5964
"""Can this driver be suspended?"""

src/textual/drivers/web_driver.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ def __init__(
6969
"""Maps delivery keys to file-like objects, used
7070
for delivering files to the browser."""
7171

72+
@property
73+
def is_web(self) -> bool:
74+
return True
75+
7276
def write(self, data: str) -> None:
7377
"""Write string data to the output device, which may be piped to
7478
the parent process (i.e. textual-web/textual-serve).

0 commit comments

Comments
 (0)