From 004513c8da43b948d8f25be23d8fc315983ae8ba Mon Sep 17 00:00:00 2001 From: Dave Pearson Date: Mon, 22 Jan 2024 14:34:12 +0000 Subject: [PATCH] Experimental suspend context manager Pulling out the very core of #1541 to start to build it up again and experiment and test (getting into the forge so I can then pull it down onto Windows and test there). --- src/textual/app.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/textual/app.py b/src/textual/app.py index bc27445098..913bec2d36 100644 --- a/src/textual/app.py +++ b/src/textual/app.py @@ -38,6 +38,7 @@ Generator, Generic, Iterable, + Iterator, List, Sequence, Type, @@ -3292,3 +3293,11 @@ def action_command_palette(self) -> None: """Show the Textual command palette.""" if self.use_command_palette and not CommandPalette.is_open(self): self.push_screen(CommandPalette(), callback=self.call_next) + + @contextmanager + def suspend(self) -> Iterator[None]: + if self._driver is not None: + self._driver.stop_application_mode() + with redirect_stdout(sys.__stdout__), redirect_stderr(sys.__stderr__): + yield + self._driver.start_application_mode()