Skip to content

Commit

Permalink
polish loading animation
Browse files Browse the repository at this point in the history
  • Loading branch information
deepu105 committed Jan 15, 2024
1 parent 9bbe7c7 commit bb499a2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use rand::Rng;
mod help;
mod overview;
pub mod resource_tabs;
Expand Down Expand Up @@ -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)
);
Expand All @@ -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 {
""
}
Expand Down

0 comments on commit bb499a2

Please sign in to comment.