mirror of
				https://github.com/nsnail/spectre.console.git
				synced 2025-11-04 10:35:27 +08:00 
			
		
		
		
	Uses OSVersion instead of RegEx to detect Windows Build info
Perf improvement.
This commit is contained in:
		
				
					committed by
					
						
						Patrik Svensson
					
				
			
			
				
	
			
			
			
						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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user