fix: Fixed a bug where ANSI color encoded strings with percentages were being scrambled

This commit is contained in:
Chris Cameron
2019-08-20 15:34:40 -04:00
parent 3f1f9611ec
commit f8c88630fc
3 changed files with 12 additions and 17 deletions

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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));
}
/// <summary>
/// Formats the text with the given console color.
/// </summary>
/// <param name="text"></param>
/// <param name="color"></param>
/// <returns></returns>
private static string FormatConsoleColor(string text, string color)
{
return string.Format("{0}{1}{2}", color, text, ConsoleColorExtensions.CONSOLE_RESET);
}
}
}