mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 17:02:51 +08:00
Uses OSVersion instead of RegEx to detect Windows Build info
Perf improvement.
This commit is contained in:
parent
6bceac8a5e
commit
c765bbd0dd
@ -15,27 +15,29 @@ namespace Spectre.Console
|
|||||||
// No colors supported
|
// No colors supported
|
||||||
return ColorSystem.NoColors;
|
return ColorSystem.NoColors;
|
||||||
}
|
}
|
||||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
if (supportsAnsi)
|
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))
|
|
||||||
{
|
{
|
||||||
|
return ColorSystem.EightBit;
|
||||||
|
}
|
||||||
|
|
||||||
|
var os = Environment.OSVersion;
|
||||||
|
var major = os.Version.Major;
|
||||||
|
var build = os.Version.Minor;
|
||||||
|
|
||||||
if (major > 10)
|
if (major > 10)
|
||||||
{
|
{
|
||||||
// Future Patrik will thank me.
|
// Future Patrik will thank me.
|
||||||
return ColorSystem.TrueColor;
|
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;
|
return ColorSystem.TrueColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var colorTerm = Environment.GetEnvironmentVariable("COLORTERM");
|
var colorTerm = Environment.GetEnvironmentVariable("COLORTERM");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user