use std::io::{self, Write};
use crate::cli::MetricKind;
use crate::core::config::Config;
use crate::core::term::{ansi_wrap, ANSI_CYAN};
use crate::feature::Family;
use crate::observers::ObserverReports;
pub(super) struct SectionCtx<'a> {
pub cfg: &'a Config,
pub reports: &'a ObserverReports,
pub colorize: bool,
}
pub(super) fn write_section_header(
label: &str,
metric: MetricKind,
ctx: &SectionCtx<'_>,
w: &mut dyn Write,
) -> io::Result<()> {
writeln!(w)?;
let family = Family::for_metric(metric.json_key()).label();
let title = format!("── [{family}] {label} ──");
writeln!(w, "{}", ansi_wrap(ANSI_CYAN, &title, ctx.colorize))?;
Ok(())
}
pub(super) trait MetricSection {
fn metric(&self) -> MetricKind;
fn render_text(&self, ctx: &SectionCtx<'_>, w: &mut dyn Write) -> io::Result<()>;
fn raw_json(&self, ctx: &SectionCtx<'_>) -> serde_json::Value;
fn worst_json(&self, ctx: &SectionCtx<'_>) -> (usize, serde_json::Value);
}
pub(super) fn all_sections() -> Vec<Box<dyn MetricSection>> {
let mut sections = super::code::sections();
sections.extend(super::docs::sections());
sections.extend(super::test::sections());
sections
}