use std::env;
use std::sync::atomic::{AtomicBool, Ordering};
#[cfg(unix)]
pub use unix::*;
#[cfg(windows)]
pub use windows::*;
pub fn enable_colors_by_default() -> bool {
(is_a_color_terminal() && &env::var("CLICOLOR").unwrap_or("1".into()) != "0") ||
&env::var("CLICOLOR_FORCE").unwrap_or("0".into()) != "0"
}
lazy_static! {
static ref ENABLE_COLORS: AtomicBool =
AtomicBool::new(enable_colors_by_default());
}
pub fn colors_enabled() -> bool {
ENABLE_COLORS.load(Ordering::Relaxed)
}
pub fn set_colors_enabled(val: bool) {
ENABLE_COLORS.store(val, Ordering::Relaxed)
}
pub fn configure_terminal() -> bool {
#[cfg(windows)]
{
if enable_ansi_mode() {
set_colors_enabled(enable_colors_by_default());
true
} else {
false
}
}
#[cfg(not(windows))]
{
true
}
}