Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): use nu-ansi-term to replace ansi_term #2040

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bytes = "1"
argh = "0.1.5"

# sloggish example
ansi_term = "0.12"
nu-ansi-term = "0.45"
humantime = "2.0"
log = "0.4"

Expand Down
4 changes: 2 additions & 2 deletions examples/examples/sloggish/sloggish_collector.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ansi_term::{Color, Style};
use nu_ansi_term::{Color, Style};
use tracing::{
field::{Field, Visit},
Collect, Id, Level, Metadata,
Expand Down Expand Up @@ -120,7 +120,7 @@ impl<'a> Visit for Event<'a> {
write!(
&mut self.stderr,
"{}",
// Have to alloc here due to `ansi_term`'s API...
// Have to alloc here due to `nu-ansi-term`'s API...
Style::new().bold().paint(format!("{:?}", value))
)
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions tracing-subscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ alloc = []
std = ["alloc", "tracing-core/std"]
env-filter = ["matchers", "regex", "lazy_static", "tracing", "std", "thread_local"]
fmt = ["registry", "std"]
ansi = ["fmt", "ansi_term"]
ansi = ["fmt", "nu-ansi-term"]
registry = ["sharded-slab", "thread_local", "std"]
json = ["tracing-serde", "serde", "serde_json"]
# Enables support for local time when using the `time` crate timestamp
Expand All @@ -48,7 +48,7 @@ lazy_static = { optional = true, version = "1" }

# fmt
tracing-log = { path = "../tracing-log", version = "0.2", optional = true, default-features = false, features = ["log-tracer", "std"] }
ansi_term = { version = "0.12", optional = true }
nu-ansi-term = { version = "0.45", optional = true }
time = { version = "0.3", features = ["formatting"], optional = true }

# only required by the json feature
Expand Down
16 changes: 8 additions & 8 deletions tracing-subscriber/src/filter/env/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ impl Builder {
}

if !disabled.is_empty() {
#[cfg(feature = "ansi_term")]
use ansi_term::{Color, Style};
#[cfg(feature = "nu-ansi-term")]
use nu_ansi_term::{Color, Style};
// NOTE: We can't use a configured `MakeWriter` because the EnvFilter
// has no knowledge of any underlying subscriber or collector, which
// may or may not use a `MakeWriter`.
let warn = |msg: &str| {
#[cfg(not(feature = "ansi_term"))]
#[cfg(not(feature = "nu-ansi-term"))]
let msg = format!("warning: {}", msg);
#[cfg(feature = "ansi_term")]
#[cfg(feature = "nu-ansi-term")]
let msg = {
let bold = Style::new().bold();
let mut warning = Color::Yellow.paint("warning");
Expand All @@ -220,9 +220,9 @@ impl Builder {
eprintln!("{}", msg);
};
let ctx_prefixed = |prefix: &str, msg: &str| {
#[cfg(not(feature = "ansi_term"))]
#[cfg(not(feature = "nu-ansi-term"))]
let msg = format!("{} {}", prefix, msg);
#[cfg(feature = "ansi_term")]
#[cfg(feature = "nu-ansi-term")]
let msg = {
let mut equal = Color::Fixed(21).paint("="); // dark blue
equal.style_ref_mut().is_bold = true;
Expand All @@ -233,9 +233,9 @@ impl Builder {
let ctx_help = |msg| ctx_prefixed("help:", msg);
let ctx_note = |msg| ctx_prefixed("note:", msg);
let ctx = |msg: &str| {
#[cfg(not(feature = "ansi_term"))]
#[cfg(not(feature = "nu-ansi-term"))]
let msg = format!("note: {}", msg);
#[cfg(feature = "ansi_term")]
#[cfg(feature = "nu-ansi-term")]
let msg = {
let mut pipe = Color::Fixed(21).paint("|");
pipe.style_ref_mut().is_bold = true;
Expand Down
16 changes: 8 additions & 8 deletions tracing-subscriber/src/fmt/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use tracing_core::{
use tracing_log::NormalizeEvent;

#[cfg(feature = "ansi")]
use ansi_term::{Colour, Style};
use nu_ansi_term::{Color, Style};

#[cfg(feature = "json")]
mod json;
Expand Down Expand Up @@ -103,7 +103,7 @@ use fmt::{Debug, Display};
/// does not support ANSI escape codes (such as a log file), and they should
/// not be emitted.
///
/// Crates like [`ansi_term`] and [`owo-colors`] can be used to add ANSI
/// Crates like [`nu-ansi-term`] and [`owo-colors`] can be used to add ANSI
/// escape codes to formatted output.
///
/// * The actual [`Event`] to be formatted.
Expand Down Expand Up @@ -191,7 +191,7 @@ use fmt::{Debug, Display};
/// [implements `FormatFields`]: super::FmtContext#impl-FormatFields<'writer>
/// [ANSI terminal escape codes]: https://en.wikipedia.org/wiki/ANSI_escape_code
/// [`Writer::has_ansi_escapes`]: Writer::has_ansi_escapes
/// [`ansi_term`]: https://crates.io/crates/ansi_term
/// [`nu-ansi-term`]: https://crates.io/crates/nu-ansi-term
/// [`owo-colors`]: https://crates.io/crates/owo-colors
/// [default formatter]: Full
pub trait FormatEvent<C, N>
Expand Down Expand Up @@ -1402,11 +1402,11 @@ impl<'a, F: LevelNames> fmt::Display for FmtLevel<F> {
{
if self.ansi {
return match self.level {
Level::TRACE => write!(f, "{}", Colour::Purple.paint(F::TRACE_STR)),
Level::DEBUG => write!(f, "{}", Colour::Blue.paint(F::DEBUG_STR)),
Level::INFO => write!(f, "{}", Colour::Green.paint(F::INFO_STR)),
Level::WARN => write!(f, "{}", Colour::Yellow.paint(F::WARN_STR)),
Level::ERROR => write!(f, "{}", Colour::Red.paint(F::ERROR_STR)),
Level::TRACE => write!(f, "{}", Color::Purple.paint(F::TRACE_STR)),
Level::DEBUG => write!(f, "{}", Color::Blue.paint(F::DEBUG_STR)),
Level::INFO => write!(f, "{}", Color::Green.paint(F::INFO_STR)),
Level::WARN => write!(f, "{}", Color::Yellow.paint(F::WARN_STR)),
Level::ERROR => write!(f, "{}", Color::Red.paint(F::ERROR_STR)),
};
}
}
Expand Down
12 changes: 6 additions & 6 deletions tracing-subscriber/src/fmt/format/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use tracing_core::{
#[cfg(feature = "tracing-log")]
use tracing_log::NormalizeEvent;

use ansi_term::{Colour, Style};
use nu_ansi_term::{Color, Style};

/// An excessively pretty, human-readable event formatter.
///
Expand Down Expand Up @@ -143,11 +143,11 @@ impl Default for Pretty {
impl Pretty {
fn style_for(level: &Level) -> Style {
match *level {
Level::TRACE => Style::new().fg(Colour::Purple),
Level::DEBUG => Style::new().fg(Colour::Blue),
Level::INFO => Style::new().fg(Colour::Green),
Level::WARN => Style::new().fg(Colour::Yellow),
Level::ERROR => Style::new().fg(Colour::Red),
Level::TRACE => Style::new().fg(Color::Purple),
Level::DEBUG => Style::new().fg(Color::Blue),
Level::INFO => Style::new().fg(Color::Green),
Level::WARN => Style::new().fg(Color::Yellow),
Level::ERROR => Style::new().fg(Color::Red),
}
}

Expand Down