mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-16 20:50:25 +00:00
* Bump flake 1.83.0 -> 1.87.0 * Move archive functionality into lychee-lib * Create example, update name and docs * Split function & update tests * Remove trailing slashes in API calls & update tests * Apply lint suggestions * Rename function * Move module * Add cargo-nextest to devShell to support 'make test'
48 lines
1.8 KiB
Rust
48 lines
1.8 KiB
Rust
pub(crate) mod color;
|
|
pub(crate) mod duration;
|
|
pub(crate) mod log;
|
|
pub(crate) mod response;
|
|
pub(crate) mod stats;
|
|
pub(crate) mod suggestion;
|
|
|
|
use self::{response::ResponseFormatter, stats::StatsFormatter};
|
|
use crate::options::{OutputMode, StatsFormat};
|
|
use supports_color::Stream;
|
|
|
|
/// Detects whether a terminal supports color, and gives details about that
|
|
/// support. It takes into account the `NO_COLOR` environment variable.
|
|
fn supports_color() -> bool {
|
|
supports_color::on(Stream::Stdout).is_some()
|
|
}
|
|
|
|
/// Create a stats formatter based on the given format option
|
|
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()),
|
|
}
|
|
}
|
|
|
|
/// Create a response formatter based on the given format option
|
|
pub(crate) fn get_response_formatter(mode: &OutputMode) -> Box<dyn ResponseFormatter> {
|
|
// Checks if color is supported in current environment or NO_COLOR is set (https://no-color.org)
|
|
if !supports_color() {
|
|
// To fix `TaskFormatter` not working if color is not supported
|
|
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),
|
|
}
|
|
}
|