pub fn try_init_with_options(
options: TerminalOptions,
) -> Result<DefaultTerminal>
Expand description
Try to initialize a terminal with the given options and reasonable defaults.
This function allows the caller to specify a custom Viewport
via the TerminalOptions
. It
will attempt to create a DefaultTerminal
and initialize it with the given options and the
following defaults:
- Raw mode is enabled
- A panic hook is installed that restores the terminal before panicking.
Unlike try_init
, this function does not enter the alternate screen buffer as this may not be
desired in all cases. If you need the alternate screen buffer, you should enable it manually
after calling this function.
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_with_options
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
use ratatui::{TerminalOptions, Viewport};
let options = TerminalOptions {
viewport: Viewport::Inline(5),
};
let terminal = ratatui::try_init_with_options(options)?;