radicle_cli/terminal/
comment.rs

1use radicle::cob::thread::{Comment, CommentId};
2use radicle::Profile;
3
4use crate::terminal as term;
5use crate::terminal::format::Author;
6
7/// Return a comment header as a [`term::Element`].
8pub fn header<T>(
9    id: &CommentId,
10    comment: &Comment<T>,
11    profile: &Profile,
12) -> term::hstack::HStack<'static> {
13    let author = comment.author();
14    let author = Author::new(&author, profile, false);
15    let (alias, nid) = author.labels();
16
17    term::hstack::HStack::default()
18        .child(term::Line::spaced([
19            alias,
20            nid,
21            term::format::timestamp(comment.timestamp()).dim().into(),
22        ]))
23        .child(term::Line::new(term::Label::space()))
24        .child(term::Line::spaced([term::format::oid(*id)
25            .fg(term::Color::Cyan)
26            .into()]))
27}
28
29/// Return a full comment widget as a [`term::Element`].
30pub fn widget<'a, T>(id: &CommentId, comment: &Comment<T>, profile: &Profile) -> term::VStack<'a> {
31    term::vstack::bordered(header(id, comment, profile))
32        .child(term::textarea(comment.body()).wrap(60))
33}