Skip to content

Commit

Permalink
Display diffs not at the world level
Browse files Browse the repository at this point in the history
  • Loading branch information
dmerejkowsky committed Oct 9, 2018
1 parent 0cfb478 commit e65aea5
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions src/replacer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,29 @@ struct Replacement {
new: String,
}

impl Replacement {
fn print_self(&self) {
let changeset = Changeset::new(&self.old, &self.new, "");
print!("{} ", "--".red());
for diff in &changeset.diffs {
match diff {
Difference::Same(s) => print!("{}", s),
Difference::Rem(s) => print!("{}", s.red().underline()),
_ => (),
}
}
print!("\n");
print!("{} ", "++".green());
for diff in &changeset.diffs {
match diff {
Difference::Same(s) => print!("{}", s),
Difference::Add(s) => print!("{}", s.green().underline()),
_ => (),
}
}
}
}

struct FilePatcher {
replacements: Vec<Replacement>,
path: PathBuf,
Expand Down Expand Up @@ -138,30 +161,8 @@ impl FilePatcher {
self.path.to_string_lossy().bold()
);
for replacement in &self.replacements {
let Replacement {
line_no: _,
old,
new,
} = replacement;
let changeset = Changeset::new(old, new, " ");
print!("{} ", "--".red());
for diff in &changeset.diffs {
match diff {
Difference::Same(s) => print!("{}", s),
Difference::Rem(s) => print!(" {} ", s.red().underline()),
_ => (),
}
}
replacement.print_self();
print!("\n");
print!("{} ", "++".green());
for diff in &changeset.diffs {
match diff {
Difference::Same(s) => print!("{}", s),
Difference::Add(s) => print!(" {} ", s.green().underline()),
_ => (),
}
}
print!("\n\n");
}
}
}
Expand All @@ -183,4 +184,14 @@ mod tests {
assert_eq!(actual_replacement.old, "Top: old is nice");
}

#[test]
fn test_display() {
let replacement = Replacement {
line_no: 1,
old: "trustchain_creation: 0".to_owned(),
new: "blockchain_creation: 0".to_owned(),
};
replacement.print_self();
}

}

0 comments on commit e65aea5

Please sign in to comment.