flake_edit/
diff.rs

1//! Wrapper for diffing the changes
2
3use std::io::IsTerminal;
4pub struct Diff<'a> {
5    old: &'a str,
6    new: &'a str,
7}
8
9impl<'a> Diff<'a> {
10    pub fn new(old: &'a str, new: &'a str) -> Self {
11        Self { old, new }
12    }
13    pub fn compare(&self) {
14        let patch = diffy::create_patch(self.old, self.new);
15        let f = if std::io::stdout().is_terminal() {
16            diffy::PatchFormatter::new().with_color()
17        } else {
18            diffy::PatchFormatter::new()
19        };
20        print!("{}", f.fmt_patch(&patch));
21    }
22}