#ansi-colors #difference #diff #source-string #pretty-assertions

colored-diff

使用 ANSI 颜色格式化两个字符串之间的差异

7 个版本

使用旧的 Rust 2015

0.2.3 2021 年 10 月 20 日
0.2.2 2019 年 5 月 17 日
0.2.1 2018 年 9 月 24 日
0.2.0 2018 年 6 月 5 日
0.1.2 2018 年 6 月 3 日

#146 in 测试

Download history 9967/week @ 2024-03-14 9260/week @ 2024-03-21 9139/week @ 2024-03-28 6236/week @ 2024-04-04 7662/week @ 2024-04-11 8747/week @ 2024-04-18 7425/week @ 2024-04-25 7505/week @ 2024-05-02 10558/week @ 2024-05-09 8740/week @ 2024-05-16 8079/week @ 2024-05-23 8037/week @ 2024-05-30 9670/week @ 2024-06-06 9210/week @ 2024-06-13 7866/week @ 2024-06-20 6501/week @ 2024-06-27

34,908 每月下载量
21 crates 中使用

MIT 或 Unlicense

9KB
170 代码行

colored-diff

显示源字符串之间的彩色差异!

灵感来自/提取自 pretty-assertionsdifference's github-style example

Powershell
Powershell Example

命令提示符
Command Prompt Example

(现在接受 macOS 终端和/或 Ubuntu (任何控制台窗口) 示例的 PR!)

诗歌示例:

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 示例:

#[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 })

依赖项

~510–730KB
~11K SLoC