How to use color_eyre with Ratatui
Full source code for this how to article is available at: https://github.com/ratatui-org/website/tree/main/code/how-to-color_eyre/
color_eyre crate provides error report handlers for panics and errors. It displays the
reports formatted and in color. To use these handlers, a Ratatui app needs to restore the terminal
before displaying the errors.
First add the crate to your
Add the following imports to
Create a new function
install_hooks() which will ensure your app calls
exiting with a panic or an error.
This example assumes that you have a
tui module in your app with
Example tui.rs module
In your application, wrap errors with extra context as needed:
Add the following import:
Call wrap_err from methods that can fail with an error.