Diff a string for presentation to a user in the terminal.
``` rust use termdiff::{signstheme, DrawDiff}; let old = "Double, double toil and trouble; Fire burn and Caldron bubble."; let new = "Double, double toil and trouble; Fire burn and caldron bubble. Cool it with a baboon's blood, Then the charm is firm and good."; let actual = format!("{}", DrawDiff::new(old, new, signstheme()));
assert_eq!( actual, "--- remove | insert +++ Double, double toil and trouble; Fire burn and -Caldron bubble. +caldron bubble. +Cool it with a baboon's blood, +Then the charm is firm and good. " ); ```
Alternatively you can use this interface
``` rust
use termdiff::{arrowstheme, diff};
let old = "Double, double toil and trouble;
Fire burn and
Caldron bubble.";
let new = "Double, double toil and trouble;
Fire burn and
caldron bubble.
Cool it with a baboon's blood,
Then the charm is firm and good.";
let mut buffer: Vec
assert_eq!(
actual,
"< left / > right
Double, double toil and trouble;
Fire burn and
caldron bubble.
Cool it with a baboon's blood,
Then the charm is firm and good.
"
);
``` Read more at Docs.rs We have a limited number of built in themes ``` rust
use termdiff::DrawDiff;
use termdiff::Theme;
use crossterm::style::Stylize; let mytheme = Theme {
header: format!("{}\n", "Header"),
highlightinsert: crossterm::style::Stylize::stylize,
highlightdelete: crossterm::style::Stylize::stylize,
equalprefix: "=".tostring(),
equalcontent: crossterm::style::Stylize::stylize,
deleteprefix: "!".tostring(),
deletecontent: crossterm::style::Stylize::stylize,
insertprefix: "|".tostring(),
insertline: crossterm::style::Stylize::stylize,
line_end: "\n".into(),
}; let old = "Double, double toil and trouble;
Fire burn and
Caldron bubble.";
let new = "Double, double toil and trouble;
Fire burn and
caldron bubble.
Cool it with a baboon's blood,
Then the charm is firm and good.";
let actual = format!("{}", DrawDiff::new(old, new, my_theme)); assert_eq!(
actual,
"Header
=Double, double toil and trouble;
=Fire burn and
!Caldron bubble.
|caldron bubble.
|Cool it with a baboon's blood,
|Then the charm is firm and good.
"
);
```
Themes
Arrows
Signs
Custom