use std::fs::File;
use std::io::copy;
use indicatif::{ProgressBar, ProgressStyle};
pub fn strip_sketch_extension(file_name: &str) -> &str {
if file_name.ends_with(".skm") || file_name.ends_with(".skd") || file_name.ends_with(".ski") {
&file_name[..file_name.len() - 4]
} else {
file_name
}
}
pub fn save_sketch_data(
db1_prefix: &str,
db2_prefix: &str,
str_output: &str,
) -> Result<(), anyhow::Error> {
let mut output_file = File::create(format!("{str_output}.skd"))?;
let mut db_sketch1 = File::open(format!("{db1_prefix}.skd"))?;
copy(&mut db_sketch1, &mut output_file)?;
let mut db_sketch2 = File::open(format!("{db2_prefix}.skd"))?;
copy(&mut db_sketch2, &mut output_file)?;
Ok(())
}
pub fn get_progress_bar(length: usize, percent: bool, quiet: bool) -> ProgressBar {
if quiet {
ProgressBar::hidden()
} else {
let style = if percent {
ProgressStyle::with_template("{percent}% {bar:80.cyan/blue} eta:{eta}").unwrap()
} else {
ProgressStyle::with_template("{human_pos}/{human_len} {bar:80.cyan/blue} eta:{eta}")
.unwrap()
};
ProgressBar::new(length as u64).with_style(style)
}
}