Repository: Textualize/textual
Pull request: fix(app): fix `inline_no_clear`
Fixes #5019. 

I'm afraid I don't fully understand commit 8c01ef7, but this change seems to fix the broken `inline_no_clear` without any regression related to issue #4882 which I believe this commit intended to fix.

- [ ] Docstrings on all new or modified functions / classes 
- [ ] Updated documentation
- [x] Updated CHANGELOG.md (where appropriate)


Problem statement:
`inline_no_clear` broken in v0.77.0
It looks like the `inline_no_clear` option was broken in v0.77.0, from a quick git bisect the culprit seems to be commit 8c01ef7.

If you run the app below where `inline_no_clear=True`, the app output is cleared on exit:

```python
from textual.app import App, ComposeResult
from textual.widgets import Static


class InlineNoClearApp(App):
    def compose(self) -> ComposeResult:
        yield Static("Quitting should not clear the app output")


if __name__ == "__main__":
    app = InlineNoClearApp()
    app.run(inline=True, inline_no_clear=True)

```

Hints from issue discussion:
Thank you for your issue. Give us a little time to review it.

PS. You might want to check the [FAQ](https://textual.textualize.io/FAQ/) if you haven't done so already.

This is an automated reply, generated by [FAQtory](https://github.com/willmcgugan/faqtory)

Commit message: update changelog

Patch to review:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ef0b9537c5..882d5c1672 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
 - Fixed flicker when setting `dark` reactive on startup https://github.com/Textualize/textual/pull/4989
 - Fixed command palette not sorting search results by their match score https://github.com/Textualize/textual/pull/4994
 - Fixed `DataTable` cached height issue on re-populating the table when using auto-height rows https://github.com/Textualize/textual/pull/4992
+- Fixed inline app output being cleared when `inline_no_clear=True` https://github.com/Textualize/textual/issues/5019
 
 ## [0.79.1] - 2024-08-31
 
diff --git a/src/textual/app.py b/src/textual/app.py
index 9bd851c927..9b4ce38b12 100644
--- a/src/textual/app.py
+++ b/src/textual/app.py
@@ -2909,10 +2909,14 @@ async def invoke_ready_callback() -> None:
                             self._driver.write(
                                 Control.move(-cursor_x, -cursor_y + 1).segment.text
                             )
-                            if inline_no_clear and not not self.app._exit_renderables:
+                            if inline_no_clear:
                                 console = Console()
-                                console.print(self.screen._compositor)
-                                console.print()
+                                try:
+                                    console.print(self.screen._compositor)
+                                except ScreenStackError:
+                                    pass
+                                else:
+                                    console.print()
 
                         driver.stop_application_mode()
             except Exception as error:


Code review comments:
diff_hunk: @@ -2909,10 +2909,14 @@ async def invoke_ready_callback() -> None:
                             self._driver.write(
                                 Control.move(-cursor_x, -cursor_y + 1).segment.text
                             )
-                            if inline_no_clear and not not self.app._exit_renderables:
path: src/textual/app.py
text: @user1:
The "not not" is a bug. I think the reasoning was that if there are errors (in the exit renderables) they should be printed rather than the last frame.