codeberg_cli/render/
comment.rs

1use time::{format_description, OffsetDateTime};
2
3use crate::types::config::BergConfig;
4
5pub fn render_comment(
6    config: &BergConfig,
7    username: &str,
8    creation_time: &OffsetDateTime,
9    comment: &str,
10) -> String {
11    let mut table = config.make_table();
12
13    const PARENTHESES: usize = 2;
14    const COLON: usize = 1;
15
16    let creation_time_formatted = creation_time
17        .format(
18            &format_description::parse("[day].[month].[year] - [hour]:[minute]")
19                .expect("invalid DateTime format"),
20        )
21        .expect("Couldn't format DateTime'");
22
23    table.add_row(vec![comment]);
24
25    format!(
26        "{}\n({}):\n{}\n\n{}",
27        username,
28        creation_time_formatted,
29        "=".repeat(creation_time_formatted.len() + PARENTHESES + COLON),
30        table.show()
31    )
32}