mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 08:52:50 +08:00
Uses OSVersion instead of RegEx to detect Windows Build info
Perf improvement.
This commit is contained in:
parent
6bceac8a5e
commit
c765bbd0dd
@ -15,25 +15,27 @@ namespace Spectre.Console
|
||||
// No colors supported
|
||||
return ColorSystem.NoColors;
|
||||
}
|
||||
else 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 (major > 10)
|
||||
{
|
||||
// Future Patrik will thank me.
|
||||
return ColorSystem.TrueColor;
|
||||
}
|
||||
|
||||
if (major == 10 && int.TryParse(match.Groups["build"].Value, out var build) && build >= 15063)
|
||||
{
|
||||
return ColorSystem.TrueColor;
|
||||
}
|
||||
}
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
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 && build >= 15063)
|
||||
{
|
||||
return ColorSystem.TrueColor;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user