diff options
author | VishnuJin <45007338+VishnuJin@users.noreply.github.com> | 2021-12-10 19:35:40 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-10 15:05:40 +0100 |
commit | 38f163022373c9adb050f17140f7d29bb403abe2 (patch) | |
tree | 02070c54dc413e537ca5117557077422f4eb4024 | |
parent | 542b71eef9fafe627adec5b05f6fe76edd8a1f2a (diff) |
fix(cli): don't add colors for non-tty outputs (#13031)
-rw-r--r-- | runtime/colors.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/runtime/colors.rs b/runtime/colors.rs index 00241b4e0..54bc0abe6 100644 --- a/runtime/colors.rs +++ b/runtime/colors.rs @@ -9,11 +9,14 @@ use termcolor::{Ansi, ColorSpec, WriteColor}; use termcolor::{BufferWriter, ColorChoice}; lazy_static::lazy_static! { +// checks if the output is piped to a tty + static ref IS_TTY: bool = atty::is(atty::Stream::Stdout); static ref NO_COLOR: bool = std::env::var_os("NO_COLOR").is_some(); } +// if the output is piped to a tty, use color pub fn use_color() -> bool { - !(*NO_COLOR) + !(*NO_COLOR) && *IS_TTY } #[cfg(windows)] |