#ansi-colors #difference #diff #debugging #pretty-assertions

colored-diff

Format the difference between two strings with ANSI colors

7 releases

Uses old Rust 2015

0.2.3 Oct 20, 2021
0.2.2 May 17, 2019
0.2.1 Sep 24, 2018
0.2.0 Jun 5, 2018
0.1.2 Jun 3, 2018

#376 in Testing

Download history 1153/week @ 2024-11-20 1314/week @ 2024-11-27 1465/week @ 2024-12-04 1613/week @ 2024-12-11 972/week @ 2024-12-18 397/week @ 2024-12-25 924/week @ 2025-01-01 1330/week @ 2025-01-08 1848/week @ 2025-01-15 1634/week @ 2025-01-22 1547/week @ 2025-01-29 1489/week @ 2025-02-05 1780/week @ 2025-02-12 1958/week @ 2025-02-19 1522/week @ 2025-02-26 1483/week @ 2025-03-05

7,049 downloads per month
Used in 30 crates (25 directly)

MIT OR Unlicense

9KB
170 lines

colored-diff

Show colored differences between source strings!

Inspired by / extracted from pretty-assertions and difference's github-style example

Powershell:
Powershell Example

Command Prompt:
Command Prompt Example

(Now accepting PRs for a macOS Terminal and/or Ubuntu (whatever console window) examples!)

Poem Example:

let expected = "\
    Roses are red, violets are blue,\n\
    I wrote this library here,\n\
    just for you.\n\
    (It's true).\n\
";
let actual = "\
    Roses are red, violets are blue,\n\
    I wrote this documentation here,\n\
    just for you.\n\
    (It's quite true).\n\
";

println!("{}", colored_diff::PrettyDifference { expected, actual })

Pretty-Assertions Example:

#[derive(Debug, PartialEq)]
struct Foo {
    lorem: &'static str,
    ipsum: u32,
    dolor: Result<String, String>,
}

let x = Some(Foo { lorem: "Hello World!", ipsum: 42, dolor: Ok("hey".to_string())});
let y = Some(Foo { lorem: "Hello Wrold!", ipsum: 42, dolor: Ok("hey ho!".to_string())});

let x = format!("{:#?}", x);
let y = format!("{:#?}", y);

println!("{}", colored_diff::PrettyDifference { expected: &x, actual: &y })

Dependencies

~540–760KB
~11K SLoC