use std::io::{self, Write};
use crate::cli::MetricKind;
use crate::core::config::Config;
use crate::core::term::{ansi_wrap, ANSI_CYAN};
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,
ctx: &SectionCtx<'_>,
w: &mut dyn Write,
) -> io::Result<()> {
writeln!(w)?;
let title = format!("── {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>> {
vec![
Box::new(super::loc::LocSection),
Box::new(super::complexity::ComplexitySection),
Box::new(super::churn::ChurnSection),
Box::new(super::coupling::ChangeCouplingSection),
Box::new(super::duplication::DuplicationSection),
Box::new(super::hotspot::HotspotSection),
Box::new(super::lcom::LcomSection),
]
}