mirror of
https://github.com/Hopiu/lychee.git
synced 2026-03-17 05:00:26 +00:00
Extend compact format (#1497)
* Show unknowns and timeouts in compact format * Clippy: make functions const
This commit is contained in:
parent
53d234d18e
commit
7fcf66c492
3 changed files with 25 additions and 8 deletions
|
|
@ -1,4 +1,6 @@
|
|||
use anyhow::Result;
|
||||
use console::Style;
|
||||
use once_cell::sync::Lazy;
|
||||
use std::{
|
||||
fmt::{self, Display},
|
||||
time::Duration,
|
||||
|
|
@ -51,25 +53,40 @@ impl Display for CompactResponseStats {
|
|||
writeln!(f)?;
|
||||
}
|
||||
|
||||
color!(f, NORMAL, "\u{1F50D} {} Total", stats.total)?;
|
||||
color!(f, NORMAL, "🔍 {} Total", stats.total)?;
|
||||
|
||||
// show duration (in a human readable format), e.g. 2m 30s
|
||||
let duration = Duration::from_secs(stats.duration_secs);
|
||||
color!(f, DIM, " (in {})", humantime::format_duration(duration))?;
|
||||
|
||||
color!(f, BOLD_GREEN, " \u{2705} {} OK", stats.successful)?;
|
||||
color!(f, BOLD_GREEN, " ✅ {} OK", stats.successful)?;
|
||||
|
||||
let total_errors = stats.errors;
|
||||
|
||||
let err_str = if total_errors == 1 { "Error" } else { "Errors" };
|
||||
color!(f, BOLD_PINK, " \u{1f6ab} {} {}", total_errors, err_str)?;
|
||||
if stats.excludes > 0 {
|
||||
color!(f, BOLD_YELLOW, " \u{1F4A4} {} Excluded", stats.excludes)?;
|
||||
}
|
||||
color!(f, BOLD_PINK, " 🚫 {} {}", total_errors, err_str)?;
|
||||
|
||||
write_if_any(stats.unknown, "❓", "Unknown", &BOLD_PINK, f)?;
|
||||
write_if_any(stats.excludes, "👻", "Excluded", &BOLD_YELLOW, f)?;
|
||||
write_if_any(stats.timeouts, "⏳", "Timeouts", &BOLD_YELLOW, f)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn write_if_any(
|
||||
value: usize,
|
||||
symbol: &str,
|
||||
text: &str,
|
||||
style: &Lazy<Style>,
|
||||
f: &mut fmt::Formatter<'_>,
|
||||
) -> Result<(), fmt::Error> {
|
||||
if value > 0 {
|
||||
color!(f, style, " {} {} {}", symbol, value, text)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) struct Compact {
|
||||
mode: options::OutputMode,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ pub(crate) struct ClientRequestChains<'a> {
|
|||
|
||||
impl<'a> ClientRequestChains<'a> {
|
||||
/// Create a new chain of request chains.
|
||||
pub(crate) fn new(chains: Vec<&'a RequestChain>) -> Self {
|
||||
pub(crate) const fn new(chains: Vec<&'a RequestChain>) -> Self {
|
||||
Self { chains }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ pub struct Remaps(Vec<(Regex, String)>);
|
|||
impl Remaps {
|
||||
/// Create a new remapper
|
||||
#[must_use]
|
||||
pub fn new(patterns: Vec<(Regex, String)>) -> Self {
|
||||
pub const fn new(patterns: Vec<(Regex, String)>) -> Self {
|
||||
Self(patterns)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue