Skip to content

Commit

Permalink
Merge pull request #121 from SergioBenitez/yansi-update
Browse files Browse the repository at this point in the history
chore: update 'yansi' to 1.0.0-rc
  • Loading branch information
tommilligan committed Aug 11, 2023
2 parents 3f1ebc0 + 08838fe commit 4a0e5a3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Expand Up @@ -47,11 +47,11 @@ jobs:
matrix:
os:
- ubuntu-22.04
- windows-2019
- windows-2022
rust:
- stable
- beta
- 1.54.0
- 1.63.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,5 +30,5 @@ alloc = []
unstable = []

[dependencies]
yansi = "0.5"
yansi = "1.0.0-rc.1"
diff = "0.1.12"
35 changes: 18 additions & 17 deletions pretty_assertions/src/printer.rs
@@ -1,14 +1,12 @@
#[cfg(feature = "alloc")]
use alloc::format;
use core::fmt;
use yansi::{
Color::{Fixed, Green, Red, Unset},
Style,
};
use yansi::Color::{Green, Red};
use yansi::{Paint, Style};

macro_rules! paint {
($f:expr, $colour:expr, $fmt:expr, $($args:tt)*) => (
write!($f, "{}", $colour.paint(format!($fmt, $($args)*)))
($f:expr, $style:expr, $fmt:expr, $($args:tt)*) => (
write!($f, "{}", format!($fmt, $($args)*).paint($style))
)
}

Expand All @@ -19,10 +17,12 @@ const SIGN_LEFT: char = '<'; // - < ←
pub(crate) fn write_header(f: &mut fmt::Formatter) -> fmt::Result {
writeln!(
f,
"{} {} / {} :",
Style::new(Unset).bold().paint("Diff"),
Red.paint(format!("{} left", SIGN_LEFT)),
Green.paint(format!("right {}", SIGN_RIGHT))
"{} {} {} / {} {} :",
"Diff".bold(),
SIGN_LEFT.red().linger(),
"left".clear(),
"right".green().linger(),
SIGN_RIGHT.clear(),
)
}

Expand Down Expand Up @@ -139,13 +139,14 @@ where
fn new(f: &'a mut Writer) -> Self {
InlineWriter {
f,
style: Style::new(Unset),
style: Style::new(),
}
}

/// Push a new character into the buffer, specifying the style it should be written in.
fn write_with_style(&mut self, c: &char, style: Style) -> fmt::Result {
fn write_with_style<T: Into<Style>>(&mut self, c: &char, style: T) -> fmt::Result {
// If the style is the same as previously, just write character
let style = style.into();
if style == self.style {
write!(self.f, "{}", c)?;
} else {
Expand All @@ -165,7 +166,7 @@ where
// Close out previous style
self.style.fmt_suffix(self.f)?;
writeln!(self.f)?;
self.style = Style::new(Unset);
self.style = Style::new();
Ok(())
}
}
Expand All @@ -180,8 +181,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 = Style::new(Red);
let heavy = Style::new(Red).bg(Fixed(52)).bold();
let light = Red;
let heavy = Red.on_fixed(52).bold();
writer.write_with_style(&SIGN_LEFT, light)?;
for change in diff.iter() {
match change {
Expand All @@ -193,8 +194,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 = Style::new(Green);
let heavy = Style::new(Green).bg(Fixed(22)).bold();
let light = Green;
let heavy = Green.on_fixed(22).bold();
writer.write_with_style(&SIGN_RIGHT, light)?;
for change in diff.iter() {
match change {
Expand Down

0 comments on commit 4a0e5a3

Please sign in to comment.