Added progress bar styling
This commit is contained in:
parent
cf9d6aa7e6
commit
efe77b97d8
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -618,7 +618,7 @@ checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286"
|
||||
[[package]]
|
||||
name = "hpk"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk.git#3d0151610d80f5453248ebd8e7e73f7cefd0fc13"
|
||||
source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk.git#0a94691685433b64c2a7acc2d11094a783297b00"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"deku",
|
||||
@ -1358,7 +1358,7 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
|
||||
[[package]]
|
||||
name = "tar"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk.git#3d0151610d80f5453248ebd8e7e73f7cefd0fc13"
|
||||
source = "git+https://git.hitchhiker-linux.org/jeang3nie/hpk.git#0a94691685433b64c2a7acc2d11094a783297b00"
|
||||
dependencies = [
|
||||
"deku",
|
||||
"libc",
|
||||
|
37
src/hpk.rs
37
src/hpk.rs
@ -1,19 +1,18 @@
|
||||
use std::io::ErrorKind;
|
||||
|
||||
#![warn(clippy::all, clippy::pedantic)]
|
||||
use {
|
||||
clap::ArgMatches,
|
||||
hpk::{Creator, Dependency, Message, Specs, Version},
|
||||
hpk_cli::cli,
|
||||
indicatif::ProgressBar,
|
||||
indicatif::{ProgressBar, ProgressStyle},
|
||||
ron::ser::{to_writer_pretty, PrettyConfig},
|
||||
std::{
|
||||
env,
|
||||
error::Error,
|
||||
ffi::OsStr,
|
||||
fs::File,
|
||||
io::{self, BufWriter},
|
||||
io::{self, BufWriter, ErrorKind},
|
||||
path::PathBuf,
|
||||
sync::{mpsc, Mutex},
|
||||
sync::mpsc,
|
||||
thread,
|
||||
},
|
||||
};
|
||||
@ -67,19 +66,30 @@ fn create(matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
specs.dependencies.push(d);
|
||||
}
|
||||
}
|
||||
let creator = Creator::new(&dir, specs)?;
|
||||
let creator = Creator::new(&dir, specs.clone())?;
|
||||
let (sender, receiver) = mpsc::channel();
|
||||
let len = creator.len();
|
||||
let pb = Mutex::new(ProgressBar::new(len as u64));
|
||||
let pb = ProgressBar::new(len as u64);
|
||||
pb.set_style(
|
||||
ProgressStyle::with_template("[ {prefix} ] {wide_bar}{pos:>5.cyan}/{len:5.green}{msg:>30}")
|
||||
.unwrap(),
|
||||
);
|
||||
pb.set_prefix("Adding files");
|
||||
pb.println(format!(
|
||||
"Creating package {}-{}_{}.tar.zst",
|
||||
&specs.name, &specs.version, &specs.release
|
||||
));
|
||||
let handle = thread::spawn(move || {
|
||||
for msg in receiver.iter() {
|
||||
match msg {
|
||||
Message::MemberAdded(_s) => pb.lock().unwrap().inc(1),
|
||||
Message::Success(_s) => {
|
||||
let pb = pb.lock().unwrap();
|
||||
Message::MemberAdded(s) => {
|
||||
pb.set_message(s.split('/').last().unwrap().to_string());
|
||||
pb.inc(1);
|
||||
pb.finish_with_message("done");
|
||||
},
|
||||
Message::Success(_s) => {
|
||||
pb.inc(1);
|
||||
pb.finish_and_clear();
|
||||
}
|
||||
Message::Failure(s) => {
|
||||
eprint!("{s}");
|
||||
return Err(io::Error::new(io::ErrorKind::Other, s));
|
||||
@ -90,7 +100,10 @@ fn create(matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||
});
|
||||
creator.create(&outdir, sender)?;
|
||||
match handle.join() {
|
||||
Ok(_) => Ok(()),
|
||||
Ok(_) => {
|
||||
println!("Package created successfully");
|
||||
Ok(())
|
||||
},
|
||||
Err(e) => Err(io::Error::new(ErrorKind::Other, format!("{e:?}")).into()),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user