Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli/diff: Replace manual pushing with Table::extend()
Matthias Beyer committed 8 months ago
commit 8554e996b8db7066bee699b9c25a5daa12b6a1f8
parent fbef60eed63cce236728f37e4f461bb2bff5e035
1 file changed +75 -67
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>>;