|
|
|
@ -27,9 +27,10 @@ use std::{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mod tasklist;
|
|
|
|
|
pub use tasklist::TaskId;
|
|
|
|
|
|
|
|
|
|
/// Command to send to worker task.
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
pub enum CommandKind
|
|
|
|
|
{
|
|
|
|
|
Line(String),
|
|
|
|
@ -38,6 +39,9 @@ pub enum CommandKind
|
|
|
|
|
Bump(isize),
|
|
|
|
|
BumpHigh(isize),
|
|
|
|
|
|
|
|
|
|
AddTask(String),
|
|
|
|
|
RemoveTask(TaskId),
|
|
|
|
|
|
|
|
|
|
Shutdown,
|
|
|
|
|
|
|
|
|
|
Many(Vec<CommandKind>),
|
|
|
|
@ -219,6 +223,7 @@ pub fn host<B: ProgressBar + Send + Sync + 'static>(bar: B) -> (Handle<B>, JoinH
|
|
|
|
|
};
|
|
|
|
|
(handle, tokio::spawn(async move {
|
|
|
|
|
({
|
|
|
|
|
let mut tasks = tasklist::TaskList::new();
|
|
|
|
|
macro_rules! update_bar {
|
|
|
|
|
(to $state:ident $($tt:tt)*) => {
|
|
|
|
|
{
|
|
|
|
@ -243,6 +248,27 @@ pub fn host<B: ProgressBar + Send + Sync + 'static>(bar: B) -> (Handle<B>, JoinH
|
|
|
|
|
update_bar!($($tt)*);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
(title $($tt:tt)*) => {
|
|
|
|
|
{
|
|
|
|
|
let mut bar = bar.write().await;
|
|
|
|
|
bar.set_title(tasks.as_str());
|
|
|
|
|
update_bar!($($tt)*);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
(+task $task:ident $($tt:tt)*) => {
|
|
|
|
|
{
|
|
|
|
|
let id = tasks.add($task);
|
|
|
|
|
update_bar!($($tt)*);
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
(-task $id:ident $($tt:tt)*) => {
|
|
|
|
|
{
|
|
|
|
|
let res = tasks.remove(&$id);
|
|
|
|
|
update_bar!($($tt)*);
|
|
|
|
|
res
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
() => {};
|
|
|
|
|
}
|
|
|
|
|
while let Some(Command(command, response)) = rx.recv().await {
|
|
|
|
@ -260,13 +286,16 @@ pub fn host<B: ProgressBar + Send + Sync + 'static>(bar: B) -> (Handle<B>, JoinH
|
|
|
|
|
macro_rules! send_response {
|
|
|
|
|
($value:expr) => (send_response!(@ response => Some(Box::new($value))));
|
|
|
|
|
(@ $response:ident => $value:expr) => {
|
|
|
|
|
{
|
|
|
|
|
let value: Response = $value;
|
|
|
|
|
{
|
|
|
|
|
if let Some(response) = $response.lock().unwrap().take() {
|
|
|
|
|
Some(response.send($value))
|
|
|
|
|
Some(response.send(value))
|
|
|
|
|
} else {
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -306,6 +335,13 @@ pub fn host<B: ProgressBar + Send + Sync + 'static>(bar: B) -> (Handle<B>, JoinH
|
|
|
|
|
CommandKind::Line(line) => update_bar!(write line),
|
|
|
|
|
CommandKind::LineErr(line) => update_bar!(write error line),
|
|
|
|
|
|
|
|
|
|
CommandKind::AddTask(string) => {
|
|
|
|
|
send_response!(update_bar!(+task string title));
|
|
|
|
|
},
|
|
|
|
|
CommandKind::RemoveTask(id) => {
|
|
|
|
|
send_response!(update_bar!(-task id title));
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
//TODO: Title
|
|
|
|
|
CommandKind::Many(_) => unimplemented!(),
|
|
|
|
|
}
|
|
|
|
|