diff options
| author | 2025-02-28 00:26:39 -0600 | |
|---|---|---|
| committer | 2025-02-28 00:26:39 -0600 | |
| commit | 2dc396e18db3c55cc08dd338fba85268cfb8e47e (patch) | |
| tree | f17ebf0a1da0c1d9b06ae8f610e6fa45fe0c6cf4 | |
| parent | lints (diff) | |
wip: uhh progress attempt
| -rw-r--r-- | ozone-cli/src/main.rs | 4 | ||||
| -rw-r--r-- | ozone/src/util/progress.rs | 47 |
2 files changed, 48 insertions, 3 deletions
diff --git a/ozone-cli/src/main.rs b/ozone-cli/src/main.rs index 9e0cc68..11349c8 100644 --- a/ozone-cli/src/main.rs +++ b/ozone-cli/src/main.rs @@ -233,6 +233,8 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> { eprintln!("No instance selected."); return Ok(ExitCode::FAILURE); }; + + // TODO: maybe delete the files settings.instances.remove(&inst); settings.selected_instance = None; @@ -372,7 +374,7 @@ async fn main_inner(cli: Cli) -> Result<ExitCode, Box<dyn Error>> { let sel_id = accounts.get_selected_account().map(|(id, _)| id); let mut first = true; - for (id, account) in iter { + for (id, account) in iter { // TODO: sort if !first { println!(); } diff --git a/ozone/src/util/progress.rs b/ozone/src/util/progress.rs index 46983c9..33373b7 100644 --- a/ozone/src/util/progress.rs +++ b/ozone/src/util/progress.rs @@ -1,3 +1,46 @@ -struct Progress { - +use std::borrow::Cow; +use std::cmp::min; +use std::sync::Mutex; + +pub trait Progress { + fn set_description(&self, step: Cow<'static, str>); + fn set_progress_full(&self, value: usize, max: usize); + fn set_progress(&self, value: usize); + fn inc_progress(&self, by: usize); +} + +struct StepProgressInner<'p> { + steps_total: usize, + step_current: usize, + progress: &'p dyn Progress +} + +pub struct StepProgress<'p> { + inner: Mutex<StepProgressInner<'p>> +} + +impl<'p> StepProgress<'p> { + pub fn new(steps: usize, progress: &'p dyn Progress) -> Self { + Self { + inner: Mutex::new(StepProgressInner { + steps_total: steps, + step_current: 0usize, + progress + }) + } + } + + pub fn set_step(&self, step: usize, max: usize) { + let mut inner = self.inner.lock().unwrap(); + assert!(step < inner.steps_total); + + inner.step_current = step; + inner.progress.set_progress_full(step * max, inner.steps_total * max); + } + + pub fn inc_step(&self, by: usize, max: usize) { + let mut inner = self.inner.lock().unwrap(); + inner.step_current = min(inner.steps_total, inner.step_current + by); + inner.progress.set_progress_full(inner.step_current * max, inner.steps_total * max); + } } |
