diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-02-08 13:34:41 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-08 13:34:41 +0000 |
| commit | 8460210202af4e48ea55c997bf2739a6f0570e4a (patch) | |
| tree | b65b7ec55da171d9246be0d2ef77a7e39ecf45cb /atuin-client/src/record | |
| parent | fix(tests): add Settings::utc() for utc settings (#1677) (diff) | |
| download | atuin-8460210202af4e48ea55c997bf2739a6f0570e4a.zip | |
feat: add progress bars to sync and store init (#1684)
Replace lots of logging with some progress bars. This looks much nicer
I'd like to move it out of the atuin-client crate and into the atuin
crate. But first, I want to decouple a lot of the record moving, so it
can wait until that's done.
Diffstat (limited to 'atuin-client/src/record')
| -rw-r--r-- | atuin-client/src/record/sync.rs | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/atuin-client/src/record/sync.rs b/atuin-client/src/record/sync.rs index 6c80b0b8..e3644371 100644 --- a/atuin-client/src/record/sync.rs +++ b/atuin-client/src/record/sync.rs @@ -1,5 +1,5 @@ // do a sync :O -use std::cmp::Ordering; +use std::{cmp::Ordering, fmt::Write}; use eyre::Result; use thiserror::Error; @@ -8,6 +8,7 @@ use super::store::Store; use crate::{api_client::Client, settings::Settings}; use atuin_common::record::{Diff, HostId, RecordId, RecordIdx, RecordStatus}; +use indicatif::{ProgressBar, ProgressState, ProgressStyle}; #[derive(Error, Debug)] pub enum SyncError { @@ -165,6 +166,12 @@ async fn sync_upload( let upload_page_size = 100; let mut progress = 0; + let pb = ProgressBar::new(expected); + pb.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ({eta})") + .unwrap() + .with_key("eta", |state: &ProgressState, w: &mut dyn Write| write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap()) + .progress_chars("#>-")); + println!( "Uploading {} records to {}/{}", expected, @@ -189,12 +196,7 @@ async fn sync_upload( SyncError::RemoteRequestError { msg: e.to_string() } })?; - println!( - "uploaded {} to remote, progress {}/{}", - page.len(), - progress, - expected - ); + pb.set_position(progress); progress += page.len() as u64; if progress >= expected { @@ -202,6 +204,8 @@ async fn sync_upload( } } + pb.finish_with_message("Uploaded records"); + Ok(progress as i64) } @@ -226,6 +230,12 @@ async fn sync_download( tag ); + let pb = ProgressBar::new(expected); + pb.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {human_pos}/{human_len} ({eta})") + .unwrap() + .with_key("eta", |state: &ProgressState, w: &mut dyn Write| write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap()) + .progress_chars("#>-")); + // preload with the first entry if remote does not know of this store loop { let page = client @@ -238,15 +248,9 @@ async fn sync_download( .await .map_err(|e| SyncError::LocalStoreError { msg: e.to_string() })?; - println!( - "downloaded {} records from remote, progress {}/{}", - page.len(), - progress, - expected - ); - ret.extend(page.iter().map(|f| f.id)); + pb.set_position(progress); progress += page.len() as u64; if progress >= expected { @@ -254,6 +258,8 @@ async fn sync_download( } } + pb.finish_with_message("Downloaded records"); + Ok(ret) } |
