Skip to content

Commit

Permalink
hardening
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Jun 14, 2024
1 parent a4c8682 commit 604b04d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/textual/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2617,9 +2617,14 @@ async def recompose(self) -> None:
Recomposing will remove children and call `self.compose` again to remount.
"""
async with self.screen.batch():
await self.screen.query("*").exclude(".-textual-system").remove()
await self.screen.mount_all(compose(self))
if self._exit:
return
try:
async with self.screen.batch():
await self.screen.query("*").exclude(".-textual-system").remove()
await self.screen.mount_all(compose(self))
except ScreenStackError:
pass

def _register_child(
self, parent: DOMNode, child: Widget, before: int | None, after: int | None
Expand Down
2 changes: 2 additions & 0 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,8 @@ def mount_all(
Only one of ``before`` or ``after`` can be provided. If both are
provided a ``MountError`` will be raised.
"""
if self.app._exit:
return AwaitMount(self, [])
await_mount = self.mount(*widgets, before=before, after=after)
return await_mount

Expand Down
11 changes: 9 additions & 2 deletions src/textual/widgets/_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from rich.text import Text

from ..app import RenderResult
from ..dom import NoScreen
from ..events import Click, Mount
from ..reactive import Reactive
from ..widget import Widget
Expand Down Expand Up @@ -213,10 +214,16 @@ def screen_sub_title(self) -> str:

def _on_mount(self, _: Mount) -> None:
async def set_title() -> None:
self.query_one(HeaderTitle).text = self.screen_title
try:
self.query_one(HeaderTitle).text = self.screen_title
except NoScreen:
pass

async def set_sub_title() -> None:
self.query_one(HeaderTitle).sub_text = self.screen_sub_title
try:
self.query_one(HeaderTitle).sub_text = self.screen_sub_title
except NoScreen:
pass

self.watch(self.app, "title", set_title)
self.watch(self.app, "sub_title", set_sub_title)
Expand Down

0 comments on commit 604b04d

Please sign in to comment.