diff --git a/release-notes.md b/release-notes.md index 924ecb90..6e6d87ab 100644 --- a/release-notes.md +++ b/release-notes.md @@ -4,6 +4,7 @@ For players: * The SMAPI console is now much simpler and easier-to-read. +* The SMAPI console now uses more readable colors in terminals with a light background. For mod developers: * Added API to edit XNB images & data loaded by the game (see [API reference](http://stardewvalleywiki.com/Modding:SMAPI_APIs#Content)). diff --git a/src/StardewModdingAPI/Framework/Monitor.cs b/src/StardewModdingAPI/Framework/Monitor.cs index 5ae24a73..c2c3a689 100644 --- a/src/StardewModdingAPI/Framework/Monitor.cs +++ b/src/StardewModdingAPI/Framework/Monitor.cs @@ -25,15 +25,7 @@ namespace StardewModdingAPI.Framework private static readonly int MaxLevelLength = (from level in Enum.GetValues(typeof(LogLevel)).Cast() select level.ToString().Length).Max(); /// The console text color for each log level. - private static readonly Dictionary Colors = new Dictionary - { - [LogLevel.Trace] = ConsoleColor.DarkGray, - [LogLevel.Debug] = ConsoleColor.DarkGray, - [LogLevel.Info] = ConsoleColor.White, - [LogLevel.Warn] = ConsoleColor.Yellow, - [LogLevel.Error] = ConsoleColor.Red, - [LogLevel.Alert] = ConsoleColor.Magenta - }; + private static readonly IDictionary Colors = Monitor.GetConsoleColorScheme(); /// Propagates notification that SMAPI should exit. private readonly CancellationTokenSource ExitTokenSource; @@ -172,5 +164,56 @@ namespace StardewModdingAPI.Framework if (this.WriteToFile) this.LogFile.WriteLine(fullMessage); } + + /// Get the color scheme to use for the current console. + private static IDictionary GetConsoleColorScheme() + { +#if !SMAPI_1_x + // scheme for dark console background + if (Monitor.IsDark(Console.BackgroundColor)) + { +#endif + return new Dictionary + { + [LogLevel.Trace] = ConsoleColor.DarkGray, + [LogLevel.Debug] = ConsoleColor.DarkGray, + [LogLevel.Info] = ConsoleColor.White, + [LogLevel.Warn] = ConsoleColor.Yellow, + [LogLevel.Error] = ConsoleColor.Red, + [LogLevel.Alert] = ConsoleColor.Magenta + }; +#if !SMAPI_1_x + } + + // scheme for light console background + return new Dictionary + { + [LogLevel.Trace] = ConsoleColor.DarkGray, + [LogLevel.Debug] = ConsoleColor.DarkGray, + [LogLevel.Info] = ConsoleColor.Black, + [LogLevel.Warn] = ConsoleColor.DarkYellow, + [LogLevel.Error] = ConsoleColor.Red, + [LogLevel.Alert] = ConsoleColor.DarkMagenta + }; +#endif + } + + /// Get whether a console color should be considered dark, which is subjectively defined as 'white looks better than black on this text'. + /// The color to check. + private static bool IsDark(ConsoleColor color) + { + switch (color) + { + case ConsoleColor.Black: + case ConsoleColor.Blue: + case ConsoleColor.DarkBlue: + case ConsoleColor.DarkRed: + case ConsoleColor.Red: + return true; + + default: + return false; + } + } } }