Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/BenchmarkDotNet/Loggers/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> 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<LogKind, ConsoleColor> colorScheme;
Expand Down Expand Up @@ -45,7 +50,7 @@ private void Write(LogKind logKind, Action<string> write, string text)
if (!unicodeSupport)
text = text.ToAscii();

if (!ConsoleSupportsColors)
if (!ConsoleSupportsColors.Value)
{
write(text);
return;
Expand Down