perf: use libc to fetch env vars

This commit is contained in:
Uzair Aftab 2025-11-30 18:00:55 +01:00
commit 8376e9d323
No known key found for this signature in database
3 changed files with 42 additions and 28 deletions

View file

@ -1,4 +1,4 @@
use std::{env, sync::LazyLock};
use std::sync::LazyLock;
pub struct Colors {
pub reset: &'static str,
@ -37,8 +37,8 @@ impl Colors {
}
pub static COLORS: LazyLock<Colors> = LazyLock::new(|| {
// Check for NO_COLOR once at startup
let is_no_color = env::var("NO_COLOR").is_ok();
const NO_COLOR: *const libc::c_char = c"NO_COLOR".as_ptr();
let is_no_color = unsafe { !libc::getenv(NO_COLOR).is_null() };
Colors::new(is_no_color)
});