summaryrefslogtreecommitdiffstats
path: root/ozone-cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'ozone-cli/src')
-rw-r--r--ozone-cli/src/main.rs80
1 files changed, 73 insertions, 7 deletions
diff --git a/ozone-cli/src/main.rs b/ozone-cli/src/main.rs
index 11349c8..dda2c32 100644
--- a/ozone-cli/src/main.rs
+++ b/ozone-cli/src/main.rs
@@ -1,11 +1,14 @@
mod cli;
+use std::borrow::Cow;
use std::error::Error;
use std::path::Path;
use std::process::ExitCode;
+use std::time::Duration;
use log::{error, info, trace};
use clap::Parser;
-use ozone::launcher::{Instance, JavaRuntimeSetting, Launcher, Settings, ALT_CLIENT_ID, MAIN_CLIENT_ID};
+use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
+use ozone::launcher::{Instance, JavaRuntimeSetting, LaunchProgress, Launcher, ProgressIndication, Settings, ALT_CLIENT_ID, MAIN_CLIENT_ID};
use ozone::launcher::version::{VersionList, VersionResult};
use uuid::Uuid;
use ozone::auth::{Account, AccountStorage, MsaAccount};
@@ -14,6 +17,51 @@ use crate::cli::{AccountCommand, Cli, InstanceCommand, ProfileSelectArgs, RootCo
const ACCOUNT_DB_PATH: &str = "ozone_accounts.json";
+struct IndicatifProgress {
+ bar: ProgressBar
+}
+
+impl ProgressIndication for IndicatifProgress {
+ fn set_progress(&self, progress: usize) {
+ self.bar.set_position(progress as u64);
+ }
+
+ fn set_max(&self, max: usize) {
+ self.bar.set_length(max as u64);
+ }
+
+ fn set_all(&self, progress: usize, max: usize) {
+ self.bar.update(|s| {
+ s.set_pos(progress as u64);
+ s.set_len(max as u64);
+ });
+ }
+
+ fn inc_progress(&self, by: usize) {
+ self.bar.inc(by as u64);
+ }
+
+ fn inc_max(&self, by: usize) {
+ self.bar.inc_length(by as u64);
+ }
+
+ fn dec_progress(&self, by: usize) {
+ self.bar.dec(by as u64);
+ }
+
+ fn dec_max(&self, by: usize) {
+ self.bar.dec_length(by as u64);
+ }
+
+ fn set_text(&self, text: Cow<'static, str>) {
+ self.bar.set_message(text);
+ }
+
+ fn complete(&self, message: Cow<'static, str>) {
+ self.bar.finish_with_message(message);
+ }
+}
+
fn find_account<'a>(auth: &'a AccountStorage, input: &ProfileSelectArgs) -> Result<Vec<(&'a String, &'a Account)>, ()> {
if let Some(uuid) = input.uuid {
Ok(auth.iter_accounts().filter(|(_, a)| match *a {
@@ -467,12 +515,30 @@ 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 launch = launcher.prepare_launch(inst, Settings::get_instance_path(selection), settings.client_id, account, args.demo).await.map_err(|e| {
- error!("error launching: {e}");
- e
- })?;
+ 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())
+ };
+
+ progress.bar.enable_steady_tick(Duration::from_millis(100));
+
+ let lp = LaunchProgress::new(&progress as &dyn ProgressIndication, &progress_sub as &dyn ProgressIndication);
+
+ let launch = launcher.prepare_launch(inst,
+ Settings::get_instance_path(selection),
+ settings.client_id,
+ account,
+ args.demo,
+ lp)
+ .await.inspect_err(|e| {
+ error!("error launching: {e}");
+ })?;
- dbg!(&launch);
info!("ok!");
println!("Launching the game!");
@@ -487,7 +553,7 @@ 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();
+ //simple_logger::SimpleLogger::new().env().init().unwrap();
let arg = Cli::parse();