From caa6eed7832bca762dd45a85d9d73c55df2bc99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20K=C3=A4nner?= Date: Thu, 24 Apr 2025 21:22:04 +0200 Subject: [PATCH] improve progress bar --- Cargo.lock | 26 ++++++++++++++++++++++++++ xtask/Cargo.toml | 1 + xtask/src/main.rs | 23 +++++++++++++++++++---- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 10ffd0a..ecafd0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -298,6 +298,16 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[package]] +name = "colored" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" +dependencies = [ + "lazy_static", + "windows-sys 0.59.0", +] + [[package]] name = "cpufeatures" version = "0.2.17" @@ -759,6 +769,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.172" @@ -1076,6 +1092,15 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +[[package]] +name = "rich_progress_bar" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "892eca205ea9663141375f828ed5cfc1adbe70b25283ccec0b2f264d7059cb06" +dependencies = [ + "colored", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -1623,6 +1648,7 @@ name = "xtask" version = "0.1.0" dependencies = [ "rayon", + "rich_progress_bar", ] [[package]] diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 13f867f..d991332 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -5,3 +5,4 @@ edition = "2024" [dependencies] rayon = "1.10" +rich_progress_bar = "1.1" diff --git a/xtask/src/main.rs b/xtask/src/main.rs index c8fdcec..e304c55 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -4,11 +4,13 @@ use std::{ net::TcpStream, path::{Path, PathBuf}, process::{Child, Command, Stdio}, + sync::{Mutex, atomic::AtomicUsize}, thread::sleep, time::Duration, }; use rayon::iter::{IntoParallelIterator, ParallelIterator}; +use rich_progress_bar::{Colors, RichProgressBar}; type DynError = Box; @@ -232,6 +234,8 @@ fn regression() -> Result<(), DynError> { } }; + sleep(Duration::from_secs(1)); + let res = try_regression(); snake.kill().and(prod.kill())?; @@ -265,18 +269,25 @@ fn try_regression() -> Result<(usize, usize, usize), DynError> { .build_global() .unwrap(); + let mut progress = RichProgressBar::new(); + progress + .set_progress_character('=') + .set_color(Colors::BrightCyan) + .set_total(GAMES as u64); + let progress = Mutex::new(&mut progress); let stats = (0..GAMES) .into_par_iter() .flat_map(|_| { - eprint!("."); let game = Command::new("./battlesnake-cli") .current_dir(project_root()) .args([ "play", - "-W", + "--width", "11", - "-H", + "--height", "11", + "--timeout", + "100", "--name", "local", "--url", @@ -290,7 +301,7 @@ fn try_regression() -> Result<(usize, usize, usize), DynError> { ]) .output() .ok()?; - if !game.status.success() { + let res = if !game.status.success() { eprintln!("game output: {}", String::from_utf8(game.stderr).ok()?); eprintln!("game status: {}", game.status); None @@ -308,7 +319,11 @@ fn try_regression() -> Result<(usize, usize, usize), DynError> { } else { Some((0, 1, 0)) } + }; + if let Ok(mut progress) = progress.lock() { + let _ = progress.inc(); } + res }) .reduce( || (0, 0, 0),