add config option to disable console colors (#707)
This commit is contained in:
parent
f635c09095
commit
5f73d47fb9
|
@ -3,6 +3,7 @@
|
|||
# Release notes
|
||||
## Upcoming release
|
||||
* For players:
|
||||
* Added config option to disable console colors.
|
||||
* Updated compatibility list.
|
||||
|
||||
* For the Console Commands mod:
|
||||
|
|
|
@ -88,8 +88,8 @@ namespace StardewModdingApi.Installer
|
|||
yield return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "ErrorLogs"); // remove old log files
|
||||
}
|
||||
|
||||
/// <summary>Handles writing color-coded text to the console.</summary>
|
||||
private ColorfulConsoleWriter ConsoleWriter;
|
||||
/// <summary>Handles writing text to the console.</summary>
|
||||
private IConsoleWriter ConsoleWriter;
|
||||
|
||||
|
||||
/*********
|
||||
|
|
|
@ -4,8 +4,8 @@ using StardewModdingAPI.Toolkit.Utilities;
|
|||
|
||||
namespace StardewModdingAPI.Internal.ConsoleWriting
|
||||
{
|
||||
/// <summary>Provides a wrapper for writing color-coded text to the console.</summary>
|
||||
internal class ColorfulConsoleWriter
|
||||
/// <summary>Writes color-coded text to the console.</summary>
|
||||
internal class ColorfulConsoleWriter : IConsoleWriter
|
||||
{
|
||||
/*********
|
||||
** Fields
|
||||
|
@ -30,8 +30,16 @@ namespace StardewModdingAPI.Internal.ConsoleWriting
|
|||
/// <param name="colorConfig">The colors to use for text written to the SMAPI console.</param>
|
||||
public ColorfulConsoleWriter(Platform platform, ColorSchemeConfig colorConfig)
|
||||
{
|
||||
this.SupportsColor = this.TestColorSupport();
|
||||
this.Colors = this.GetConsoleColorScheme(platform, colorConfig);
|
||||
if (colorConfig.UseScheme == MonitorColorScheme.None)
|
||||
{
|
||||
this.SupportsColor = false;
|
||||
this.Colors = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.SupportsColor = this.TestColorSupport();
|
||||
this.Colors = this.GetConsoleColorScheme(platform, colorConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Write a message line to the log.</summary>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
namespace StardewModdingAPI.Internal.ConsoleWriting
|
||||
{
|
||||
/// <summary>Writes text to the console.</summary>
|
||||
internal interface IConsoleWriter
|
||||
{
|
||||
/// <summary>Write a message line to the log.</summary>
|
||||
/// <param name="message">The message to log.</param>
|
||||
/// <param name="level">The log level.</param>
|
||||
void WriteLine(string message, ConsoleLogLevel level);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,9 @@ namespace StardewModdingAPI.Internal.ConsoleWriting
|
|||
DarkBackground,
|
||||
|
||||
/// <summary>Use darker text colors that look better on a white or light background.</summary>
|
||||
LightBackground
|
||||
LightBackground,
|
||||
|
||||
/// <summary>Disable console color.</summary>
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)ConsoleWriting\ColorfulConsoleWriter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ConsoleWriting\ColorSchemeConfig.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ConsoleWriting\ConsoleLogLevel.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ConsoleWriting\IConsoleWriter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)ConsoleWriting\MonitorColorScheme.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -81,7 +81,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SMAPI.Web.LegacyRedirects",
|
|||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
SMAPI.Internal\SMAPI.Internal.projitems*{0634ea4c-3b8f-42db-aea6-ca9e4ef6e92f}*SharedItemsImports = 5
|
||||
SMAPI.Internal\SMAPI.Internal.projitems*{0a9bb24f-15ff-4c26-b1a2-81f7ae316518}*SharedItemsImports = 5
|
||||
SMAPI.Internal\SMAPI.Internal.projitems*{1b3821e6-d030-402c-b3a1-7ca45c2800ea}*SharedItemsImports = 5
|
||||
SMAPI.Internal\SMAPI.Internal.projitems*{80efd92f-728f-41e0-8a5b-9f6f49a91899}*SharedItemsImports = 5
|
||||
SMAPI.Internal\SMAPI.Internal.projitems*{85208f8d-6fd1-4531-be05-7142490f59fe}*SharedItemsImports = 13
|
||||
SMAPI.Internal\SMAPI.Internal.projitems*{cd53ad6f-97f4-4872-a212-50c2a0fd3601}*SharedItemsImports = 5
|
||||
SMAPI.Internal\SMAPI.Internal.projitems*{e6da2198-7686-4f1d-b312-4a4dc70884c0}*SharedItemsImports = 5
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
|
|
@ -15,8 +15,8 @@ namespace StardewModdingAPI.Framework
|
|||
/// <summary>The name of the module which logs messages using this instance.</summary>
|
||||
private readonly string Source;
|
||||
|
||||
/// <summary>Handles writing color-coded text to the console.</summary>
|
||||
private readonly ColorfulConsoleWriter ConsoleWriter;
|
||||
/// <summary>Handles writing text to the console.</summary>
|
||||
private readonly IConsoleWriter ConsoleWriter;
|
||||
|
||||
/// <summary>Manages access to the console output.</summary>
|
||||
private readonly ConsoleInterceptionManager ConsoleInterceptor;
|
||||
|
|
|
@ -73,6 +73,7 @@ copy all the settings, or you may cause bugs due to overridden changes in future
|
|||
* automatically on Linux or Windows.
|
||||
* - LightBackground: use darker text colors that look better on a white or light background.
|
||||
* - DarkBackground: use lighter text colors that look better on a black or dark background.
|
||||
* - None: disables all colors, so everything is written in the default terminal color.
|
||||
*
|
||||
* For available color codes, see https://docs.microsoft.com/en-us/dotnet/api/system.consolecolor.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue