Skip to content

Commit 4c37917

Browse files
authored
Merge pull request #248 from epage/atty
fix!: Replace atty with is_terminal
2 parents e572d04 + d55d269 commit 4c37917

File tree

12 files changed

+169
-39
lines changed

12 files changed

+169
-39
lines changed

.clippy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
msrv = "1.60.0" # MSRV

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ jobs:
5555
- name: Run crate example
5656
run: cargo run --example default
5757
msrv:
58-
name: "Check MSRV: 1.41.0"
58+
name: "Check MSRV: 1.60.0"
5959
runs-on: ubuntu-latest
6060
steps:
6161
- name: Checkout repository
6262
uses: actions/checkout@v3
6363
- name: Install Rust
6464
uses: actions-rs/toolchain@v1
6565
with:
66-
toolchain: 1.41.0 # MSRV
66+
toolchain: 1.60.0 # MSRV
6767
profile: minimal
6868
override: true
6969
- uses: Swatinem/rust-cache@v1
@@ -119,7 +119,7 @@ jobs:
119119
- name: Install Rust
120120
uses: actions-rs/toolchain@v1
121121
with:
122-
toolchain: 1.41.0 # MSRV
122+
toolchain: 1.60.0 # MSRV
123123
profile: minimal
124124
override: true
125125
components: clippy

Cargo.lock

