diff --git a/src/appstate.rs b/src/appstate.rs index 8ce7180..955ea02 100644 --- a/src/appstate.rs +++ b/src/appstate.rs @@ -72,8 +72,8 @@ impl AppState { .with_style( ProgressStyle::with_template(&format!( concat!( - "{{msg:.yellow}}: {{bar:50.cyan/blue}} ", - "{{binary_bytes:.magenta}}{}{{binary_total_bytes:.magenta}} ", + "{{bar:50.cyan/blue}} {{msg:.magenta}}: ", + "{{binary_bytes:.yellow}}{}{{binary_total_bytes:.yellow}} ", "({{eta}})", ), style("/").magenta(), diff --git a/src/cachefile.rs b/src/cachefile.rs index 164f4ec..8a676b3 100644 --- a/src/cachefile.rs +++ b/src/cachefile.rs @@ -108,7 +108,8 @@ impl CacheFile { let endpoint = self .uri .endpoint(format!("alias/upload/{}/files/tus", self.share_id)); - Some(state.start_upload(http, &endpoint, &self.alias_id).unwrap()) // HACK unwrap, somehow retry + // TODO somehow retry + Some(state.start_upload(http, &endpoint, &self.alias_id).unwrap()) // HACK unwrap } else { None } diff --git a/src/main.rs b/src/main.rs index 4f62808..df2856e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,13 +14,39 @@ use std::{ use clap::Parser; use console::style; -use dialoguer::{Confirm, theme::ColorfulTheme}; +use dialoguer::{Select, theme::ColorfulTheme}; use log::{error, info, trace}; use appstate::AppState; use cli::Cli; use sharry::ClientError; +fn prompt_continue() -> bool { + let prompt = format!( + "This operation has previously been stopped. {}", + style("How to proceed?").cyan() + ); + + let choices = [ + format!("Load and {}", style("continue operation").green().bold()), + format!("Start a {}", style("new operation").cyan().bold()), + format!("Quit {}", style("ShrUpl").yellow().bold()), + ]; + + let selection = Select::with_theme(&ColorfulTheme::default()) + .with_prompt(prompt) + .default(0) + .items(&choices) + .interact() + .unwrap_or(2); + + if selection == 2 { + process::exit(255); + } + + selection == 0 +} + fn print_error(e: &ClientError) { if let Some(cause) = match e { // known errors @@ -77,13 +103,7 @@ fn main() { info!("args: {args:?}"); let mut state = AppState::try_resume(&args) - .and_then(|state| { - Confirm::with_theme(&ColorfulTheme::default()) - .with_prompt("Continue previously stopped operation?") - .default(true) - .interact() - .map_or(None, |b| b.then_some(state)) - }) + .and_then(|state| prompt_continue().then_some(state)) .unwrap_or_else(|| { check_ctrlc(); @@ -107,10 +127,16 @@ fn main() { info!("continuing with state: {state:?}"); + let fns_magenta = state + .file_names() + .iter() + .map(|&n| style(n).magenta().to_string()) + .collect::>() + .join(", "); + println!( - "{} uploading: {}", + "{} is uploading: {fns_magenta}", style("ShrUpl").yellow().bold(), - style(state.file_names().join(", ")).magenta(), ); let mut buffer = vec![0; args.chunk_size * 1024 * 1024]; @@ -118,7 +144,7 @@ fn main() { loop { match state.upload_chunk(&mut buffer) { Err(e) => { - // HACK handle errors better (this will just retry endlessly) + // TODO better error handling (this will just retry endlessly) error!("error: {e:?}"); if let Some(s) = state.rewind() {