Skip to content

Commit

Permalink
Merge pull request #102 from Roguelazer/issue-101
Browse files Browse the repository at this point in the history
replace ansi_term with yansi
  • Loading branch information
tommilligan committed Aug 30, 2022
2 parents 4fed8fd + 3b01fec commit 3294a90
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Expand Up @@ -49,7 +49,7 @@ jobs:
rust:
- stable
- beta
- 1.35.0
- 1.54.0
experimental:
- false
# Run a canary test on nightly that's allowed to fail
Expand Down
2 changes: 1 addition & 1 deletion pretty_assertions/Cargo.toml
Expand Up @@ -30,7 +30,7 @@ alloc = []
unstable = []

[dependencies]
ansi_term = "0.12.1"
yansi = "0.5"
diff = "0.1.12"

[target.'cfg(windows)'.dependencies]
Expand Down
4 changes: 1 addition & 3 deletions pretty_assertions/src/lib.rs
Expand Up @@ -80,7 +80,6 @@
#[cfg(feature = "alloc")]
#[macro_use]
extern crate alloc;
pub use ansi_term::Style;
use core::fmt::{self, Debug, Display};

mod printer;
Expand Down Expand Up @@ -335,13 +334,12 @@ macro_rules! assert_ne {
if *left_val == *right_val {
::core::panic!("assertion failed: `(left != right)`{}{}\
\n\
\n{}:\
\nBoth sides:\
\n{:#?}\
\n\
\n",
$maybe_colon,
format_args!($($arg)+),
$crate::Style::new().bold().paint("Both sides"),
left_val
)
}
Expand Down
28 changes: 15 additions & 13 deletions pretty_assertions/src/printer.rs
@@ -1,10 +1,10 @@
#[cfg(feature = "alloc")]
use alloc::format;
use ansi_term::{
Colour::{Fixed, Green, Red},
use core::fmt;
use yansi::{
Color::{Fixed, Green, Red, Unset},
Style,
};
use core::fmt;

macro_rules! paint {
($f:expr, $colour:expr, $fmt:expr, $($args:tt)*) => (
Expand All @@ -20,7 +20,7 @@ pub(crate) fn write_header(f: &mut fmt::Formatter) -> fmt::Result {
writeln!(
f,
"{} {} / {} :",
Style::new().bold().paint("Diff"),
Style::new(Unset).bold().paint("Diff"),
Red.paint(format!("{} left", SIGN_LEFT)),
Green.paint(format!("right {}", SIGN_RIGHT))
)
Expand Down Expand Up @@ -139,7 +139,7 @@ where
fn new(f: &'a mut Writer) -> Self {
InlineWriter {
f,
style: Style::new(),
style: Style::new(Unset),
}
}

Expand All @@ -150,10 +150,11 @@ where
write!(self.f, "{}", c)?;
} else {
// Close out previous style
write!(self.f, "{}", self.style.suffix())?;
self.style.fmt_suffix(self.f)?;

// Store new style and start writing it
write!(self.f, "{}{}", style.prefix(), c)?;
style.fmt_prefix(self.f)?;
write!(self.f, "{}", c)?;
self.style = style;
}
Ok(())
Expand All @@ -162,8 +163,9 @@ where
/// Finish any existing style and reset to default state.
fn finish(&mut self) -> fmt::Result {
// Close out previous style
writeln!(self.f, "{}", self.style.suffix())?;
self.style = Default::default();
self.style.fmt_suffix(self.f)?;
writeln!(self.f)?;
self.style = Style::new(Unset);
Ok(())
}
}
Expand All @@ -178,8 +180,8 @@ fn write_inline_diff<TWrite: fmt::Write>(f: &mut TWrite, left: &str, right: &str
let mut writer = InlineWriter::new(f);

// Print the left string on one line, with differences highlighted
let light = Red.into();
let heavy = Red.on(Fixed(52)).bold();
let light = Style::new(Red);
let heavy = Style::new(Red).bg(Fixed(52)).bold();
writer.write_with_style(&SIGN_LEFT, light)?;
for change in diff.iter() {
match change {
Expand All @@ -191,8 +193,8 @@ fn write_inline_diff<TWrite: fmt::Write>(f: &mut TWrite, left: &str, right: &str
writer.finish()?;

// Print the right string on one line, with differences highlighted
let light = Green.into();
let heavy = Green.on(Fixed(22)).bold();
let light = Style::new(Green);
let heavy = Style::new(Green).bg(Fixed(22)).bold();
writer.write_with_style(&SIGN_RIGHT, light)?;
for change in diff.iter() {
match change {
Expand Down
10 changes: 5 additions & 5 deletions pretty_assertions/tests/macros.rs
Expand Up @@ -234,7 +234,7 @@ mod assert_ne {
#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`
[1mBoth sides[0m:
Both sides:
666
"#)]
fn fails() {
Expand All @@ -244,7 +244,7 @@ mod assert_ne {
#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`
[1mBoth sides[0m:
Both sides:
666
"#)]
fn fails_trailing_comma() {
Expand All @@ -254,7 +254,7 @@ mod assert_ne {
#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`
[1mBoth sides[0m:
Both sides:
[
101,
]
Expand All @@ -269,7 +269,7 @@ mod assert_ne {
#[should_panic(
expected = r#"assertion failed: `(left != right)`: custom panic message
[1mBoth sides[0m:
Both sides:
666
"#
)]
Expand All @@ -281,7 +281,7 @@ mod assert_ne {
#[should_panic(
expected = r#"assertion failed: `(left != right)`: custom panic message
[1mBoth sides[0m:
Both sides:
666
"#
)]
Expand Down

0 comments on commit 3294a90

Please sign in to comment.