|
|
|
@ -47,7 +47,8 @@ impl std::ops::Drop for Command
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct AsyncProgressCounter
|
|
|
|
|
pub struct AsyncProgressCounter<T>
|
|
|
|
|
where T: termprogress::ProgressBar + WithTitle + std::marker::Send + std::marker::Sync +'static,
|
|
|
|
|
{
|
|
|
|
|
writer: Sender<Command>,
|
|
|
|
|
reader: Receiver<Command>,
|
|
|
|
@ -55,6 +56,8 @@ pub struct AsyncProgressCounter
|
|
|
|
|
|
|
|
|
|
small: u64,
|
|
|
|
|
large: u64,
|
|
|
|
|
|
|
|
|
|
_phantom: std::marker::PhantomData<T>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
@ -226,7 +229,8 @@ impl CommandCallback
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl AsyncProgressCounter
|
|
|
|
|
impl<T> AsyncProgressCounter<T>
|
|
|
|
|
where T: termprogress::ProgressBar + WithTitle + std::marker::Send + std::marker::Sync +'static,
|
|
|
|
|
{
|
|
|
|
|
/// Create a new `AsyncProgressCounter`
|
|
|
|
|
pub fn new(title: impl Into<String>, max: u64) -> Self
|
|
|
|
@ -239,6 +243,8 @@ impl AsyncProgressCounter
|
|
|
|
|
title: title.into(),
|
|
|
|
|
small: 0,
|
|
|
|
|
large: max,
|
|
|
|
|
|
|
|
|
|
_phantom: std::marker::PhantomData,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -257,7 +263,7 @@ impl AsyncProgressCounter
|
|
|
|
|
pub fn host(mut self) -> JoinHandle<()>
|
|
|
|
|
{
|
|
|
|
|
//let mut spin = spinner::Spin::with_title(&self.title[..], Default::default());
|
|
|
|
|
let mut bar = termprogress::progress::Bar::with_title(50, &self.title[..]);
|
|
|
|
|
let mut bar = T::with_title(50, &self.title[..]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bar.update();
|
|
|
|
@ -317,3 +323,54 @@ impl AsyncProgressCounter
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub trait WithTitle: Sized + ProgressBar + Display
|
|
|
|
|
{
|
|
|
|
|
fn with_title(len: usize, string: impl AsRef<str>) -> Self;
|
|
|
|
|
fn update(&mut self);
|
|
|
|
|
fn complete(self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl WithTitle for termprogress::progress::Bar
|
|
|
|
|
{
|
|
|
|
|
fn with_title(len: usize, string: impl AsRef<str>) -> Self
|
|
|
|
|
{
|
|
|
|
|
Self::with_title(len, string)
|
|
|
|
|
}
|
|
|
|
|
fn update(&mut self)
|
|
|
|
|
{
|
|
|
|
|
self.update();
|
|
|
|
|
}
|
|
|
|
|
fn complete(self)
|
|
|
|
|
{
|
|
|
|
|
self.complete();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub struct Silent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl termprogress::Display for Silent
|
|
|
|
|
{
|
|
|
|
|
fn println(&self, _: &str){}
|
|
|
|
|
fn refresh(&self){}
|
|
|
|
|
fn blank(&self){}
|
|
|
|
|
fn get_title(&self) -> &str{""}
|
|
|
|
|
fn set_title(&mut self, _: &str){}
|
|
|
|
|
fn update_dimensions(&mut self, _:usize){}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl termprogress::ProgressBar for Silent
|
|
|
|
|
{
|
|
|
|
|
fn set_progress(&mut self, _:f64){}
|
|
|
|
|
fn get_progress(&self) -> f64{0.0}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl WithTitle for Silent
|
|
|
|
|
{
|
|
|
|
|
fn with_title(_: usize, _: impl AsRef<str>) -> Self{Self}
|
|
|
|
|
fn update(&mut self) {}
|
|
|
|
|
fn complete(self) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|