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]
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#[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}