Uses OSVersion instead of RegEx to detect Windows Build info

Perf improvement.
This commit is contained in:
Phil Scott 2021-04-02 12:06:06 -04:00 committed by Patrik Svensson
parent 6bceac8a5e
commit c765bbd0dd

View File

@ -15,27 +15,29 @@ namespace Spectre.Console
// No colors supported
return ColorSystem.NoColors;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
if (supportsAnsi)
{
var regex = new Regex("^Microsoft Windows (?'major'[0-9]*).(?'minor'[0-9]*).(?'build'[0-9]*)\\s*$");
var match = regex.Match(RuntimeInformation.OSDescription);
if (match.Success && int.TryParse(match.Groups["major"].Value, out var major))
if (!supportsAnsi)
{
return ColorSystem.EightBit;
}
var os = Environment.OSVersion;
var major = os.Version.Major;
var build = os.Version.Minor;
if (major > 10)
{
// Future Patrik will thank me.
return ColorSystem.TrueColor;
}
if (major == 10 && int.TryParse(match.Groups["build"].Value, out var build) && build >= 15063)
if (major == 10 && build >= 15063)
{
return ColorSystem.TrueColor;
}
}
}
}
else
{
var colorTerm = Environment.GetEnvironmentVariable("COLORTERM");