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 Mar 8, 2024
1 parent 0e7aa42 commit 665fbb6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 104 deletions.
136 changes: 47 additions & 89 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 @@ -30,6 +30,7 @@ prettydiff = { version = "0.6.4", default_features = false }
annotate-snippets = { version = "0.10.0" }
levenshtein = "1.0.5"
spanned = "0.1.6"
supports-color = "2.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::{Annotation, AnnotationType, Renderer, Slice, Snippet, SourceAnnotation};
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 @@ -213,13 +213,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 @@ -592,6 +591,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 @@ -639,11 +640,12 @@ fn create_error(
.collect(),
footer: vec![],
};
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 665fbb6

Please sign in to comment.