diff options
Diffstat (limited to 'src/SMAPI.Internal/ConsoleWriting/ColorfulConsoleWriter.cs')
-rw-r--r-- | src/SMAPI.Internal/ConsoleWriting/ColorfulConsoleWriter.cs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/SMAPI.Internal/ConsoleWriting/ColorfulConsoleWriter.cs b/src/SMAPI.Internal/ConsoleWriting/ColorfulConsoleWriter.cs index 19a31c7b..78db0d65 100644 --- a/src/SMAPI.Internal/ConsoleWriting/ColorfulConsoleWriter.cs +++ b/src/SMAPI.Internal/ConsoleWriting/ColorfulConsoleWriter.cs @@ -1,7 +1,6 @@ -#nullable disable - using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using StardewModdingAPI.Toolkit.Utilities; namespace StardewModdingAPI.Internal.ConsoleWriting @@ -13,10 +12,11 @@ namespace StardewModdingAPI.Internal.ConsoleWriting ** Fields *********/ /// <summary>The console text color for each log level.</summary> - private readonly IDictionary<ConsoleLogLevel, ConsoleColor> Colors; + private readonly IDictionary<ConsoleLogLevel, ConsoleColor>? Colors; /// <summary>Whether the current console supports color formatting.</summary> - private readonly bool SupportsColor; + [MemberNotNullWhen(true, nameof(ColorfulConsoleWriter.Colors))] + private bool SupportsColor { get; } /********* @@ -74,10 +74,9 @@ namespace StardewModdingAPI.Internal.ConsoleWriting /// <remarks>The colors here should be kept in sync with the SMAPI config file.</remarks> public static ColorSchemeConfig GetDefaultColorSchemeConfig(MonitorColorScheme useScheme) { - return new ColorSchemeConfig - { - UseScheme = useScheme, - Schemes = new Dictionary<MonitorColorScheme, IDictionary<ConsoleLogLevel, ConsoleColor>> + return new ColorSchemeConfig( + useScheme: useScheme, + schemes: new Dictionary<MonitorColorScheme, IDictionary<ConsoleLogLevel, ConsoleColor>> { [MonitorColorScheme.DarkBackground] = new Dictionary<ConsoleLogLevel, ConsoleColor> { @@ -100,7 +99,7 @@ namespace StardewModdingAPI.Internal.ConsoleWriting [ConsoleLogLevel.Success] = ConsoleColor.DarkGreen } } - }; + ); } @@ -136,7 +135,7 @@ namespace StardewModdingAPI.Internal.ConsoleWriting } // get colors for scheme - return colorConfig.Schemes.TryGetValue(schemeID, out IDictionary<ConsoleLogLevel, ConsoleColor> scheme) + return colorConfig.Schemes.TryGetValue(schemeID, out IDictionary<ConsoleLogLevel, ConsoleColor>? scheme) ? scheme : throw new NotSupportedException($"Unknown color scheme '{schemeID}'."); } |