예제 #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}'."));
        }
예제 #2
0
        /// <summary>Get the color scheme to use for the current console.</summary>
        /// <param name="platform">The target platform.</param>
        /// <param name="colorScheme">The console color scheme to use.</param>
        private IDictionary <ConsoleLogLevel, ConsoleColor> GetConsoleColorScheme(Platform platform, MonitorColorScheme colorScheme)
        {
            // auto detect color scheme
            if (colorScheme == MonitorColorScheme.AutoDetect)
            {
                colorScheme = 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
            switch (colorScheme)
            {
            case MonitorColorScheme.DarkBackground:
                return(new Dictionary <ConsoleLogLevel, ConsoleColor>
                {
                    [ConsoleLogLevel.Trace] = ConsoleColor.DarkGray,
                    [ConsoleLogLevel.Debug] = ConsoleColor.DarkGray,
                    [ConsoleLogLevel.Info] = ConsoleColor.White,
                    [ConsoleLogLevel.Warn] = ConsoleColor.Yellow,
                    [ConsoleLogLevel.Error] = ConsoleColor.Red,
                    [ConsoleLogLevel.Alert] = ConsoleColor.Magenta,
                    [ConsoleLogLevel.Success] = ConsoleColor.DarkGreen
                });

            case MonitorColorScheme.LightBackground:
                return(new Dictionary <ConsoleLogLevel, ConsoleColor>
                {
                    [ConsoleLogLevel.Trace] = ConsoleColor.DarkGray,
                    [ConsoleLogLevel.Debug] = ConsoleColor.DarkGray,
                    [ConsoleLogLevel.Info] = ConsoleColor.Black,
                    [ConsoleLogLevel.Warn] = ConsoleColor.DarkYellow,
                    [ConsoleLogLevel.Error] = ConsoleColor.Red,
                    [ConsoleLogLevel.Alert] = ConsoleColor.DarkMagenta,
                    [ConsoleLogLevel.Success] = ConsoleColor.DarkGreen
                });

            default:
                throw new NotSupportedException($"Unknown color scheme '{colorScheme}'.");
            }
        }