This folder contains examples that are more application focused.
There are also widget examples in ratatui-widgets
.
You can run these examples using:
cargo run -p example-name
This folder might use unreleased code. Consider viewing the examples in the latest
branch instead
of the main
branch for code which is guaranteed to work with the released ratatui version.
Warning
There may be backwards incompatible changes in these examples, as they are designed to compile
against the main
branch.
There are a few workaround for this problem:
- View the examples as they were when the latest version was release by selecting the tag that matches that version. E.g. https://github.com/ratatui/ratatui/tree/v0.26.1/examples.
- If you're viewing this file on GitHub, there is a combo box at the top of this page which allows you to select any previous tagged version.
- To view the code locally, checkout the tag. E.g.
git switch --detach v0.26.1
. - Use the latest [alpha version of Ratatui] in your app. These are released weekly on Saturdays.
- Compile your code against the main branch either locally by adding e.g.
path = "../ratatui"
to the dependency, or remotely by addinggit = "https://github.com/ratatui/ratatui"
For a list of unreleased breaking changes, see [BREAKING-CHANGES.md].
We don't keep the CHANGELOG updated with unreleased changes, check the git commit history or run
git-cliff -u
against a cloned version of this repository.
The examples contain some opinionated choices in order to make it easier for newer rustaceans to easily be productive in creating applications:
- Each example has an
App
struct, with methods that implement a main loop, handle events and drawing the UI. - We use
color_eyre
for handling errors and panics. See How to use color-eyre with Ratatui on the website for more information about this. - Common code is not extracted into a separate file. This makes each example self-contained and easy to read as a whole.
This is the original demo example from the main README. It is available for each of the backends. Source.
This is the demo example from the main README and crate page. Source.
Shows how to fetch data from GitHub API asynchronously. Source.
Shows how to render a calendar with different styles. Source.
Shows how to render a canvas with different shapes. Source.
Shows how to render line, bar, and scatter charts. Source.
Shows how to handle the supported colors. Source.
Shows the full range of RGB colors in an animation. Source.
Shows how different constraints can be used to layout widgets. Source.
Shows different types of constraints. Source.
Shows how to create a custom widget that can be interacted with the mouse. Source.
Shows how to render hyperlinks in a terminal using OSC 8. Source.
Shows how to use the flex layouts. Source.
Shows how to create a simple TUI with a text. Source.
Shows different types of gauges. Source.
Shows how to use the inlined viewport to render in a specific area of the screen. Source.
Shows how to render a form with input fields. Source.
Shows different types of modifiers. Source.
Shows how to handle mouse events. Source.
Shows how to create a minimal application. Source.
Shows how to handle panics. Source.
Shows how to handle popups. Source.
Shows how to render different types of scrollbars. Source.
Shows how to create an interactive table. Source.
Shows how to create a simple todo list application. Source.
Shows how to use the tracing crate to log to a file. Source.
Shows how to handle user input. Source. Source.
Shows how to render weather data using barchart widget. Source.
Shows how to use WidgetRef
to store widgets in a container. Source.
Shows how to render the Widget
trait in different ways.
How to update these examples?
These gifs were created using VHS. Each example has a
corresponding .tape
file that holds instructions for how to generate the images. Note that the
images themselves are stored in a separate images
git branch to avoid bloating the main
branch.