From 0d3d847b09f9797e5628065d4c83db5f490c75e2 Mon Sep 17 00:00:00 2001 From: Avril Date: Mon, 10 Aug 2020 03:16:31 +0100 Subject: [PATCH] start many --- src/progress.rs | 96 +++++++++++++++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 34 deletions(-) diff --git a/src/progress.rs b/src/progress.rs index 82c182c..584eb35 100644 --- a/src/progress.rs +++ b/src/progress.rs @@ -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), } #[derive(Debug)] @@ -268,40 +273,63 @@ pub fn create_progress { - 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), + Many(Vec), + } + + impl From 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*/)) {