From bb499a2ca811a442c574ac9cd00b27955f935c66 Mon Sep 17 00:00:00 2001 From: Deepu Date: Mon, 15 Jan 2024 15:12:45 +0100 Subject: [PATCH] polish loading animation --- Cargo.lock | 37 +++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + Makefile | 2 +- src/ui/mod.rs | 8 ++++++-- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e9603b9..86c188d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -910,6 +910,7 @@ dependencies = [ "kubectl-view-allocations", "openssl", "openssl-probe", + "rand", "ratatui", "regex", "serde", @@ -1423,6 +1424,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + [[package]] name = "proc-macro2" version = "1.0.76" @@ -1450,6 +1457,36 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + [[package]] name = "ratatui" version = "0.25.0" diff --git a/Cargo.toml b/Cargo.toml index 4c00b61..c9198d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,6 +61,7 @@ human-panic = "1.1" kubectl-view-allocations = { version = "0.18.1", default-features = false } async-trait = "0.1.73" glob-match = "0.2.1" +rand = "0.8" # XCB is a PITA to compile for ARM so disabling the copy feature on ARM for now [target.'cfg(target_arch = "x86_64")'.dependencies] diff --git a/Makefile b/Makefile index 0d36d51..3c6854a 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ default: run ## Run all tests test: - @cargo test + @make lint && cargo test ## Run all tests with coverage- `cargo install cargo-tarpaulin` test-cov: diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 3518369..9ed1df5 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -1,3 +1,4 @@ +use rand::Rng; mod help; mod overview; pub mod resource_tabs; @@ -85,7 +86,7 @@ fn draw_app_title(f: &mut Frame<'_>, app: &App, area: Rect) { f.render_widget(title, area); let text = format!( - "v{} with ♥ in Rust {}", + "v{} with ♥ in Rust {} ", env!("CARGO_PKG_VERSION"), nw_loading_indicator(app.is_loading) ); @@ -97,9 +98,12 @@ fn draw_app_title(f: &mut Frame<'_>, app: &App, area: Rect) { f.render_widget(meta, area); } +// loading animation frames +const FRAMES: &[&str] = &["⠋⠴", "⠦⠙", "⠏⠼", "⠧⠹", "⠯⠽"]; + fn nw_loading_indicator<'a>(loading: bool) -> &'a str { if loading { - "..." + FRAMES[rand::thread_rng().gen_range(0..FRAMES.len())] } else { "" }