コード例 #1
0
        /// <summary>Get the color scheme to use for the current console.</summary>
        /// <param name="platform">The target platform.</param>
        /// <param name="colorConfig">The colors to use for text written to the SMAPI console.</param>
        private IDictionary <ConsoleLogLevel, ConsoleColor> GetConsoleColorScheme(Platform platform, ColorSchemeConfig colorConfig)
        {
            // get color scheme ID
            MonitorColorScheme schemeID = colorConfig.UseScheme;

            if (schemeID == MonitorColorScheme.AutoDetect)
            {
                schemeID = platform == Platform.Mac
                    ? MonitorColorScheme.LightBackground // macOS doesn't provide console background color info, but it's usually white.
                    : ColorfulConsoleWriter.IsDark(Console.BackgroundColor) ? MonitorColorScheme.DarkBackground : MonitorColorScheme.LightBackground;
            }

            // get colors for scheme
            return(colorConfig.Schemes.TryGetValue(schemeID, out IDictionary <ConsoleLogLevel, ConsoleColor> scheme)
                ? scheme
                : throw new NotSupportedException($"Unknown color scheme '{schemeID}'."));
        }