ratatui

Function try_init

source
pub fn try_init() -> Result<DefaultTerminal>
Available on crate feature crossterm only.
Expand description

Try to initialize a terminal using reasonable defaults for most applications.

This function will attempt to create a DefaultTerminal and initialize it with the following defaults:

  • Raw mode is enabled
  • Alternate screen buffer enabled
  • A panic hook is installed that restores the terminal before panicking.
  • A Terminal is created using CrosstermBackend writing to Stdout

If any of these steps fail, the error is returned.

Ensure that this method is called after your app installs any other panic hooks to ensure the terminal is restored before the other hooks are called.

Generally, you should use init instead of this function, as the panic hook installed by this function will ensure that any failures during initialization will restore the terminal before panicking. This function is provided for cases where you need to handle the error yourself.

ยงExamples

let terminal = ratatui::try_init()?;