cli/diff: Replace manual pushing with Table::extend()
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
fbef60eed6
commit
8554e996b8
|
|
@ -444,78 +444,86 @@ 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 {
|
|
||||||
match line {
|
table.extend(
|
||||||
Modification::Addition(a) => {
|
self.lines
|
||||||
table.push([
|
.iter()
|
||||||
term::Label::space()
|
.map(|line| line_to_table_row(hi, blobs, repo, &theme, line)),
|
||||||
.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()),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vstack.push(table);
|
vstack.push(table);
|
||||||
vstack
|
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 {
|
impl ToPretty for Modification {
|
||||||
type Output = term::Line;
|
type Output = term::Line;
|
||||||
type Context = Blobs<Vec<term::Line>>;
|
type Context = Blobs<Vec<term::Line>>;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue