From 4db5e8793162e33e17efce36057afaa41d988788 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 24 Nov 2022 09:56:36 -0600 Subject: [PATCH] fix!: Rename termcolor/atty features This makes it easier to change dependencies in the future. BREAKING CHANGE: `termcolor` -> `color` and `atty` -> `auto-color` --- Cargo.toml | 6 +++++- ci/src/main.rs | 2 +- examples/custom_format.rs | 4 ++-- src/fmt/mod.rs | 12 ++++++------ src/fmt/writer/atty.rs | 11 +++++------ src/fmt/writer/termcolor/mod.rs | 4 ++-- 6 files changed, 21 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d4cbd7d6..c47dbf75 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,11 @@ pre-release-replacements = [ ] [features] -default = ["termcolor", "atty", "humantime", "regex"] +default = ["auto-color", "humantime", "regex"] +color = ["dep:termcolor"] +auto-color = ["dep:atty", "color"] +humantime = ["dep:humantime"] +regex = ["dep:regex"] [dependencies] log = { version = "0.4.8", features = ["std"] } diff --git a/ci/src/main.rs b/ci/src/main.rs index e7280f1c..961a3141 100644 --- a/ci/src/main.rs +++ b/ci/src/main.rs @@ -2,7 +2,7 @@ mod permute; mod task; fn main() { - let features = ["termcolor", "humantime", "atty", "regex"]; + let features = ["color", "humantime", "auto-color", "regex"]; // Run a default build if !task::test(Default::default()) { diff --git a/examples/custom_format.rs b/examples/custom_format.rs index d8585a53..cc16b336 100644 --- a/examples/custom_format.rs +++ b/examples/custom_format.rs @@ -17,7 +17,7 @@ $ export MY_LOG_STYLE=never If you want to control the logging output completely, see the `custom_logger` example. */ -#[cfg(all(feature = "termcolor", feature = "humantime"))] +#[cfg(all(feature = "color", feature = "humantime"))] fn main() { use env_logger::{fmt::Color, Builder, Env}; @@ -50,5 +50,5 @@ fn main() { log::info!("a log from `MyLogger`"); } -#[cfg(not(all(feature = "termcolor", feature = "humantime")))] +#[cfg(not(all(feature = "color", feature = "humantime")))] fn main() {} diff --git a/src/fmt/mod.rs b/src/fmt/mod.rs index 1677887a..86c093f0 100644 --- a/src/fmt/mod.rs +++ b/src/fmt/mod.rs @@ -202,9 +202,9 @@ impl Builder { } } -#[cfg(feature = "termcolor")] +#[cfg(feature = "color")] type SubtleStyle = StyledValue<'static, &'static str>; -#[cfg(not(feature = "termcolor"))] +#[cfg(not(feature = "color"))] type SubtleStyle = &'static str; /// The default format. @@ -233,7 +233,7 @@ impl<'a> DefaultFormat<'a> { } fn subtle_style(&self, text: &'static str) -> SubtleStyle { - #[cfg(feature = "termcolor")] + #[cfg(feature = "color")] { self.buf .style() @@ -242,7 +242,7 @@ impl<'a> DefaultFormat<'a> { .clone() .into_value(text) } - #[cfg(not(feature = "termcolor"))] + #[cfg(not(feature = "color"))] { text } @@ -268,11 +268,11 @@ impl<'a> DefaultFormat<'a> { } let level = { - #[cfg(feature = "termcolor")] + #[cfg(feature = "color")] { self.buf.default_styled_level(record.level()) } - #[cfg(not(feature = "termcolor"))] + #[cfg(not(feature = "color"))] { record.level() } diff --git a/src/fmt/writer/atty.rs b/src/fmt/writer/atty.rs index 343539c1..58502168 100644 --- a/src/fmt/writer/atty.rs +++ b/src/fmt/writer/atty.rs @@ -1,13 +1,12 @@ /* This internal module contains the terminal detection implementation. -If the `atty` crate is available then we use it to detect whether we're -attached to a particular TTY. If the `atty` crate is not available we -assume we're not attached to anything. This effectively prevents styles -from being printed. +If the `auto-color` feature is enabled then we detect whether we're attached to a particular TTY. +Otherwise, assume we're not attached to anything. This effectively prevents styles from being +printed. */ -#[cfg(feature = "atty")] +#[cfg(feature = "auto-color")] mod imp { pub(in crate::fmt) fn is_stdout() -> bool { atty::is(atty::Stream::Stdout) @@ -18,7 +17,7 @@ mod imp { } } -#[cfg(not(feature = "atty"))] +#[cfg(not(feature = "auto-color"))] mod imp { pub(in crate::fmt) fn is_stdout() -> bool { false diff --git a/src/fmt/writer/termcolor/mod.rs b/src/fmt/writer/termcolor/mod.rs index f3e6768c..20f01979 100644 --- a/src/fmt/writer/termcolor/mod.rs +++ b/src/fmt/writer/termcolor/mod.rs @@ -5,8 +5,8 @@ Its public API is available when the `termcolor` crate is available. The terminal printing is shimmed when the `termcolor` crate is not available. */ -#[cfg_attr(feature = "termcolor", path = "extern_impl.rs")] -#[cfg_attr(not(feature = "termcolor"), path = "shim_impl.rs")] +#[cfg_attr(feature = "color", path = "extern_impl.rs")] +#[cfg_attr(not(feature = "color"), path = "shim_impl.rs")] mod imp; pub(in crate::fmt) use self::imp::*;