master
Avril 4 years ago
parent 283a2712c3
commit 0d3d847b09
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -14,7 +14,10 @@ use std::{
Poll,
},
pin::Pin,
iter::{
self,
Once,
},
};
use tokio::{
sync::{
@ -58,6 +61,8 @@ enum CommandKind
RemoveTask(usize),
Complete,
Many(Vec<CommandKind>),
}
#[derive(Debug)]
@ -268,40 +273,63 @@ pub fn create_progress<P: ProgressBar + WithTitle + Send + 'static,
(comm, d)
};
// Match the command
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());
enum MaybeSingle
{
Single(Once<CommandKind>),
Many(Vec<CommandKind>),
}
impl From<CommandKind> for MaybeSingle
{
fn from(from: CommandKind) -> Self
{
match from {
CommandKind::Many(many) => Self::Many(many),
x => Self::Single(iter::once(x)),
}
},
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*/)) {

Loading…
Cancel
Save