termdiff

Diff a string for presentation to a user in the terminal.

Usage

``` rust use termdiff::{signstheme, DrawDiff}; let old = "The quick brown fox and\njumps over the sleepy dog"; let new = "The quick red fox and\njumps over the lazy dog"; let actual = format!("{}", DrawDiff::new(old, new, signstheme()));

assert_eq!( actual, "--- remove | insert +++ -The quick brown fox and -jumps over the sleepy dog +The quick red fox and +jumps over the lazy dog " ); ```

Alternatively you can use this interface

``` rust use termdiff::{arrowstheme, diff}; let old = "The quick brown fox and\njumps over the sleepy dog"; let new = "The quick red fox and\njumps over the lazy dog"; let mut buffer: Vec = Vec::new(); diff(&mut buffer, old, new, arrowstheme()).unwrap(); let actual: String = String::from_utf8(buffer).expect("Not valid UTF-8");

assert_eq!( actual, "< left / > right

The quick red fox and jumps over the lazy dog " ); ```

Read more at Docs.rs

Themes

We have a limited number of built in themes

Arrows

Demo of the arrows
format

Signs

Demo of the signs format

Custom

``` 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 = "The quick brown fox and\njumps over the sleepy dog"; let new = "The quick red fox and\njumps over the lazy dog"; let actual = format!("{}", DrawDiff::new(old, new, my_theme));

assert_eq!( actual, "Header !The quick brown fox and !jumps over the sleepy dog |The quick red fox and |jumps over the lazy dog " ); ```