diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dc1c97..9cf8822 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Changed + - Fixed a bug where ANSI color encoded strings with percentages were being scrambled + ## [9.7.0] - 2019-08-15 ### Added - Added logger timestamps to non simplsharp programs diff --git a/ICD.Common.Utils/ConsoleColor.cs b/ICD.Common.Utils/ConsoleColor.cs index 7035e50..c88c8bb 100644 --- a/ICD.Common.Utils/ConsoleColor.cs +++ b/ICD.Common.Utils/ConsoleColor.cs @@ -28,6 +28,9 @@ namespace ICD.Common.Utils public static string FormatAnsi(this eConsoleColor extends, string data) { + // % needs to be escaped or weird things happen + data = string.IsNullOrEmpty(data) ? data : data.Replace("%", "%%"); + return string.Format("{0}{1}{2}", extends.ToAnsiPrefix(), data, CONSOLE_RESET); } diff --git a/ICD.Common.Utils/IcdErrorLog.cs b/ICD.Common.Utils/IcdErrorLog.cs index b71df5a..26a90fd 100644 --- a/ICD.Common.Utils/IcdErrorLog.cs +++ b/ICD.Common.Utils/IcdErrorLog.cs @@ -26,7 +26,7 @@ namespace ICD.Common.Utils try { #if SIMPLSHARP - message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_RED); + message = eConsoleColor.Red.FormatAnsi(message); ErrorLog.Error(message); #else Console.Write("Error - {0} - ", IcdEnvironment.GetLocalTime()); @@ -55,7 +55,7 @@ namespace ICD.Common.Utils try { #if SIMPLSHARP - message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_YELLOW); + message = eConsoleColor.Yellow.FormatAnsi(message); ErrorLog.Warn(message); #else Console.Write("Warn - {0} - ", IcdEnvironment.GetLocalTime()); @@ -84,7 +84,7 @@ namespace ICD.Common.Utils try { #if SIMPLSHARP - message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_BLUE); + message = eConsoleColor.Blue.FormatAnsi(message); ErrorLog.Notice(message); #else Console.Write("Notice - {0} - ", IcdEnvironment.GetLocalTime()); @@ -113,7 +113,7 @@ namespace ICD.Common.Utils try { #if SIMPLSHARP - message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_GREEN); + message = eConsoleColor.Green.FormatAnsi(message); ErrorLog.Ok(message); #else Console.Write("OK - {0} - ", IcdEnvironment.GetLocalTime()); @@ -142,7 +142,7 @@ namespace ICD.Common.Utils try { #if SIMPLSHARP - message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_YELLOW_ON_RED_BACKGROUND); + message = eConsoleColor.YellowOnRed.FormatAnsi(message); ErrorLog.Exception(message, ex); #else Console.Write("Except - {0} - ", IcdEnvironment.GetLocalTime()); @@ -174,7 +174,7 @@ namespace ICD.Common.Utils try { #if SIMPLSHARP - message = FormatConsoleColor(message, ConsoleColorExtensions.CONSOLE_CYAN); + message = eConsoleColor.Cyan.FormatAnsi(message); ErrorLog.Info(message); #else Console.Write("Info - {0} - ", IcdEnvironment.GetLocalTime()); @@ -194,16 +194,5 @@ namespace ICD.Common.Utils { Info(string.Format(message, args)); } - - /// - /// Formats the text with the given console color. - /// - /// - /// - /// - private static string FormatConsoleColor(string text, string color) - { - return string.Format("{0}{1}{2}", color, text, ConsoleColorExtensions.CONSOLE_RESET); - } } }