ratatui/examples
2024-08-10 17:43:13 -07:00
..
demo docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
demo2 feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084) 2024-08-06 00:40:47 -07:00
vhs docs(examples): simplify the barchart example (#1079) 2024-08-06 01:10:58 -07:00
async.rs docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
barchart-grouped.rs docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
barchart.rs docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
block.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
calendar.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
canvas.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
chart.rs docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
colors.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
colors_rgb.rs feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084) 2024-08-06 00:40:47 -07:00
constraint-explorer.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
constraints.rs feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084) 2024-08-06 00:40:47 -07:00
custom_widget.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
docsrs.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
flex.rs feat(buffer): add Buffer::cell, cell_mut and index implementations (#1084) 2024-08-06 00:40:47 -07:00
gauge.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
hello_world.rs chore(deps): remove anyhow from dev dependencies (#1305) 2024-08-06 23:17:11 +03:00
hyperlink.rs docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
inline.rs docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
layout.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
line_gauge.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
list.rs docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
minimal.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
modifiers.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
panic.rs docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
paragraph.rs docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
popup.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
ratatui-logo.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
README.md docs(examples): update barcharts gifs (#1306) 2024-08-06 23:09:40 +03:00
scrollbar.rs docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
sparkline.rs docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
table.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
tabs.rs feat(frame): replace Frame::size() with Frame::area() (#1293) 2024-08-05 20:15:14 -07:00
tracing.rs docs(examples): use ratatui::crossterm in examples (#1315) 2024-08-10 17:43:13 -07:00
user_input.rs feat!: add get/set_cursor_position() methods to Terminal and Backend (#1284) 2024-08-06 04:10:28 -07:00

Examples

This folder might use unreleased code. View the examples for the latest release instead.

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-org/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 adding git = "https://github.com/ratatui-org/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.

Design choices

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.

Not every example has been updated with all these points in mind yet, however over time they will be. None of the above choices are strictly necessary for Ratatui apps, but these choices make examples easier to run, maintain and explain. These choices are designed to help newer users fall into the pit of success when incorporating example code into their own apps. We may also eventually move some of these design choices into the core of Ratatui to simplify apps.

Demo2

This is the demo example from the main README and crate page. Source: demo2.

cargo run --example=demo2 --features="crossterm widget-calendar"

Demo2

Demo

This is the previous demo example from the main README. It is available for each of the backends. Source: demo.rs.

cargo run --example=demo --features=crossterm
cargo run --example=demo --no-default-features --features=termion
cargo run --example=demo --no-default-features --features=termwiz

Demo

Hello World

This is a pretty boring example, but it contains some good documentation on writing tui apps. Source: hello_world.rs.

cargo run --example=hello_world --features=crossterm

Hello World

Barchart

Demonstrates the BarChart widget. Source: barchart.rs.

cargo run --example=barchart --features=crossterm

Barchart

Barchart (Grouped)

Demonstrates the BarChart widget with groups. Source: barchart-grouped.rs.

cargo run --example=barchart-grouped --features=crossterm

Barchart Grouped

Block

Demonstrates the Block widget. Source: block.rs.

cargo run --example=block --features=crossterm

Block

Calendar

Demonstrates the Calendar widget. Source: calendar.rs.

cargo run --example=calendar --features="crossterm widget-calendar"

Calendar

Canvas

Demonstrates the Canvas widget and related shapes in the canvas module. Source: canvas.rs.

cargo run --example=canvas --features=crossterm

Canvas

Chart

Demonstrates the Chart widget. Source: chart.rs.

cargo run --example=chart --features=crossterm

Chart

Colors

Demonstrates the available Color options. These can be used in any style field. Source: colors.rs.

cargo run --example=colors --features=crossterm

Colors

Colors (RGB)

Demonstrates the available RGB Color options. These can be used in any style field. Source: colors_rgb.rs. Uses a half block technique to render two square-ish pixels in the space of a single rectangular terminal cell.

cargo run --example=colors_rgb --features=crossterm

Note: VHs renders full screen animations poorly, so this is a screen capture rather than the output of the VHS tape.

https://github.com/ratatui-org/ratatui/assets/381361/485e775a-e0b5-4133-899b-1e8aeb56e774

Constraint Explorer

Demonstrates the behaviour of each Constraint option with respect to each other across different Flex modes.

cargo run --example=constraint-explorer --features=crossterm

Constraint Explorer

Constraints

Demonstrates how to use Constraint options for defining layout element sizes.

Constraints

cargo run --example=constraints --features=crossterm

Custom Widget

Demonstrates how to implement the Widget trait. Also shows mouse interaction. Source: custom_widget.rs.

cargo run --example=custom_widget --features=crossterm

Custom Widget

Gauge

Demonstrates the Gauge widget. Source: gauge.rs.

cargo run --example=gauge --features=crossterm

Gauge

Flex

Demonstrates the different Flex modes for controlling layout space distribution.

cargo run --example=flex --features=crossterm

Flex

Line Gauge

Demonstrates the Line Gauge widget. Source: line_gauge.rs.

cargo run --example=line_gauge --features=crossterm

LineGauge

Demonstrates how to use OSC 8 to create hyperlinks in the terminal.

cargo run --example=hyperlink --features="crossterm unstable-widget-ref"

Hyperlink

Inline

Demonstrates how to use the Inline Viewport mode for ratatui apps. Source: inline.rs.

cargo run --example=inline --features=crossterm

Inline

Layout

Demonstrates the Layout and interaction between each constraint. Source: layout.rs.

cargo run --example=layout --features=crossterm

Layout

List

Demonstrates the List widget. Source: list.rs.

cargo run --example=list --features=crossterm

List

Modifiers

Demonstrates the style Modifiers. Source: modifiers.rs.

cargo run --example=modifiers --features=crossterm

Modifiers

Minimal

Demonstrates how to create a minimal Hello World! program.

cargo run --example=minimal --features=crossterm

Minimal

Panic

Demonstrates how to handle panics by ensuring that panic messages are written correctly to the screen. Source: panic.rs.

cargo run --example=panic --features=crossterm

Panic

Paragraph

Demonstrates the Paragraph widget. Source: paragraph.rs

cargo run --example=paragraph --features=crossterm

Paragraph

Popup

Demonstrates how to render a widget over the top of previously rendered widgets using the Clear widget. Source: popup.rs.

cargo run --example=popup --features=crossterm

Popup

A fun example of using half blocks to render graphics Source: ratatui-logo.rs.

cargo run --example=ratatui-logo --features=crossterm

Ratatui Logo

Scrollbar

Demonstrates the Scrollbar widget. Source: scrollbar.rs.

cargo run --example=scrollbar --features=crossterm

Scrollbar

Sparkline

Demonstrates the Sparkline widget. Source: sparkline.rs.

cargo run --example=sparkline --features=crossterm

Sparkline

Table

Demonstrates the Table widget. Source: table.rs.

cargo run --example=table --features=crossterm

Table

Tabs

Demonstrates the Tabs widget. Source: tabs.rs.

cargo run --example=tabs --features=crossterm

Tabs

Tracing

Demonstrates how to use the tracing crate for logging. Creates a file named tracing.log in the current directory.

cargo run --example=tracing --features=crossterm

Tracing

User Input

Demonstrates one approach to accepting user input. Source user_input.rs.

Note

Consider using tui-textarea or tui-input crates for more functional text entry UIs.

cargo run --example=user_input --features=crossterm

User Input

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 repository.