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 all 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 @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Added `min_color` and `max_color` to Sparklines constructor, which take precedence over CSS https://github.com/Textualize/textual/pull/5174
- Added new demo `python -m textual`, not *quite* finished but better than the old one https://github.com/Textualize/textual/pull/5174
- Added `Screen.can_view_partial` and `Widget.can_view_partial` https://github.com/Textualize/textual/pull/5174
- Added `App.is_web` property to indicate if the app is running via a web browser https://github.com/Textualize/textual/pull/5128

### Fixed

Expand Down
5 changes: 5 additions & 0 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,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