docs(terminal): add disclaimer about panics to Terminal::new (#2088)

<!-- Please read CONTRIBUTING.md before submitting any pull request. -->
part of #2087

cc @orhun

---------

Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
This commit is contained in:
lolbinarycat 2025-09-24 15:41:09 -05:00 committed by GitHub
parent 881d2452e0
commit b08b4cbd5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<Self, B::Error> {