git-stats 0.2.2

A tool for getting aggregated commit stats
Documentation
use tabled::{
    Table,
    settings::{
        Alignment, Padding, Style,
        format::Format,
        object::{Columns, Rows},
    },
};
use yansi::Paint;

use crate::model::{Review, Stat};

/// Render the per-author stats table. The last row is expected to be the "Total"
/// row (shown bold); the header row is bold and underlined. Styling is gated by
/// yansi's global condition, so it is plain text when color is disabled.
#[must_use]
pub fn render_stats(rows: &[Stat]) -> String {
    let mut table = Table::new(rows);
    table
        .with(Style::empty())
        .modify(Columns::first(), Padding::new(0, 1, 0, 0))
        .modify(Columns::last(), Padding::new(1, 0, 0, 0))
        .modify(Columns::new(1..=5), Alignment::right())
        .modify(
            Rows::first(),
            Format::content(|s| s.bold().underline().to_string()),
        )
        .modify(Rows::last(), Format::content(|s| s.bold().to_string()));
    table.to_string()
}

/// Render the per-reviewer table. For consistency with the stats table, its
/// header row is bold and underlined (gated by yansi's global color condition).
#[must_use]
pub fn render_reviews(rows: &[Review]) -> String {
    let mut table = Table::new(rows);
    table
        .with(Style::empty())
        .modify(Columns::first(), Padding::new(0, 1, 0, 0))
        .modify(Columns::last(), Padding::new(1, 0, 0, 0))
        .modify(Columns::new(1..=1), Alignment::right())
        .modify(
            Rows::first(),
            Format::content(|s| s.bold().underline().to_string()),
        );
    table.to_string()
}