|
|
@ -14,7 +14,10 @@ use std::{
|
|
|
|
Poll,
|
|
|
|
Poll,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
pin::Pin,
|
|
|
|
pin::Pin,
|
|
|
|
|
|
|
|
iter::{
|
|
|
|
|
|
|
|
self,
|
|
|
|
|
|
|
|
Once,
|
|
|
|
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use tokio::{
|
|
|
|
use tokio::{
|
|
|
|
sync::{
|
|
|
|
sync::{
|
|
|
@ -58,6 +61,8 @@ enum CommandKind
|
|
|
|
RemoveTask(usize),
|
|
|
|
RemoveTask(usize),
|
|
|
|
|
|
|
|
|
|
|
|
Complete,
|
|
|
|
Complete,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Many(Vec<CommandKind>),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
#[derive(Debug)]
|
|
|
@ -268,40 +273,63 @@ pub fn create_progress<P: ProgressBar + WithTitle + Send + 'static,
|
|
|
|
(comm, d)
|
|
|
|
(comm, d)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Match the command
|
|
|
|
enum MaybeSingle
|
|
|
|
match command {
|
|
|
|
{
|
|
|
|
CommandKind::BumpHigh(high) => {
|
|
|
|
Single(Once<CommandKind>),
|
|
|
|
let stat = stat.to_mut();
|
|
|
|
Many(Vec<CommandKind>),
|
|
|
|
stat.high+=high;
|
|
|
|
}
|
|
|
|
progress.set_progress(stat.get_pct());
|
|
|
|
|
|
|
|
},
|
|
|
|
impl From<CommandKind> for MaybeSingle
|
|
|
|
CommandKind::BumpLow(low) => {
|
|
|
|
{
|
|
|
|
let stat = stat.to_mut();
|
|
|
|
fn from(from: CommandKind) -> Self
|
|
|
|
stat.low+=low;
|
|
|
|
{
|
|
|
|
progress.set_progress(stat.get_pct());
|
|
|
|
match from {
|
|
|
|
},
|
|
|
|
CommandKind::Many(many) => Self::Many(many),
|
|
|
|
CommandKind::PrintLine(line) => {
|
|
|
|
x => Self::Single(iter::once(x)),
|
|
|
|
progress.println(&line[..]);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
CommandKind::PrintLineErr(line) => {
|
|
|
|
|
|
|
|
progress.eprintln(&line[..]);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
CommandKind::AddTask(task) => {
|
|
|
|
|
|
|
|
let idx = list.push(task.name);
|
|
|
|
|
|
|
|
if let Err(_) = task.idx.send(idx) {
|
|
|
|
|
|
|
|
list.pop(idx);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
progress.set_title(list.as_ref());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
CommandKind::RemoveTask(task) => {
|
|
|
|
|
|
|
|
if list.pop(task) {
|
|
|
|
|
|
|
|
progress.set_title(list.as_ref());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
CommandKind::Complete => {
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
},
|
|
|
|
//TODO: IntoIterator for Maybesingle??? We'll need our own type, I think. Maybe generalise it, and put in ext or util?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let command = MaybeSingle::from(command);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Match the command
|
|
|
|
|
|
|
|
for command in command.into_iter() {
|
|
|
|
|
|
|
|
match command {
|
|
|
|
|
|
|
|
CommandKind::BumpHigh(high) => {
|
|
|
|
|
|
|
|
let stat = stat.to_mut();
|
|
|
|
|
|
|
|
stat.high+=high;
|
|
|
|
|
|
|
|
progress.set_progress(stat.get_pct());
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
CommandKind::BumpLow(low) => {
|
|
|
|
|
|
|
|
let stat = stat.to_mut();
|
|
|
|
|
|
|
|
stat.low+=low;
|
|
|
|
|
|
|
|
progress.set_progress(stat.get_pct());
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
CommandKind::PrintLine(line) => {
|
|
|
|
|
|
|
|
progress.println(&line[..]);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
CommandKind::PrintLineErr(line) => {
|
|
|
|
|
|
|
|
progress.eprintln(&line[..]);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
CommandKind::AddTask(task) => {
|
|
|
|
|
|
|
|
let idx = list.push(task.name);
|
|
|
|
|
|
|
|
if let Err(_) = task.idx.send(idx) {
|
|
|
|
|
|
|
|
list.pop(idx);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
progress.set_title(list.as_ref());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
CommandKind::RemoveTask(task) => {
|
|
|
|
|
|
|
|
if list.pop(task) {
|
|
|
|
|
|
|
|
progress.set_title(list.as_ref());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
CommandKind::Complete => {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if let Cow::Owned(stat) = std::mem::replace(&mut stat, Cow::Borrowed(&last_stat /* wtf? how is this legal? idk*/)) {
|
|
|
|
if let Cow::Owned(stat) = std::mem::replace(&mut stat, Cow::Borrowed(&last_stat /* wtf? how is this legal? idk*/)) {
|
|
|
|