Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app): add is_web property #5128

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 https://github.com/Textualize/textual/pull/5128

## [0.83.0] - 2024-10-10

Expand Down
5 changes: 5 additions & 0 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/textual/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?"""
Expand Down
4 changes: 4 additions & 0 deletions src/textual/drivers/web_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Loading