Skip to content

Commit

Permalink
fix!: Rename termcolor/atty features
Browse files Browse the repository at this point in the history
This makes it easier to change dependencies in the future.

BREAKING CHANGE: `termcolor` -> `color` and `atty` -> `auto-color`
  • Loading branch information
epage committed Nov 24, 2022
1 parent f18c338 commit 2e88dc2
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion ci/src/main.rs
Expand Up @@ -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()) {
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_format.rs
Expand Up @@ -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};

Expand Down Expand Up @@ -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() {}
12 changes: 6 additions & 6 deletions src/fmt/mod.rs
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand All @@ -242,7 +242,7 @@ impl<'a> DefaultFormat<'a> {
.clone()
.into_value(text)
}
#[cfg(not(feature = "termcolor"))]
#[cfg(not(feature = "color"))]
{
text
}
Expand All @@ -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()
}
Expand Down
4 changes: 2 additions & 2 deletions src/fmt/writer/atty.rs
Expand Up @@ -7,7 +7,7 @@ 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)
Expand All @@ -18,7 +18,7 @@ mod imp {
}
}

#[cfg(not(feature = "atty"))]
#[cfg(not(feature = "auto-color"))]
mod imp {
pub(in crate::fmt) fn is_stdout() -> bool {
false
Expand Down
4 changes: 2 additions & 2 deletions src/fmt/writer/termcolor/mod.rs
Expand Up @@ -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::*;

0 comments on commit 2e88dc2

Please sign in to comment.