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/config.rs | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/config.rs') diff --git a/src/config.rs b/src/config.rs index a952d40..54cf768 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,6 +4,7 @@ use std::{ path::Path, }; +use indicatif::{ProgressBar, ProgressStyle}; use serde::{Deserialize, Serialize}; use crate::{db::db_setup, error::MLE, Modloader, VersionLevel, check_game_versions}; @@ -79,9 +80,10 @@ impl Cfg { } fn create_config(path: &str) -> MLE<()> { - print!("No config file found, create default"); - //Force flush of stdout, else print! doesn't print instantly - std::io::stdout().flush()?; + let p = ProgressBar::new(1); + p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); + p.set_message("Create default config"); + let cache_dir = dirs::cache_dir() .unwrap() .join("modlist") @@ -102,37 +104,36 @@ fn create_config(path: &str) -> MLE<()> { create_dir_all(path.split("config.toml").collect::>()[0])?; let mut file = File::create(path)?; file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; - println!(" ✓"); + p.finish_with_message(format!("Created default config ({})", path)); Ok(()) } fn create_database(path: &str) -> MLE<()> { - print!("No database found, create base"); - //Force flush of stdout, else print! doesn't print instantly - std::io::stdout().flush()?; + let p = ProgressBar::new(1); + p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); + p.set_message("Create database"); File::create(path)?; db_setup(path)?; - println!(" ✓"); + p.finish_with_message(format!("Created database ({})", path)); Ok(()) } fn create_cache(path: &str) -> MLE<()> { - print!("No cache direcory found, create one"); - //Force flush of stdout, else print! doesn't print instantly - std::io::stdout().flush()?; + let p = ProgressBar::new(1); + p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); + p.set_message("Create cache"); create_dir_all(path)?; - println!(" ✓"); + p.finish_with_message(format!("Created cache ({})", path)); Ok(()) } async fn create_versions_dummy(path: &str) -> MLE<()> { - print!("No version file found, create dummy"); - //Force flush of stdout, else print! doesn't print instantly - std::io::stdout().flush()?; - + let p = ProgressBar::new(1); + p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap()); + p.set_message("Create version file"); File::create(path)?; - println!(" ✓"); + p.finish_with_message(format!("Created version file ({})", path)); Ok(()) } -- cgit v1.2.3