From 7f1a262999d7a8b7f12a97daf4b6722638dc62a1 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 25 May 2023 21:06:40 +0200 Subject: more progress instead of print, more references --- src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 69cc650..a7a34ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,8 +12,13 @@ pub use apis::*; use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; pub use commands::*; use error::{ErrorType, MLError, MLE}; +use indicatif::{ProgressStyle, ProgressBar}; use serde::{Deserialize, Serialize}; +pub static STYLE_BAR_POS: &str = "{spinner:.green}{wide_msg}{pos}/{len} [{bar:.green/lime}]"; +pub static STYLE_BAR_BYTE: &str = "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]"; +pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}"; +pub static STYLE_MESSAGE: &str = "{wide_msg}"; pub static PROGRESS_CHARS: &str = "#>-"; #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] @@ -59,15 +64,19 @@ pub enum VersionLevel { /// Checks if update needed (time) /// if yes: get versions, update pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { + let p = ProgressBar::new(1); + p.set_style(ProgressStyle::with_template(STYLE_MESSAGE).unwrap()); + p.set_message("Update minecraft versions"); + let creation_time = fs::metadata(path)?.created()?; if !force && creation_time.elapsed().unwrap() < Duration::from_secs(60 * 60 * 24) { return Ok(()); } - print!("Update minecraft versions"); std::io::stdout().flush()?; let versions = get_game_versions().await; remove_file(path)?; let mut file = File::create(path)?; file.write_all(serde_json::to_string_pretty(&versions)?.as_bytes())?; - println!(" ✓"); + + p.finish_with_message("Updated minecraft versions"); Ok(()) } -- cgit v1.2.3