Skip to content

Commit

Permalink
Update yansi to v1.0.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
de-vri-es committed Aug 27, 2024
1 parent caa0791 commit 95569ae
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
main:
* Update `syn` to `v2.0.76`.
* Update `yansi` to `v1.0.1`.

v0.3.14 - 2024-03-04:
* Fix support for Rust 1.65.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ categories = ["development-tools::debugging", "development-tools::testing"]

[dependencies]
assert2-macros = { version = "=0.3.14", path = "assert2-macros" }
yansi = "0.5.0"
yansi = "1.0.1"
is-terminal = "0.4.3"
diff = "0.1.13"

Expand Down
20 changes: 10 additions & 10 deletions src/__assert2_impl/print/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ impl<'a> MultiLineDiff<'a> {
for diff in &self.line_diffs {
match *diff {
LineDiff::LeftOnly(left) => {
writeln!(buffer, "{}", Paint::cyan(format_args!("< {left}"))).unwrap();
writeln!(buffer, "{}", Paint::cyan(&format_args!("< {left}"))).unwrap();
},
LineDiff::RightOnly(right) => {
writeln!(buffer, "{}", Paint::yellow(format_args!("> {right}"))).unwrap();
writeln!(buffer, "{}", Paint::yellow(&format_args!("> {right}"))).unwrap();
},
LineDiff::Different(left, right) => {
let diff = SingleLineDiff::new(left, right);
write!(buffer, "{} ", diff.left_highlights.normal.paint("<")).unwrap();
write!(buffer, "{} ", "<".paint(diff.left_highlights.normal)).unwrap();
diff.write_left(buffer);
write!(buffer, "\n{} ", diff.right_highlights.normal.paint(">")).unwrap();
write!(buffer, "\n{} ", ">".paint(diff.right_highlights.normal)).unwrap();
diff.write_right(buffer);
buffer.push('\n');
},
LineDiff::Equal(text) => {
writeln!(buffer, " {}", Paint::default(text).dimmed()).unwrap();
writeln!(buffer, " {}", text.primary().on_primary().dim()).unwrap();
},
}
}
Expand Down Expand Up @@ -217,8 +217,8 @@ struct Highlighter {
impl Highlighter {
/// Create a new highlighter with the given color.
fn new(color: yansi::Color) -> Self {
let normal = yansi::Style::new(color);
let highlight = yansi::Style::new(yansi::Color::Black).bg(color).bold();
let normal = yansi::Style::new().fg(color);
let highlight = yansi::Style::new().fg(yansi::Color::Black).bg(color).bold();
Self {
ranges: Vec::new(),
total_highlighted: 0,
Expand Down Expand Up @@ -248,13 +248,13 @@ impl Highlighter {
fn write_highlighted(&self, buffer: &mut String, data: &str) {
let not_highlighted = data.len() - self.total_highlighted;
if not_highlighted < div_ceil(self.total_highlighted, 2) {
write!(buffer, "{}", self.normal.paint(data)).unwrap();
write!(buffer, "{}", data.paint(self.normal)).unwrap();
} else {
for (highlight, range) in self.ranges.iter().cloned() {
let piece = if highlight {
self.highlight.paint(&data[range])
data[range].paint(self.highlight)
} else {
self.normal.paint(&data[range])
data[range].paint(self.normal)
};
write!(buffer, "{}", piece).unwrap();
}
Expand Down
14 changes: 7 additions & 7 deletions src/__assert2_impl/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl<'a, T: CheckExpression> FailedCheck<'a, T> {
pub fn print(&self) {
let mut print_message = String::new();
writeln!(&mut print_message, "{msg} at {file}:{line}:{column}:",
msg = Paint::red("Assertion failed").bold(),
file = Paint::default(self.file).bold(),
msg = "Assertion failed".red().bold(),
file = self.file.bold(),
line = self.line,
column = self.column,
).unwrap();
Expand All @@ -73,7 +73,7 @@ impl<'a, T: CheckExpression> FailedCheck<'a, T> {
writeln!(&mut print_message, ).unwrap();
if let Some(msg) = self.custom_msg {
writeln!(&mut print_message, "with message:").unwrap();
writeln!(&mut print_message, " {}", Paint::default(msg).bold()).unwrap();
writeln!(&mut print_message, " {}", msg.bold()).unwrap();
}
writeln!(&mut print_message).unwrap();

Expand Down Expand Up @@ -106,9 +106,9 @@ impl<Left: Debug, Right: Debug> CheckExpression for BinaryOp<'_, Left, Right> {
diff.write_right(print_message);
if left == right {
if self.operator == "==" {
write!(print_message, "\n{}", Paint::red("Note: Left and right compared as unequal, but the Debug output of left and right is identical!")).unwrap();
write!(print_message, "\n{}", "Note: Left and right compared as unequal, but the Debug output of left and right is identical!".red()).unwrap();
} else {
write!(print_message, "\n{}", Paint::default("Note: Debug output of left and right is identical.").bold()).unwrap();
write!(print_message, "\n{}", "Note: Debug output of left and right is identical.".bold()).unwrap();
}
}
return
Expand All @@ -132,7 +132,7 @@ impl CheckExpression for BooleanExpr<'_> {

fn write_expansion(&self, print_message: &mut String) {
writeln!(print_message, "with expansion:").unwrap();
write!(print_message, " {:?}", Paint::cyan(false)).unwrap();
write!(print_message, " {:?}", false.cyan()).unwrap();
}
}

Expand All @@ -152,7 +152,7 @@ impl<Value: Debug> CheckExpression for MatchExpr<'_, Value> {
fn write_expansion(&self, print_message: &mut String) {
writeln!(print_message, "with expansion:").unwrap();
let [value] = AssertOptions::get().expand.expand_all([&self.value]);
let message = Paint::yellow(value).to_string();
let message = value.yellow().to_string();
for line in message.lines() {
writeln!(print_message, " {line}").unwrap();
}
Expand Down
4 changes: 2 additions & 2 deletions src/__assert2_impl/print/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ impl AssertOptions {
Ok(mut style) => {
let style = style.get_or_insert_with(AssertOptions::from_env);
if style.color {
yansi::Paint::enable()
yansi::whenever(yansi::Condition::ALWAYS)
} else {
yansi::Paint::disable()
yansi::whenever(yansi::Condition::NEVER)
}
return *style;
}
Expand Down

0 comments on commit 95569ae

Please sign in to comment.