From 7bd8a5624e0f6340af8bb930ee98b3386114705b Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Sat, 15 Mar 2025 19:59:11 -0500 Subject: granular progress indication the code for the cli kinda sucks --- ozone-cli/src/main.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'ozone-cli/src/main.rs') diff --git a/ozone-cli/src/main.rs b/ozone-cli/src/main.rs index dda2c32..05fef49 100644 --- a/ozone-cli/src/main.rs +++ b/ozone-cli/src/main.rs @@ -8,6 +8,7 @@ use std::time::Duration; use log::{error, info, trace}; use clap::Parser; use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; +use indicatif_log_bridge::LogWrapper; use ozone::launcher::{Instance, JavaRuntimeSetting, LaunchProgress, Launcher, ProgressIndication, Settings, ALT_CLIENT_ID, MAIN_CLIENT_ID}; use ozone::launcher::version::{VersionList, VersionResult}; use uuid::Uuid; @@ -156,7 +157,7 @@ fn display_account(account: &Account, selected: bool, verbose: bool) { } } -async fn main_inner(cli: Cli) -> Result> { +async fn main_inner(cli: Cli, multi: MultiProgress) -> Result> { let Some(home) = cli.home.or_else(Launcher::sensible_home) else { error!("Could not choose a launcher home directory. Please choose one with `--home'."); return Ok(ExitCode::FAILURE); // we print our own error message @@ -515,17 +516,18 @@ async fn main_inner(cli: Cli) -> Result> { println!("Preparing the game files..."); let launcher = Launcher::new(&home, !cli.offline).await?; - let multi = MultiProgress::new(); let progress = IndicatifProgress { bar: multi.add(ProgressBar::no_length() .with_style(ProgressStyle::with_template("{spinner} Step {pos} of {len}: {msg}").unwrap())) }; let progress_sub = IndicatifProgress { - bar: multi.add(ProgressBar::no_length()) + bar: multi.add(ProgressBar::no_length() + .with_style(ProgressStyle::with_template("{bar} {pos}/{len}: {msg}").unwrap())) }; progress.bar.enable_steady_tick(Duration::from_millis(100)); + progress_sub.bar.enable_steady_tick(Duration::from_millis(50)); let lp = LaunchProgress::new(&progress as &dyn ProgressIndication, &progress_sub as &dyn ProgressIndication); @@ -541,6 +543,9 @@ async fn main_inner(cli: Cli) -> Result> { info!("ok!"); + progress.bar.finish(); + progress_sub.bar.finish(); + multi.clear().unwrap(); println!("Launching the game!"); ozone::launcher::run_the_game(&launch)?; @@ -553,11 +558,12 @@ async fn main_inner(cli: Cli) -> Result> { #[tokio::main] async fn main() -> ExitCode { // use Warn as the default level to minimize noise on the command line - //simple_logger::SimpleLogger::new().env().init().unwrap(); + let progress = MultiProgress::new(); + LogWrapper::new(progress.clone(), simple_logger::SimpleLogger::new().env()).try_init().unwrap(); let arg = Cli::parse(); - main_inner(arg).await.unwrap_or_else(|e| { + main_inner(arg, progress).await.unwrap_or_else(|e| { error!("Launcher initialization error:"); error!("{e}"); -- cgit v1.2.3-70-g09d2