Skip to content

Commit

Permalink
switch colored to owo-colors
Browse files Browse the repository at this point in the history
  • Loading branch information
klensy committed Jun 21, 2024
1 parent 67135b2 commit 3733106
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 101 deletions.
112 changes: 26 additions & 86 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ doctest = false # but no doc tests

[dependencies]
rustc_version = "0.4"
colored = "2"
owo-colors = "3.5"
lazy_static = "1.4.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand All @@ -29,6 +29,7 @@ prettydiff = { version = "0.7", default_features = false }
annotate-snippets = { version = "0.11.2" }
levenshtein = "1.0.5"
spanned = "0.2.1"
supports-color = "3.0"

[dependencies.regex]
version = "1.5.5"
Expand Down
6 changes: 4 additions & 2 deletions src/diff.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use colored::*;
use owo_colors::OwoColorize;
use prettydiff::{basic::DiffOp, basic::DiffOp::*, diff_lines, diff_words};

/// How many lines of context are displayed around the actual diffs
Expand Down Expand Up @@ -52,10 +52,12 @@ fn row(row: DiffOp<'_, &str>) {
}

fn print_line_diff(l: &str, r: &str) {
use supports_color::Stream;

let diff = diff_words(l, r);
let diff = diff.diff();
if has_both_insertions_and_deletions(&diff)
|| !colored::control::SHOULD_COLORIZE.should_colorize()
|| !supports_color::on_cached(Stream::Stdout).map_or(false, |support| support.has_basic)
{
// The line both adds and removes chars, print both lines, but highlight their differences instead of
// drawing the entire line in red/green.
Expand Down
26 changes: 14 additions & 12 deletions src/status_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
use annotate_snippets::{Renderer, Snippet};
use bstr::ByteSlice;
use colored::Colorize;
use crossbeam_channel::{Sender, TryRecvError};
use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle};
use owo_colors::OwoColorize;
use spanned::Span;

use crate::{
Expand Down Expand Up @@ -305,13 +305,12 @@ impl TestStatus for TextTest {
self.text.sender.send(Msg::Inc).unwrap();
self.text.sender.send(Msg::Pop(self.msg(), None)).unwrap();
} else {
let result = match result {
Ok(TestOk::Ok) => "ok".green(),
Err(Errored { .. }) => "FAILED".bright_red().bold(),
Ok(TestOk::Ignored) => "ignored (in-test comment)".yellow(),
};
let old_msg = self.msg();
let msg = format!("... {result}");
let msg = match result {
Ok(TestOk::Ok) => format!("... {}", "ok".green()),
Err(Errored { .. }) => format!("... {}", "FAILED".bright_red().bold()),
Ok(TestOk::Ignored) => format!("... {}", "ignored (in-test comment)".yellow()),
};
if ProgressDrawTarget::stdout().is_hidden() {
println!("{old_msg} {msg}");
std::io::stdout().flush().unwrap();
Expand Down Expand Up @@ -705,6 +704,8 @@ fn create_error(
lines: &[(&[(&str, Option<Span>)], NonZeroUsize)],
file: &Path,
) {
use supports_color::Stream;

let source = std::fs::read_to_string(file).unwrap();
let source: Vec<_> = source.split_inclusive('\n').collect();
let file = file.display().to_string();
Expand Down Expand Up @@ -744,11 +745,12 @@ fn create_error(
}));
msg = msg.snippet(snippet);
}
let renderer = if colored::control::SHOULD_COLORIZE.should_colorize() {
Renderer::styled()
} else {
Renderer::plain()
};
let renderer =
if supports_color::on_cached(Stream::Stdout).map_or(false, |support| support.has_basic) {
Renderer::styled()
} else {
Renderer::plain()
};
println!("{}", renderer.render(msg));
}

Expand Down

0 comments on commit 3733106

Please sign in to comment.