pub mod terminal;
#[derive(Clone, Debug)]
pub enum Progress {
Phase(&'static str),
DownloadSource { url: String },
TryingMethod { index: usize, total: usize },
MethodFailed { error: String },
RunningCommand { tool: String },
CommandFailed { tool: String, error: String },
Bytes { done: u64, total: Option<u64> },
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct ProgressState {
pub total: Option<u64>,
pub position: u64,
}
impl ProgressState {
pub fn update(self, event: &Progress) -> ProgressState {
match event {
Progress::Bytes { done, total } => ProgressState {
total: total.or(self.total),
position: self.position.max(*done),
},
_ => ProgressState::default(),
}
}
}
pub trait Reporter: Send {
fn report(&self, event: Progress);
}
pub struct SilentReporter;
impl Reporter for SilentReporter {
fn report(&self, _event: Progress) {}
}
#[cfg(test)]
mod tests;