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.
14///
15/// Blue comes from the ANSI 16 palette so terminal themes can remap it. Styling
16/// is gated by yansi's global condition, so it is plain text when color is
17/// disabled.
18#[must_use]
19pub fn render_stats(rows: &[Stat]) -> String {
20    let mut table = Table::new(rows);
21    table
22        .with(Style::empty())
23        .modify(Columns::first(), Padding::new(0, 1, 0, 0))
24        .modify(Columns::last(), Padding::new(1, 0, 0, 0))
25        .modify(Columns::new(1..=5), Alignment::right())
26        .modify(
27            Rows::first(),
28            Format::content(|s| s.blue().bold().to_string()),
29        )
30        .modify(
31            Rows::last(),
32            Format::content(|s| s.blue().bold().to_string()),
33        );
34    table.to_string()
35}
36
37/// Render the per-reviewer table. For consistency with the stats table, its
38/// header row is bold blue (gated by yansi's global color condition).
39#[must_use]
40pub fn render_reviews(rows: &[Review]) -> String {
41    let mut table = Table::new(rows);
42    table
43        .with(Style::empty())
44        .modify(Columns::first(), Padding::new(0, 1, 0, 0))
45        .modify(Columns::last(), Padding::new(1, 0, 0, 0))
46        .modify(Columns::new(1..=1), Alignment::right())
47        .modify(
48            Rows::first(),
49            Format::content(|s| s.blue().bold().to_string()),
50        );
51    table.to_string()
52}