ratatui

Function init_with_options

Source
pub fn init_with_options(options: TerminalOptions) -> DefaultTerminal
Expand description

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 create a new 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 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.

For more control over the terminal initialization, use Terminal::with_options.

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, use this function instead of try_init_with_options to ensure that the terminal is restored correctly if any of the initialization steps fail. If you need to handle the error yourself, use try_init_with_options instead.

§Panics

This function will panic if any of the following steps fail:

  • Enabling raw mode
  • Creating the terminal fails due to being unable to calculate the terminal size

§Examples

use ratatui::{TerminalOptions, Viewport};

let options = TerminalOptions {
    viewport: Viewport::Inline(5),
};
let terminal = ratatui::init_with_options(options);