Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
Replace manual pushing to term::Table with Table::extend()
Merged did:key:z6MkwcUR...q1kL opened 7 months ago

What the title says.

4 files changed +123 -99 370ae364 646d4360
modified crates/radicle-cli/src/commands/issue.rs
@@ -783,7 +783,7 @@ where
    ]);
    table.divider();

-
    for (id, issue) in all {
+
    table.extend(all.into_iter().map(|(id, issue)| {
        let assigned: String = issue
            .assignees()
            .map(|did| {
@@ -800,34 +800,46 @@ where
        let author = issue.author().id;
        let (alias, did) = Author::new(&author, profile, false).labels();

-
        table.push([
-
            match issue.state() {
-
                State::Open => term::format::positive("●").into(),
-
                State::Closed { .. } => term::format::negative("●").into(),
-
            },
-
            term::format::tertiary(term::format::cob(&id))
-
                .to_owned()
-
                .into(),
-
            term::format::default(issue.title().to_owned()).into(),
-
            alias.into(),
-
            did.into(),
-
            term::format::secondary(labels.join(", ")).into(),
-
            if assigned.is_empty() {
-
                term::format::dim(String::default()).into()
-
            } else {
-
                term::format::primary(assigned.to_string()).dim().into()
-
            },
-
            term::format::timestamp(issue.timestamp())
-
                .dim()
-
                .italic()
-
                .into(),
-
        ]);
-
    }
+
        mk_issue_row(id, issue, assigned, labels, alias, did)
+
    }));
+

    table.print();

    Ok(())
}

+
fn mk_issue_row(
+
    id: cob::ObjectId,
+
    issue: issue::Issue,
+
    assigned: String,
+
    labels: Vec<String>,
+
    alias: radicle_term::Label,
+
    did: radicle_term::Label,
+
) -> [radicle_term::Line; 8] {
+
    [
+
        match issue.state() {
+
            State::Open => term::format::positive("●").into(),
+
            State::Closed { .. } => term::format::negative("●").into(),
+
        },
+
        term::format::tertiary(term::format::cob(&id))
+
            .to_owned()
+
            .into(),
+
        term::format::default(issue.title().to_owned()).into(),
+
        alias.into(),
+
        did.into(),
+
        term::format::secondary(labels.join(", ")).into(),
+
        if assigned.is_empty() {
+
            term::format::dim(String::default()).into()
+
        } else {
+
            term::format::primary(assigned.to_string()).dim().into()
+
        },
+
        term::format::timestamp(issue.timestamp())
+
            .dim()
+
            .italic()
+
            .into(),
+
    ]
+
}
+

fn open<R, G>(
    title: Option<Title>,
    description: Option<String>,
modified crates/radicle-cli/src/commands/node/control.rs
@@ -377,7 +377,7 @@ pub fn sessions(node: &Node) -> Result<Option<term::Table<5, term::Label>>, node
    ]);
    table.divider();

-
    for sess in sessions {
+
    table.extend(sessions.into_iter().map(|sess| {
        let nid = term::format::tertiary(term::format::node_id_human(&sess.nid)).into();
        let (addr, state, time) = match sess.state {
            node::State::Initial => (
@@ -405,8 +405,10 @@ pub fn sessions(node: &Node) -> Result<Option<term::Table<5, term::Label>>, node
            node::Link::Inbound => term::Label::from(link_direction_inbound()),
            node::Link::Outbound => term::Label::from(link_direction_outbound()),
        };
-
        table.push([nid, addr, state, direction, time]);
-
    }
+

+
        [nid, addr, state, direction, time]
+
    }));
+

    Ok(Some(table))
}

