cli/diff: Replace manual pushing with Table::extend()

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2025-09-07 12:59:26 +02:00 committed by Lorenz Leutgeb
parent fbef60eed6
commit 8554e996b8
1 changed files with 75 additions and 67 deletions

View File

@ -444,10 +444,27 @@ impl ToPretty for Hunk<Modification> {
if let Ok(header) = HunkHeader::from_bytes(self.header.as_bytes()) { if let Ok(header) = HunkHeader::from_bytes(self.header.as_bytes()) {
vstack.push(header.pretty(hi, &(), repo)); vstack.push(header.pretty(hi, &(), repo));
} }
for line in &self.lines {
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 { match line {
Modification::Addition(a) => { Modification::Addition(a) => [
table.push([
term::Label::space() term::Label::space()
.pad(5) .pad(5)
.bg(theme.color("positive")) .bg(theme.color("positive"))
@ -465,10 +482,8 @@ impl ToPretty for Hunk<Modification> {
line.pretty(hi, blobs, repo) line.pretty(hi, blobs, repo)
.filled(theme.color("positive.dark")), .filled(theme.color("positive.dark")),
term::Line::blank().filled(term::Color::default()), term::Line::blank().filled(term::Color::default()),
]); ],
} Modification::Deletion(a) => [
Modification::Deletion(a) => {
table.push([
term::label(a.line_no.to_string()) term::label(a.line_no.to_string())
.pad(5) .pad(5)
.fg(theme.color("negative.light")) .fg(theme.color("negative.light"))
@ -486,14 +501,12 @@ impl ToPretty for Hunk<Modification> {
line.pretty(hi, blobs, repo) line.pretty(hi, blobs, repo)
.filled(theme.color("negative.dark")), .filled(theme.color("negative.dark")),
term::Line::blank().filled(term::Color::default()), term::Line::blank().filled(term::Color::default()),
]); ],
}
Modification::Context { Modification::Context {
line_no_old, line_no_old,
line_no_new, line_no_new,
.. ..
} => { } => [
table.push([
term::label(line_no_old.to_string()) term::label(line_no_old.to_string())
.pad(5) .pad(5)
.fg(theme.color("dim")) .fg(theme.color("dim"))
@ -507,12 +520,7 @@ impl ToPretty for Hunk<Modification> {
term::label(" ").to_line().filled(term::Color::default()), term::label(" ").to_line().filled(term::Color::default()),
line.pretty(hi, blobs, repo).filled(term::Color::default()), line.pretty(hi, blobs, repo).filled(term::Color::default()),
term::Line::blank().filled(term::Color::default()), term::Line::blank().filled(term::Color::default()),
]); ],
}
}
}
vstack.push(table);
vstack
} }
} }