Lines changed: 134 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ license = "MIT OR Apache-2.0"
1414
repository = "https://github.com/rust-cli/env_logger/"
1515
categories = ["development-tools::debugging"]
1616
keywords = ["logging", "log", "logger"]
17-
edition = "2018"
18-
rust-version = "1.41.0" # MSRV
17+
edition = "2021"
18+
rust-version = "1.60.0" # MSRV
1919
include = [
2020
"build.rs",
2121
"src/**/*",
@@ -37,14 +37,18 @@ pre-release-replacements = [
3737
]
3838

3939
[features]
40-
default = ["termcolor", "atty", "humantime", "regex"]
40+
default = ["auto-color", "humantime", "regex"]
41+
color = ["dep:termcolor"]
42+
auto-color = ["dep:is-terminal", "color"]
43+
humantime = ["dep:humantime"]
44+
regex = ["dep:regex"]
4145

4246
[dependencies]
4347
log = { version = "0.4.8", features = ["std"] }
4448
regex = { version = "1.0.3", optional = true, default-features=false, features=["std", "perf"] }
4549
termcolor = { version = "1.1.1", optional = true }
4650
humantime = { version = "2.0.0", optional = true }
47-
atty = { version = "0.2.5", optional = true }
51+
is-terminal = { version = "0.4.0", optional = true }
4852

4953
[[test]]
5054
name = "regexp_filter"

ci/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod permute;
22
mod task;
33

44
fn main() {
5-
let features = ["termcolor", "humantime", "atty", "regex"];
5+
let features = ["color", "humantime", "auto-color", "regex"];
66

77
// Run a default build
88
if !task::test(Default::default()) {

ci/src/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn test(args: TestArgs) -> bool {
5858
}
5959

6060
if let Some(features) = &features {
61-
command.args(&["--features", features]);
61+
command.args(["--features", features]);
6262
}
6363

6464
println!("running {:?}", command);

examples/custom_format.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $ export MY_LOG_STYLE=never
1717
If you want to control the logging output completely, see the `custom_logger` example.
1818
*/
1919

20-
#[cfg(all(feature = "termcolor", feature = "humantime"))]
20+
#[cfg(all(feature = "color", feature = "humantime"))]
2121
fn main() {
2222
use env_logger::{fmt::Color, Builder, Env};
2323

@@ -50,5 +50,5 @@ fn main() {
5050
log::info!("a log from `MyLogger`");
5151
}
5252

53-
#[cfg(not(all(feature = "termcolor", feature = "humantime")))]
53+
#[cfg(not(all(feature = "color", feature = "humantime")))]
5454
fn main() {}

src/fmt/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ impl Builder {
202202
}
203203
}
204204

205-
#[cfg(feature = "termcolor")]
205+
#[cfg(feature = "color")]
206206
type SubtleStyle = StyledValue<'static, &'static str>;
207-
#[cfg(not(feature = "termcolor"))]
207+
#[cfg(not(feature = "color"))]
208208
type SubtleStyle = &'static str;
209209

210210
/// The default format.
@@ -233,7 +233,7 @@ impl<'a> DefaultFormat<'a> {
233233
}
234234

235235
fn subtle_style(&self, text: &'static str) -> SubtleStyle {
236-
#[cfg(feature = "termcolor")]
236+
#[cfg(feature = "color")]
237237
{
238238
self.buf
239239
.style()
@@ -242,7 +242,7 @@ impl<'a> DefaultFormat<'a> {
242242
.clone()
243243
.into_value(text)
244244
}
245-
#[cfg(not(feature = "termcolor"))]
245+
#[cfg(not(feature = "color"))]
246246
{
247247
text
248248
}
@@ -268,11 +268,11 @@ impl<'a> DefaultFormat<'a> {
268268
}
269269

270270
let level = {
271-
#[cfg(feature = "termcolor")]
271+
#[cfg(feature = "color")]
272272
{
273273
self.buf.default_styled_level(record.level())
274274
}
275-
#[cfg(not(feature = "termcolor"))]
275+
#[cfg(not(feature = "color"))]
276276
{
277277
record.level()
278278
}

src/fmt/writer/atty.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
/*
22
This internal module contains the terminal detection implementation.
33
4-
If the `atty` crate is available then we use it to detect whether we're
5-
attached to a particular TTY. If the `atty` crate is not available we
6-
assume we're not attached to anything. This effectively prevents styles
7-
from being printed.
4+
If the `auto-color` feature is enabled then we detect whether we're attached to a particular TTY.
5+
Otherwise, assume we're not attached to anything. This effectively prevents styles from being
6+
printed.
87
*/
98

10-
#[cfg(feature = "atty")]
9+
#[cfg(feature = "auto-color")]
1110
mod imp {
11+
use is_terminal::IsTerminal;
12+
1213
pub(in crate::fmt) fn is_stdout() -> bool {
13-
atty::is(atty::Stream::Stdout)
14+
std::io::stdout().is_terminal()
1415
}
1516

1617
pub(in crate::fmt) fn is_stderr() -> bool {
17-
atty::is(atty::Stream::Stderr)
18+
std::io::stderr().is_terminal()
1819
}
1920
}
2021

21-
#[cfg(not(feature = "atty"))]
22+
#[cfg(not(feature = "auto-color"))]
2223
mod imp {
2324
pub(in crate::fmt) fn is_stdout() -> bool {
2425
false

src/fmt/writer/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ impl Builder {
165165
}
166166

167167
/// Whether or not to capture logs for `cargo test`.
168+
#[allow(clippy::wrong_self_convention)]
168169
pub(crate) fn is_test(&mut self, is_test: bool) -> &mut Self {
169170
self.is_test = is_test;
170171
self

src/fmt/writer/termcolor/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Its public API is available when the `termcolor` crate is available.
55
The terminal printing is shimmed when the `termcolor` crate is not available.
66
*/
77

8-
#[cfg_attr(feature = "termcolor", path = "extern_impl.rs")]
9-
#[cfg_attr(not(feature = "termcolor"), path = "shim_impl.rs")]
8+
#[cfg_attr(feature = "color", path = "extern_impl.rs")]
9+
#[cfg_attr(not(feature = "color"), path = "shim_impl.rs")]
1010
mod imp;
1111

1212
pub(in crate::fmt) use self::imp::*;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ pub fn init() {
11681168
/// ```
11691169
/// use env_logger::{Builder, Env};
11701170
///
1171-
/// # fn run() -> Result<(), Box<::std::error::Error>> {
1171+
/// # fn run() -> Result<(), Box<dyn ::std::error::Error>> {
11721172
/// let env = Env::new().filter("MY_LOG").write_style("MY_LOG_STYLE");
11731173
///
11741174
/// env_logger::try_init_from_env(env)?;

0 commit comments

Comments
 (0)