From b08b4cbd5e74961066e1ca7cae6e7ccb3f84fe25 Mon Sep 17 00:00:00 2001 From: lolbinarycat Date: Wed, 24 Sep 2025 15:41:09 -0500 Subject: [PATCH] docs(terminal): add disclaimer about panics to Terminal::new (#2088) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit part of #2087 cc @orhun --------- Co-authored-by: Orhun Parmaksız --- ratatui-core/src/terminal/terminal.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ratatui-core/src/terminal/terminal.rs b/ratatui-core/src/terminal/terminal.rs index 3c8e130d..1127b088 100644 --- a/ratatui-core/src/terminal/terminal.rs +++ b/ratatui-core/src/terminal/terminal.rs @@ -128,6 +128,15 @@ where { /// Creates a new [`Terminal`] with the given [`Backend`] with a full screen viewport. /// + /// Note that unlike `ratatui::init`, this does not install any panic hook, + /// so it is recommended to do that manually when using this function, + /// otherwise any panic messages will be printed to the alternate screen and + /// the terminal may be left in an unusable state. + /// + /// See [how to set up panic hooks](https://ratatui.rs/recipes/apps/panic-hooks/) + /// and [`better-panic` example](https://ratatui.rs/recipes/apps/better-panic/) + /// for more information. + /// /// # Example /// /// ```rust,ignore @@ -137,6 +146,13 @@ where /// /// let backend = CrosstermBackend::new(stdout()); /// let terminal = Terminal::new(backend)?; + /// + /// // Optionally set up a panic hook to restore the terminal on panic. + /// let old_hook = std::panic::take_hook(); + /// std::panic::set_hook(Box::new(move |info| { + /// ratatui::restore(); + /// old_hook(info); + /// })); /// # std::io::Result::Ok(()) /// ``` pub fn new(backend: B) -> Result {