Skip to content

Install

pito-hourglass is a Rust library for ratatui 0.30 apps. It isn’t on crates.io; add it from its repository, pinned to a release tag.

The same command works on all three, in any shell, from the app’s folder:

Terminal window
cargo add pito-hourglass --git https://github.com/gmrdad82/pito-hourglass --tag v1.0.1
Updating git repository `https://github.com/gmrdad82/pito-hourglass`
Adding pito-hourglass (git) to dependencies

or by hand in Cargo.toml:

[dependencies]
pito-hourglass = { git = "https://github.com/gmrdad82/pito-hourglass", tag = "v1.0.1" }
ratatui = "0.30"

It needs nothing else: no backend, no build script, no system library. Its dependencies (ratatui with no default features, unicode-segmentation and unicode-width) are already in a ratatui app’s graph.

Keep the moment the wait started and draw the widget from the time since:

use std::time::Instant;
use pito_hourglass::Hourglass;
use ratatui::{
Frame,
style::{Color, Modifier, Style},
};
fn draw(frame: &mut Frame, started: Instant) {
let hourglass = Hourglass::new(started.elapsed())
.label("Loading the data...")
.hint(Some("esc stops waiting"))
.glass(Style::new().fg(Color::Yellow))
.accent(Style::new().fg(Color::Magenta))
.muted(Style::new().fg(Color::DarkGray).add_modifier(Modifier::DIM));
frame.render_widget(hourglass, frame.area());
}

Redraw about every 50 ms while it shows; the picture depends only on the elapsed time.

From a clone, the demo draws exactly that, full screen. Esc or q quits:

Terminal window
git clone https://github.com/gmrdad82/pito-hourglass
cd pito-hourglass
cargo run --example demo

The demo: the hourglass drains and flips while “Loading the data…” shimmers under it

Next: show it while data loads.