summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-01-14 15:05:38 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-01-14 15:05:38 -0500
commit90e92ef61f0808688abf638ee5cb941215c1586f (patch)
tree09e0b6734e867a61d31e934b7d40436a7dd970ca /src/StardewModdingAPI/Framework
parent2d824b34e478bd53a9cfae85332669755b326d84 (diff)
downloadSMAPI-90e92ef61f0808688abf638ee5cb941215c1586f.tar.gz
SMAPI-90e92ef61f0808688abf638ee5cb941215c1586f.tar.bz2
SMAPI-90e92ef61f0808688abf638ee5cb941215c1586f.zip
fix error when the console doesn't support colour (#206)
Diffstat (limited to 'src/StardewModdingAPI/Framework')
-rw-r--r--src/StardewModdingAPI/Framework/Monitor.cs28
1 files changed, 25 insertions, 3 deletions
diff --git a/src/StardewModdingAPI/Framework/Monitor.cs b/src/StardewModdingAPI/Framework/Monitor.cs
index 0989bb7e..b492e5c7 100644
--- a/src/StardewModdingAPI/Framework/Monitor.cs
+++ b/src/StardewModdingAPI/Framework/Monitor.cs
@@ -34,6 +34,9 @@ namespace StardewModdingAPI.Framework
/*********
** Accessors
*********/
+ /// <summary>Whether the current console supports color codes.</summary>
+ internal static readonly bool ConsoleSupportsColor = Monitor.GetConsoleSupportsColor();
+
/// <summary>Whether to show trace messages in the console.</summary>
internal bool ShowTraceInConsole { get; set; }
@@ -113,11 +116,30 @@ namespace StardewModdingAPI.Framework
// log
if (this.WriteToConsole && (this.ShowTraceInConsole || level != LogLevel.Trace))
{
- Console.ForegroundColor = color;
- Console.WriteLine(message);
- Console.ResetColor();
+ if (Monitor.ConsoleSupportsColor)
+ {
+ Console.ForegroundColor = color;
+ Console.WriteLine(message);
+ Console.ResetColor();
+ }
+ else
+ Console.WriteLine(message);
}
this.LogFile.WriteLine(message);
}
+
+ /// <summary>Test whether the current console supports color formatting.</summary>
+ private static bool GetConsoleSupportsColor()
+ {
+ try
+ {
+ Console.ResetColor();
+ return true;
+ }
+ catch (Exception)
+ {
+ return false;
+ }
+ }
}
} \ No newline at end of file