pub(crate) mod color;
pub(crate) mod duration;
pub(crate) mod log;
pub(crate) mod response;
pub(crate) mod stats;
use self::{response::ResponseFormatter, stats::StatsFormatter};
use crate::options::{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::Markdown => Box::new(stats::Markdown::new()),
StatsFormat::Raw => Box::new(stats::Raw::new()),
}
}
pub(crate) fn get_response_formatter(mode: &OutputMode) -> Box<dyn ResponseFormatter> {
if !supports_color() {
return Box::new(response::PlainFormatter);
}
match mode {
OutputMode::Plain => Box::new(response::PlainFormatter),
OutputMode::Color => Box::new(response::ColorFormatter),
OutputMode::Emoji => Box::new(response::EmojiFormatter),
}
}