diff options
Diffstat (limited to 'runtime/colors.rs')
-rw-r--r-- | runtime/colors.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/runtime/colors.rs b/runtime/colors.rs index f2dbf22bd..196e522e4 100644 --- a/runtime/colors.rs +++ b/runtime/colors.rs @@ -1,5 +1,6 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +use atty; use once_cell::sync::Lazy; use std::fmt; use std::io::Write; @@ -12,6 +13,12 @@ use termcolor::{BufferWriter, ColorChoice}; static NO_COLOR: Lazy<bool> = Lazy::new(|| std::env::var_os("NO_COLOR").is_some()); +static IS_TTY: Lazy<bool> = Lazy::new(|| atty::is(atty::Stream::Stdout)); + +pub fn is_tty() -> bool { + *IS_TTY +} + pub fn use_color() -> bool { !(*NO_COLOR) } |