use std::collections::VecDeque;
use crate::outcome::StepOutcome;
use crate::theme::Theme;
pub type GroupMap = &'static [(&'static str, &'static [&'static str])];
pub fn group_index_for_step(groups: GroupMap, step_id: &str) -> Option<usize> {
groups
.iter()
.position(|(_, steps)| steps.contains(&step_id))
}
#[derive(Debug, Clone, Copy)]
pub struct ProgressSpec {
pub groups: GroupMap,
pub footer: &'static str,
pub rich_title: &'static str,
pub skipped: &'static str,
pub plain_skipped: &'static str,
pub interrupted: &'static str,
}
pub trait SummaryView: Send + std::fmt::Debug {
fn plain_lines(&self) -> Vec<String>;
fn rich_lines(&self, theme: &Theme, logs: &VecDeque<String>) -> Vec<String>;
fn fullscreen_grid(
&self,
theme: &Theme,
journal: &VecDeque<String>,
cols: usize,
rows: usize,
) -> Vec<String>;
fn failed(&self) -> bool;
}
#[derive(Debug)]
pub enum ProgressEvent {
StepStarted {
id: String,
},
StepResult {
id: String,
outcome: StepOutcome,
},
SubProgress {
id: String,
done: u64,
total: u64,
},
Activity {
id: String,
message: String,
},
SubLog {
id: String,
line: String,
},
ByteProgress {
id: String,
done: u64,
total: u64,
label: String,
},
Log {
level: tracing::Level,
line: String,
},
Summary(Box<dyn SummaryView>),
Finished,
}
#[cfg(test)]
mod tests {
use super::*;
const GROUPS: GroupMap = &[("Prepare", &["a", "b"]), ("Finish", &["c"])];
#[test]
fn group_lookup_resolves() {
assert_eq!(group_index_for_step(GROUPS, "a"), Some(0));
assert_eq!(group_index_for_step(GROUPS, "b"), Some(0));
assert_eq!(group_index_for_step(GROUPS, "c"), Some(1));
assert_eq!(group_index_for_step(GROUPS, "nope"), None);
}
}