Skip to content

Commit

Permalink
Merge pull request #5128 from TomJGooding/feat-app-add-is-web-property
Browse files Browse the repository at this point in the history
feat(app): add is_web property
  • Loading branch information
willmcgugan authored Oct 25, 2024
2 parents 5c2111a + b2feee0 commit b9be24f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
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

0 comments on commit b9be24f

Please sign in to comment.