add tracing

This commit is contained in:
Qyriad 2026-02-02 17:43:44 +01:00
parent 9ae0630db4
commit a06790a2af
7 changed files with 413 additions and 17 deletions

View file

@ -6,10 +6,14 @@ use std::{
#[allow(unused_imports)]
use crate::prelude::*;
pub static CLI_ENABLE_COLOR: OnceLock<bool> = OnceLock::new();
/// The actual, final value for whether color should be used, based on CLI and environment values.
pub static SHOULD_COLOR: LazyLock<bool> = LazyLock::new(|| is_clicolor_forced() || is_color_reqd());
/// Initialized from the `--color` value from the CLI, along with `io::stdin().is_terminal()`.
pub static _CLI_ENABLE_COLOR: OnceLock<bool> = OnceLock::new();
fn is_color_reqd() -> bool {
CLI_ENABLE_COLOR.get().copied().unwrap_or(false)
_CLI_ENABLE_COLOR.get().copied().unwrap_or(false)
}
fn is_clicolor_forced() -> bool {
@ -24,8 +28,6 @@ fn is_clicolor_forced() -> bool {
.unwrap_or(false)
}
pub static SHOULD_COLOR: LazyLock<bool> = LazyLock::new(|| is_clicolor_forced() || is_color_reqd());
/// Silly wrapper around LazyLock<&'static str> to impl Display.
pub(crate) struct _LazyLockDisplay(LazyLock<&'static str>);
impl Display for _LazyLockDisplay {
@ -47,8 +49,5 @@ pub(crate) const ANSI_CYAN: _LazyLockDisplay = _LazyLockDisplay(LazyLock::new(||
}));
pub(crate) const ANSI_RESET: _LazyLockDisplay = _LazyLockDisplay(LazyLock::new(|| {
SHOULD_COLOR
// C'mon rustfmt, just format it to match ^.
.then_some("\x1b[0m")
.unwrap_or_default()
SHOULD_COLOR.then_some("\x1b[0m").unwrap_or_default()
}));