You can start by using cargo-generate
:
cargo install cargo-generate
cargo generate ratatui/templates component --name ratatui-hello-world
cd ratatui-hello-world
- Uses tokio for async events
- Start and stop key events to shell out to another TUI like vim
- Supports suspend signal hooks
- Logs using tracing
- better-panic
- color-eyre
- human-panic
- Clap for command line argument parsing
Component
trait withHome
andFps
components as examples
You can also use a
template.toml
file to skip the prompts:
$ cargo generate --git https://github.com/ratatui/async-template --template-values-file .github/workflows/template.toml --name ratatui-hello-world
# OR generate from local clone
$ cargo generate --path . --template-values-file .github/workflows/template.toml --name ratatui-hello-world
cargo run # Press `q` to exit
$ cargo run -- --help
Hello World project using ratatui-template
Usage: ratatui-hello-world [OPTIONS]
Options:
-t, --tick-rate <FLOAT> Tick rate, i.e. number of ticks per second [default: 1]
-f, --frame-rate <FLOAT> Frame rate, i.e. number of frames per second [default: 60]
-h, --help Print help
-V, --version Print version
Without direnv variables:
$ cargo run -- --version
Finished dev [unoptimized debuginfo] target(s) in 0.07s
Running `target/debug/ratatui-hello-world --version`
ratatui-hello-world v0.1.0-47-eb0a31a
Authors: Dheepak Krishnamurthy
Config directory: /Users/kd/Library/Application Support/com.kdheepak.ratatui-hello-world
Data directory: /Users/kd/Library/Application Support/com.kdheepak.ratatui-hello-world
With direnv variables:
$ direnv allow
direnv: loading ~/gitrepos/async-template/ratatui-hello-world/.envrc
direnv: export RATATUI_HELLO_WORLD_CONFIG RATATUI_HELLO_WORLD_DATA RATATUI_HELLO_WORLD_LOG_LEVEL
$ # OR
$ export RATATUI_HELLO_WORLD_CONFIG=`pwd`/.config
$ export RATATUI_HELLO_WORLD_DATA=`pwd`/.data
$ export RATATUI_HELLO_WORLD_LOG_LEVEL=debug
$ cargo run -- --version
Finished dev [unoptimized debuginfo] target(s) in 0.07s
Running `target/debug/ratatui-hello-world --version`
ratatui-hello-world v0.1.0-47-eb0a31a
Authors: Dheepak Krishnamurthy
Config directory: /Users/kd/gitrepos/async-template/ratatui-hello-world/.config
Data directory: /Users/kd/gitrepos/async-template/ratatui-hello-world/.data
Read documentation on design decisions in the template here: https://ratatui.github.io/async-template/
This repo contains a ratatui-counter
folder that is a working demo as an example. If you wish to
run a demo without using cargo generate
, you can run the counter text input demo by following
the instructions below:
git clone https://github.com/ratatui/async-template
cd async-template
cd ratatui-counter # counter text input demo
export RATATUI_COUNTER_CONFIG=`pwd`/.config
export RATATUI_COUNTER_DATA=`pwd`/.data
export RATATUI_COUNTER_LOG_LEVEL=debug
# OR
direnv allow
cargo run
You should see a demo like this: