From 8460210202af4e48ea55c997bf2739a6f0570e4a Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Thu, 8 Feb 2024 13:34:41 +0000 Subject: 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. --- atuin-client/src/history/store.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'atuin-client/src/history') diff --git a/atuin-client/src/history/store.rs b/atuin-client/src/history/store.rs index 08c55c51..4a4cb1ab 100644 --- a/atuin-client/src/history/store.rs +++ b/atuin-client/src/history/store.rs @@ -1,6 +1,7 @@ -use std::collections::HashSet; +use std::{collections::HashSet, fmt::Write}; use eyre::{bail, eyre, Result}; +use indicatif::{ProgressBar, ProgressState, ProgressStyle}; use rmp::decode::Bytes; use crate::{ @@ -263,11 +264,17 @@ impl HistoryStore { println!("Fetching history already in store"); let store_ids = self.history_ids().await?; + let pb = ProgressBar::new(history.len() as u64); + 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("#>-")); + for i in history { - println!("loaded {}", i.id); + debug!("loaded {}", i.id); if store_ids.contains(&i.id) { - println!("skipping {} - already exists", i.id); + debug!("skipping {} - already exists", i.id); continue; } @@ -277,8 +284,12 @@ impl HistoryStore { } else { self.push(i).await?; } + + pb.inc(1); } + pb.finish_with_message("Import complete"); + Ok(()) } } -- cgit v1.3.1