From 3246e816b1d9a103847a178f370a65a3718e1e5f Mon Sep 17 00:00:00 2001 From: filzrev <103790468+filzrev@users.noreply.github.com> Date: Thu, 20 Nov 2025 18:07:11 +0900 Subject: [PATCH] chore: add NO_COLOR environment variable support --- src/BenchmarkDotNet/Loggers/ConsoleLogger.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/BenchmarkDotNet/Loggers/ConsoleLogger.cs b/src/BenchmarkDotNet/Loggers/ConsoleLogger.cs index d201f5da75..e760a1b0c8 100644 --- a/src/BenchmarkDotNet/Loggers/ConsoleLogger.cs +++ b/src/BenchmarkDotNet/Loggers/ConsoleLogger.cs @@ -15,8 +15,13 @@ public sealed class ConsoleLogger : ILogger public static readonly ILogger Default = new ConsoleLogger(); public static readonly ILogger Ascii = new ConsoleLogger(false); public static readonly ILogger Unicode = new ConsoleLogger(true); - private static readonly bool ConsoleSupportsColors - = !(OsDetector.IsAndroid() || OsDetector.IsIOS() || RuntimeInformation.IsWasm || OsDetector.IsTvOS()); + private static readonly Lazy ConsoleSupportsColors = new(() => + { + if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("NO_COLOR"))) + return false; + + return !(OsDetector.IsAndroid() || OsDetector.IsIOS() || RuntimeInformation.IsWasm || OsDetector.IsTvOS()); + }); private readonly bool unicodeSupport; private readonly Dictionary colorScheme; @@ -45,7 +50,7 @@ private void Write(LogKind logKind, Action write, string text) if (!unicodeSupport) text = text.ToAscii(); - if (!ConsoleSupportsColors) + if (!ConsoleSupportsColors.Value) { write(text); return;