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 660cf7f commit 4db5e87
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 18 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
11 changes: 5 additions & 6 deletions src/fmt/writer/atty.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/fmt/writer/termcolor/mod.rs
Original file line number Diff line number Diff line change
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 4db5e87

Please sign in to comment.