git_stats/logic/
render.rs1use 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#[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#[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}