pub(crate) mod color;
pub(crate) mod duration;
pub(crate) mod host_stats;
pub(crate) mod log;
pub(crate) mod response;
pub(crate) mod stats;
pub(crate) mod suggestion;
use self::{response::ResponseFormatter, stats::StatsFormatter};
use crate::config::{OutputMode, StatsFormat};
use supports_color::Stream;
fn supports_color() -> bool {
supports_color::on(Stream::Stdout).is_some()
}
pub(crate) fn get_stats_formatter(
format: &StatsFormat,
mode: &OutputMode,
) -> Box<dyn StatsFormatter> {
match format {
StatsFormat::Compact => Box::new(stats::Compact::new(mode.clone())),
StatsFormat::Detailed => Box::new(stats::Detailed::new(mode.clone())),
StatsFormat::Json => Box::new(stats::Json::new()),
StatsFormat::Junit => Box::new(stats::Junit::new()),
StatsFormat::Markdown => Box::new(stats::Markdown::new()),
}
}
pub(crate) fn get_progress_formatter(mode: &OutputMode) -> Box<dyn ResponseFormatter> {
let mode = match mode {
OutputMode::Plain => OutputMode::Plain,
OutputMode::Color => OutputMode::Color,
OutputMode::Emoji => OutputMode::Emoji,
OutputMode::Task => OutputMode::default(),
};
get_response_formatter(&mode)
}
pub(crate) fn get_response_formatter(mode: &OutputMode) -> Box<dyn ResponseFormatter> {
if !supports_color() {
return match mode {
OutputMode::Task => Box::new(response::TaskFormatter),
_ => Box::new(response::PlainFormatter),
};
}
match mode {
OutputMode::Plain => Box::new(response::PlainFormatter),
OutputMode::Color => Box::new(response::ColorFormatter),
OutputMode::Emoji => Box::new(response::EmojiFormatter),
OutputMode::Task => Box::new(response::TaskFormatter),
}
}