diff options
| author | 2025-03-15 19:59:11 -0500 | |
|---|---|---|
| committer | 2025-03-15 19:59:11 -0500 | |
| commit | 7bd8a5624e0f6340af8bb930ee98b3386114705b (patch) | |
| tree | 2c7c7948a43839f4f00f557b4836db2176a352da /ozone-cli | |
| parent | wip: progress (diff) | |
granular progress indication
the code for the cli kinda sucks
Diffstat (limited to 'ozone-cli')
| -rw-r--r-- | ozone-cli/Cargo.toml | 1 | ||||
| -rw-r--r-- | ozone-cli/src/main.rs | 16 |
2 files changed, 12 insertions, 5 deletions
diff --git a/ozone-cli/Cargo.toml b/ozone-cli/Cargo.toml index ad65d92..77d93d0 100644 --- a/ozone-cli/Cargo.toml +++ b/ozone-cli/Cargo.toml @@ -14,3 +14,4 @@ lazy_static = "1.5.0" regex = "1.11.1" uuid = { version = "1.12.1", features = ["v4"] } indicatif = "0.17.11" +indicatif-log-bridge = "0.2.3" 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<ExitCode, Box<dyn Error>> { +async fn main_inner(cli: Cli, multi: MultiProgress) -> Result<ExitCode, Box<dyn Error>> { 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<ExitCode, Box<dyn Error>> { 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<ExitCode, Box<dyn Error>> { 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<ExitCode, Box<dyn Error>> { #[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}"); |
