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

fmt: call nu_ansi_term::enable_ansi_support for windows #3079

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions tracing-subscriber/src/fmt/fmt_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,18 @@ impl<C, N, E, W> Subscriber<C, N, E, W> {
/// [`with_ansi`]: Subscriber::with_ansi
/// [`set_ansi`]: Subscriber::set_ansi
pub fn with_ansi(self, ansi: bool) -> Self {
#[cfg(not(feature = "ansi"))]
if ansi {
const ERROR: &str =
"tracing-subscriber: the `ansi` crate feature is required to enable ANSI terminal colors";
#[cfg(debug_assertions)]
panic!("{}", ERROR);
#[cfg(not(debug_assertions))]
eprintln!("{}", ERROR);
#[cfg(not(feature = "ansi"))]
{
const ERROR: &str =
"tracing-subscriber: the `ansi` crate feature is required to enable ANSI terminal colors";
#[cfg(debug_assertions)]
panic!("{}", ERROR);
#[cfg(not(debug_assertions))]
eprintln!("{}", ERROR);
}
#[cfg(target_os = "windows")]
nu_ansi_term::enable_ansi_support();
}

Subscriber {
Expand Down Expand Up @@ -571,6 +575,8 @@ where
#[cfg(feature = "ansi")]
#[cfg_attr(docsrs, doc(cfg(feature = "ansi")))]
pub fn pretty(self) -> Subscriber<C, format::Pretty, format::Format<format::Pretty, T>, W> {
#[cfg(target_os = "windows")]
nu_ansi_term::enable_ansi_support();
Subscriber {
fmt_event: self.fmt_event.pretty(),
fmt_fields: format::Pretty::default(),
Expand Down
4 changes: 4 additions & 0 deletions tracing-subscriber/src/fmt/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,10 @@ impl<F, T> Format<F, T> {

/// Enable ANSI terminal colors for formatted output.
pub fn with_ansi(self, ansi: bool) -> Format<F, T> {
if ansi {
#[cfg(target_os = "windows")]
nu_ansi_term::enable_ansi_support();
}
Format {
ansi: Some(ansi),
..self
Expand Down
6 changes: 6 additions & 0 deletions tracing-subscriber/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,10 @@ where
/// whether or not other crates in the dependency graph enable the "ansi"
/// feature flag.
pub fn with_ansi(self, ansi: bool) -> CollectorBuilder<N, format::Format<L, T>, F, W> {
if ansi {
#[cfg(target_os = "windows")]
nu_ansi_term::enable_ansi_support();
}
CollectorBuilder {
inner: self.inner.with_ansi(ansi),
..self
Expand Down Expand Up @@ -750,6 +754,8 @@ where
pub fn pretty(
self,
) -> CollectorBuilder<format::Pretty, format::Format<format::Pretty, T>, F, W> {
#[cfg(target_os = "windows")]
nu_ansi_term::enable_ansi_support();
CollectorBuilder {
filter: self.filter,
inner: self.inner.pretty(),
Expand Down
Loading