Skip to main content

git_stats/logic/
render.rs

1use tabled::{
2    Table,
3    settings::{
4        Alignment, Padding, Style,
5        format::Format,
6        object::{Columns, Rows},
7    },
8};
9use yansi::Paint;
10
11use crate::model::{Review, Stat};
12
13/// Render the per-author stats table. The last row is expected to be the "Total"
14/// row (shown bold); the header row is bold and underlined. Styling is gated by
15/// yansi's global condition, so it is plain text when color is disabled.
16#[must_use]
17pub fn render_stats(rows: &[Stat]) -> String {
18    let mut table = Table::new(rows);
19    table
20        .with(Style::empty())
21        .modify(Columns::first(), Padding::new(0, 1, 0, 0))
22        .modify(Columns::last(), Padding::new(1, 0, 0, 0))
23        .modify(Columns::new(1..=5), Alignment::right())
24        .modify(
25            Rows::first(),
26            Format::content(|s| s.bold().underline().to_string()),
27        )
28        .modify(Rows::last(), Format::content(|s| s.bold().to_string()));
29    table.to_string()
30}
31
32/// Render the per-reviewer table. For consistency with the stats table, its
33/// header row is bold and underlined (gated by yansi's global color condition).
34#[must_use]
35pub fn render_reviews(rows: &[Review]) -> String {
36    let mut table = Table::new(rows);
37    table
38        .with(Style::empty())
39        .modify(Columns::first(), Padding::new(0, 1, 0, 0))
40        .modify(Columns::last(), Padding::new(1, 0, 0, 0))
41        .modify(Columns::new(1..=1), Alignment::right())
42        .modify(
43            Rows::first(),
44            Format::content(|s| s.bold().underline().to_string()),
45        );
46    table.to_string()
47}