Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.
/ async-template Public archive

An opinionated "component-based" ratatui template using async crossterm and tokio

License

Notifications You must be signed in to change notification settings

ratatui/async-template

Repository files navigation

async-template

DEPRECATED: Use https://github.com/ratatui-org/templates instead

cargo generate ratatui-org/templates async

Features

  • 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 with Home and Fps components as examples

Usage

You can start by using cargo-generate:

cargo install cargo-generate
cargo generate --git https://github.com/ratatui-org/async-template --name ratatui-hello-world
cd ratatui-hello-world

You can also use a template.toml file to skip the prompts:

$ cargo generate --git https://github.com/ratatui-org/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

Run

cargo run # Press `q` to exit

Show help

$ 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

Show 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

Documentation

Read documentation on design decisions in the template here: https://ratatui-org.github.io/async-template/

Counter + Text Input Demo

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-org/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: