forked from rust-cli/env_logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atty.rs
36 lines (28 loc) · 835 Bytes
/
atty.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
This internal module contains the terminal detection implementation.
If the `is-terminal` crate is available then we use it to detect whether
we're attached to a particular TTY. If the `is-terminal` crate is not
available we assume we're not attached to anything. This effectively
prevents styles from being printed.
*/
#[cfg(feature = "is-terminal")]
mod imp {
use std::io::{stderr, stdout};
use is_terminal::IsTerminal;
pub(in crate::fmt) fn is_stdout() -> bool {
stdout().is_terminal()
}
pub(in crate::fmt) fn is_stderr() -> bool {
stderr().is_terminal()
}
}
#[cfg(not(feature = "is-terminal"))]
mod imp {
pub(in crate::fmt) fn is_stdout() -> bool {
false
}
pub(in crate::fmt) fn is_stderr() -> bool {
false
}
}
pub(in crate::fmt) use self::imp::*;