Skip to content

Commit

Permalink
Merge pull request #240 from epage/diff
Browse files Browse the repository at this point in the history
fix(snap): Finish swapping colors
  • Loading branch information
epage authored Dec 8, 2023
2 parents 31b4e86 + 648d390 commit 792787f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions crates/snapbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,7 @@ windows-sys = { version = "0.52.0", features = ["Win32_Foundation"], optional =

[target.'cfg(unix)'.dependencies]
libc = { version = "0.2.137", optional = true }

[[example]]
name = "diff"
required-features = ["diff"]
24 changes: 24 additions & 0 deletions crates/snapbox/examples/diff.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
fn main() {
let mut args = std::env::args();
let _ = args.next().expect("expects `$ diff <old> <new>`");
let old_path = args.next().expect("expects `$ diff <old> <new>`");
let new_path = args.next().expect("expects `$ diff <old> <new>`");
if args.next().is_some() {
panic!("expects `$ diff <old> <new>`");
}

let old = snapbox::Data::text(std::fs::read_to_string(&old_path).unwrap());
let new = snapbox::Data::text(std::fs::read_to_string(&new_path).unwrap());

let mut output = String::new();
snapbox::report::write_diff(
&mut output,
&old,
&new,
Some(&old_path),
Some(&new_path),
snapbox::report::Palette::color(),
)
.unwrap();
println!("{output}");
}
4 changes: 2 additions & 2 deletions crates/snapbox/src/report/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ impl Palette {
warn: anstyle::AnsiColor::Yellow.on_default(),
error: anstyle::AnsiColor::Red.on_default(),
hint: anstyle::Effects::DIMMED.into(),
expected: anstyle::AnsiColor::Green.on_default() | anstyle::Effects::UNDERLINE,
actual: anstyle::AnsiColor::Red.on_default() | anstyle::Effects::UNDERLINE,
expected: anstyle::AnsiColor::Red.on_default() | anstyle::Effects::UNDERLINE,
actual: anstyle::AnsiColor::Green.on_default() | anstyle::Effects::UNDERLINE,
}
} else {
Self::plain()
Expand Down

0 comments on commit 792787f

Please sign in to comment.