|
|
@ -41,7 +41,10 @@ pub enum CommandKind
|
|
|
|
|
|
|
|
|
|
|
|
Bump(isize),
|
|
|
|
Bump(isize),
|
|
|
|
BumpHigh(isize),
|
|
|
|
BumpHigh(isize),
|
|
|
|
|
|
|
|
Set{low: Option<usize>, high: Option<usize>},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Refresh,
|
|
|
|
|
|
|
|
|
|
|
|
/// Add a task to the tasklist
|
|
|
|
/// Add a task to the tasklist
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// # Response
|
|
|
|
/// # Response
|
|
|
@ -58,6 +61,7 @@ pub enum CommandKind
|
|
|
|
Many(Vec<CommandKind>),
|
|
|
|
Many(Vec<CommandKind>),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// The type sent in response to a `Command`.
|
|
|
|
pub type Response = Option<Box<dyn std::any::Any + Send+ Sync + 'static>>;
|
|
|
|
pub type Response = Option<Box<dyn std::any::Any + Send+ Sync + 'static>>;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
@ -131,7 +135,7 @@ impl State
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// A handle to a running async progress bar
|
|
|
|
/// A handle to a running async progress bar
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Handle<B = Bar>
|
|
|
|
pub struct Handle<B = Bar>
|
|
|
|
where B: ProgressBar,
|
|
|
|
where B: ProgressBar,
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -145,6 +149,19 @@ where B: ProgressBar,
|
|
|
|
dead: watch::Receiver<bool>,
|
|
|
|
dead: watch::Receiver<bool>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl<B: ProgressBar> Clone for Handle<B>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fn clone(&self)->Self
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Self {
|
|
|
|
|
|
|
|
chan: self.chan.clone(),
|
|
|
|
|
|
|
|
bar: self.bar.clone(),
|
|
|
|
|
|
|
|
state: self.state.clone(),
|
|
|
|
|
|
|
|
dead: self.dead.clone(),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<B: ProgressBar> Handle<B>
|
|
|
|
impl<B: ProgressBar> Handle<B>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/// Is the worker alive?
|
|
|
|
/// Is the worker alive?
|
|
|
@ -235,7 +252,7 @@ impl fmt::Display for WorkerCommError
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Host a progress bar detached
|
|
|
|
/// Host a progress bar and detach it
|
|
|
|
pub fn host<B: ProgressBar + Send + Sync + 'static>(bar: B) -> (Handle<B>, JoinHandle<B>)
|
|
|
|
pub fn host<B: ProgressBar + Send + Sync + 'static>(bar: B) -> (Handle<B>, JoinHandle<B>)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let state = Arc::new(RwLock::new(Default::default()));
|
|
|
|
let state = Arc::new(RwLock::new(Default::default()));
|
|
|
@ -255,6 +272,13 @@ pub fn host<B: ProgressBar + Send + Sync + 'static>(bar: B) -> (Handle<B>, JoinH
|
|
|
|
({
|
|
|
|
({
|
|
|
|
let mut tasks = tasklist::TaskList::new();
|
|
|
|
let mut tasks = tasklist::TaskList::new();
|
|
|
|
macro_rules! update_bar {
|
|
|
|
macro_rules! update_bar {
|
|
|
|
|
|
|
|
(refresh $($tt:tt)*) => {
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let bar = bar.read().await;
|
|
|
|
|
|
|
|
bar.refresh();
|
|
|
|
|
|
|
|
update_bar!($($tt)*);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
(to $state:ident $($tt:tt)*) => {
|
|
|
|
(to $state:ident $($tt:tt)*) => {
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let mut bar = bar.write().await;
|
|
|
|
let mut bar = bar.write().await;
|
|
|
@ -301,6 +325,8 @@ pub fn host<B: ProgressBar + Send + Sync + 'static>(bar: B) -> (Handle<B>, JoinH
|
|
|
|
};
|
|
|
|
};
|
|
|
|
() => {};
|
|
|
|
() => {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
update_bar!(refresh);
|
|
|
|
while let Some(Command(command, response)) = rx.recv().await {
|
|
|
|
while let Some(Command(command, response)) = rx.recv().await {
|
|
|
|
let response = Arc::new(std::sync::Mutex::new(Some(response)));
|
|
|
|
let response = Arc::new(std::sync::Mutex::new(Some(response)));
|
|
|
|
|
|
|
|
|
|
|
@ -362,6 +388,14 @@ pub fn host<B: ProgressBar + Send + Sync + 'static>(bar: B) -> (Handle<B>, JoinH
|
|
|
|
|
|
|
|
|
|
|
|
update_bar!(to state);
|
|
|
|
update_bar!(to state);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
CommandKind::Set{low: None, high: None} => (),
|
|
|
|
|
|
|
|
CommandKind::Set{low, high} => {
|
|
|
|
|
|
|
|
let mut state = state.write().await;
|
|
|
|
|
|
|
|
state.cur = low.unwrap_or(state.cur);
|
|
|
|
|
|
|
|
state.max = high.unwrap_or(state.max);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
update_bar!(to state);
|
|
|
|
|
|
|
|
},
|
|
|
|
CommandKind::Line(line) => update_bar!(write line),
|
|
|
|
CommandKind::Line(line) => update_bar!(write line),
|
|
|
|
CommandKind::LineErr(line) => update_bar!(write error line),
|
|
|
|
CommandKind::LineErr(line) => update_bar!(write error line),
|
|
|
|
|
|
|
|
|
|
|
@ -371,8 +405,7 @@ pub fn host<B: ProgressBar + Send + Sync + 'static>(bar: B) -> (Handle<B>, JoinH
|
|
|
|
CommandKind::RemoveTask(id) => {
|
|
|
|
CommandKind::RemoveTask(id) => {
|
|
|
|
send_response!(update_bar!(-task id title));
|
|
|
|
send_response!(update_bar!(-task id title));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
CommandKind::Refresh => update_bar!(refresh),
|
|
|
|
//TODO: Title
|
|
|
|
|
|
|
|
CommandKind::Many(_) => unimplemented!(),
|
|
|
|
CommandKind::Many(_) => unimplemented!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|