diff --git a/Cargo.toml b/Cargo.toml index 97f9eb7..ee528a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ rust-version = "1.70" no-color = [] [dependencies] -lazy_static = "1" [target.'cfg(windows)'.dependencies.windows-sys] version = "0.48" diff --git a/src/control.rs b/src/control.rs index da09888..c48a3f3 100644 --- a/src/control.rs +++ b/src/control.rs @@ -4,6 +4,7 @@ use std::default::Default; use std::env; use std::io::{self, IsTerminal}; use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::OnceLock; /// Sets a flag to the console to use a virtual terminal environment. /// @@ -69,18 +70,19 @@ pub struct ShouldColorize { /// Use this to force colored to ignore the environment and always/never colorize /// See example/control.rs pub fn set_override(override_colorize: bool) { - SHOULD_COLORIZE.set_override(override_colorize) + should_colorize_global().set_override(override_colorize) } /// Remove the manual override and let the environment decide if it's ok to colorize /// See example/control.rs pub fn unset_override() { - SHOULD_COLORIZE.unset_override() + should_colorize_global().unset_override() } -lazy_static! { /// The persistent [`ShouldColorize`]. - pub static ref SHOULD_COLORIZE: ShouldColorize = ShouldColorize::from_env(); +pub fn should_colorize_global() -> &'static ShouldColorize { + static SHOULD_COLORIZE: OnceLock = OnceLock::new(); + SHOULD_COLORIZE.get_or_init(ShouldColorize::from_env) } impl Default for ShouldColorize { diff --git a/src/lib.rs b/src/lib.rs index 6942868..b5a02f7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,9 +29,6 @@ //! modify them. #![warn(missing_docs)] -#[macro_use] -extern crate lazy_static; - #[cfg(test)] extern crate rspec; @@ -491,7 +488,7 @@ impl ColoredString { #[cfg(not(feature = "no-color"))] fn has_colors(&self) -> bool { - control::SHOULD_COLORIZE.should_colorize() + control::should_colorize_global().should_colorize() } #[cfg(feature = "no-color")]