modified crates/radicle-cli/src/commands/sync.rs
@@ -360,7 +360,7 @@ fn sync_status(

    sort_seeds_by(local_nid, &mut seeds, &aliases, &options.sort_by);

-
    for seed in seeds {
+
    let seeds = seeds.into_iter().flat_map(|seed| {
        let (status, head, time) = match seed.sync {
            Some(SyncStatus::Synced {
                at: SyncedAt { oid, timestamp },
@@ -391,19 +391,21 @@ fn sync_status(
                term::paint(String::new()),
                term::paint(String::new()),
            ),
-
            None => continue,
+
            None => return None,
        };

        let (alias, nid) = Author::new(&seed.nid, profile, options.verbose).labels();

-
        table.push([
+
        Some([
            nid,
            alias,
            status.into(),
            term::format::secondary(head).into(),
            time.dim().italic().into(),
-
        ]);
-
    }
+
        ])
+
    });
+

+
    table.extend(seeds);
    table.print();

    if profile.hints() {
modified crates/radicle-cli/src/git/pretty_diff.rs
@@ -444,78 +444,86 @@ impl ToPretty for Hunk<Modification> {
        if let Ok(header) = HunkHeader::from_bytes(self.header.as_bytes()) {
            vstack.push(header.pretty(hi, &(), repo));
        }
-
        for line in &self.lines {
-
            match line {
-
                Modification::Addition(a) => {
-
                    table.push([
-
                        term::Label::space()
-
                            .pad(5)
-
                            .bg(theme.color("positive"))
-
                            .to_line()
-
                            .filled(theme.color("positive")),
-
                        term::label(a.line_no.to_string())
-
                            .pad(5)
-
                            .fg(theme.color("positive.light"))
-
                            .to_line()
-
                            .filled(theme.color("positive")),
-
                        term::label(" + ")
-
                            .fg(theme.color("positive.light"))
-
                            .to_line()
-
                            .filled(theme.color("positive.dark")),
-
                        line.pretty(hi, blobs, repo)
-
                            .filled(theme.color("positive.dark")),
-
                        term::Line::blank().filled(term::Color::default()),
-
                    ]);
-
                }
-
                Modification::Deletion(a) => {
-
                    table.push([
-
                        term::label(a.line_no.to_string())
-
                            .pad(5)
-
                            .fg(theme.color("negative.light"))
-
                            .to_line()
-
                            .filled(theme.color("negative")),
-
                        term::Label::space()
-
                            .pad(5)
-
                            .fg(theme.color("dim"))
-
                            .to_line()
-
                            .filled(theme.color("negative")),
-
                        term::label(" - ")
-
                            .fg(theme.color("negative.light"))
-
                            .to_line()
-
                            .filled(theme.color("negative.dark")),
-
                        line.pretty(hi, blobs, repo)
-
                            .filled(theme.color("negative.dark")),
-
                        term::Line::blank().filled(term::Color::default()),
-
                    ]);
-
                }
-
                Modification::Context {
-
                    line_no_old,
-
                    line_no_new,
-
                    ..
-
                } => {
-
                    table.push([
-
                        term::label(line_no_old.to_string())
-
                            .pad(5)
-
                            .fg(theme.color("dim"))
-
                            .to_line()
-
                            .filled(theme.color("faint")),
-
                        term::label(line_no_new.to_string())
-
                            .pad(5)
-
                            .fg(theme.color("dim"))
-
                            .to_line()
-
                            .filled(theme.color("faint")),
-
                        term::label("   ").to_line().filled(term::Color::default()),
-
                        line.pretty(hi, blobs, repo).filled(term::Color::default()),
-
                        term::Line::blank().filled(term::Color::default()),
-
                    ]);
-
                }
-
            }
-
        }
+

+
        table.extend(
+
            self.lines
+
                .iter()
+
                .map(|line| line_to_table_row(hi, blobs, repo, &theme, line)),
+
        );
+

        vstack.push(table);
        vstack
    }
}

+
fn line_to_table_row<R: Repo>(
+
    hi: &mut Highlighter,
+
    blobs: &Blobs<Vec<radicle_term::Line>>,
+
    repo: &R,
+
    theme: &Theme,
+
    line: &Modification,
+
) -> [radicle_term::Filled<radicle_term::Line>; 5] {
+
    match line {
+
        Modification::Addition(a) => [
+
            term::Label::space()
+
                .pad(5)
+
                .bg(theme.color("positive"))
+
                .to_line()
+
                .filled(theme.color("positive")),
+
            term::label(a.line_no.to_string())
+
                .pad(5)
+
                .fg(theme.color("positive.light"))
+
                .to_line()
+
                .filled(theme.color("positive")),
+
            term::label(" + ")
+
                .fg(theme.color("positive.light"))
+
                .to_line()
+
                .filled(theme.color("positive.dark")),
+
            line.pretty(hi, blobs, repo)
+
                .filled(theme.color("positive.dark")),
+
            term::Line::blank().filled(term::Color::default()),
+
        ],
+
        Modification::Deletion(a) => [
+
            term::label(a.line_no.to_string())
+
                .pad(5)
+
                .fg(theme.color("negative.light"))
+
                .to_line()
+
                .filled(theme.color("negative")),
+
            term::Label::space()
+
                .pad(5)
+
                .fg(theme.color("dim"))
+
                .to_line()
+
                .filled(theme.color("negative")),
+
            term::label(" - ")
+
                .fg(theme.color("negative.light"))
+
                .to_line()
+
                .filled(theme.color("negative.dark")),
+
            line.pretty(hi, blobs, repo)
+
                .filled(theme.color("negative.dark")),
+
            term::Line::blank().filled(term::Color::default()),
+
        ],
+
        Modification::Context {
+
            line_no_old,
+
            line_no_new,
+
            ..
+
        } => [
+
            term::label(line_no_old.to_string())
+
                .pad(5)
+
                .fg(theme.color("dim"))
+
                .to_line()
+
                .filled(theme.color("faint")),
+
            term::label(line_no_new.to_string())
+
                .pad(5)
+
                .fg(theme.color("dim"))
+
                .to_line()
+
                .filled(theme.color("faint")),
+
            term::label("   ").to_line().filled(term::Color::default()),
+
            line.pretty(hi, blobs, repo).filled(term::Color::default()),
+
            term::Line::blank().filled(term::Color::default()),
+
        ],
+
    }
+
}
+

impl ToPretty for Modification {
    type Output = term::Line;
    type Context = Blobs<Vec<term::Line>>;