Skip to content

Commit

Permalink
feat(cli): Add information to progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
emmyoh committed Apr 30, 2024
1 parent 5ad3ea7 commit 004cd9a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ space = "0.17.0"
lz4_flex = { version = "0.11.3", default-features = false, features = ["frame"] }
ticky = { version = "1.0.2", optional = true }
pretty-duration = { version = "0.1.1", optional = true }
indicatif = { version = "0.17.8", optional = true }
indicatif = { version = "0.17.8", optional = true, features = ["rayon", "improved_unicode"] }
distances = "1.6.3"
candle-examples = "0.4.1"
candle-core = "0.4.1"
Expand Down
20 changes: 14 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::{command, Parser, Subcommand};
use fastembed::TextEmbedding;
use indicatif::ProgressStyle;
use indicatif::{ProgressBar, ProgressDrawTarget};
use pretty_duration::pretty_duration;
use rodio::{Decoder, OutputStream, Sink};
Expand Down Expand Up @@ -138,8 +139,9 @@ fn main() -> Result<(), Box<dyn Error>> {
let progress_bar = ProgressBar::with_draw_target(
Some(num_texts.try_into()?),
ProgressDrawTarget::hidden(),
)
.with_message(format!("Inserting texts from {} file(s).", num_texts));
);
// .with_message(format!("Inserting texts from {} file(s).", num_texts));
progress_bar.set_style(progress_bar_style()?);
let mut i = 0;
let mut texts = Vec::new();
// Insert texts in batches of INSERT_BATCH_SIZE.
Expand Down Expand Up @@ -228,8 +230,9 @@ fn main() -> Result<(), Box<dyn Error>> {
let progress_bar = ProgressBar::with_draw_target(
Some(num_images.try_into()?),
ProgressDrawTarget::hidden(),
)
.with_message(format!("Inserting images from {} file(s).", num_images));
);
// .with_message(format!("Inserting images from {} file(s).", num_images));
progress_bar.set_style(progress_bar_style()?);
let images: Vec<String> = file_paths
.into_iter()
.map(|x| x.to_str().unwrap().to_string())
Expand Down Expand Up @@ -316,8 +319,9 @@ fn main() -> Result<(), Box<dyn Error>> {
let progress_bar = ProgressBar::with_draw_target(
Some(num_sounds.try_into()?),
ProgressDrawTarget::hidden(),
)
.with_message(format!("Inserting sounds from {} file(s).", num_sounds));
);
// .with_message(format!("Inserting sounds from {} file(s).", num_sounds));
progress_bar.set_style(progress_bar_style()?);
let sounds: Vec<String> = file_paths
.into_iter()
.map(|x| x.to_str().unwrap().to_string())
Expand Down Expand Up @@ -391,3 +395,7 @@ fn main() -> Result<(), Box<dyn Error>> {
}
Ok(())
}

fn progress_bar_style() -> Result<ProgressStyle, Box<dyn Error>> {
Ok(ProgressStyle::with_template("[{elapsed} elapsed, {eta} remaining ({duration} total)] {wide_bar:.cyan/blue} {human_pos} of {human_len} ({percent}%) {msg}")?)
}

0 comments on commit 004cd9a

Please sign in to comment.