From 7457578257cfb1eb2940b26818798a017efc1921 Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Fri, 24 Jun 2016 10:35:17 -0700 Subject: [PATCH] Use standard ansi color codes --- .../Internal/AnsiLogConsole.cs | 38 +++++++++---------- .../AnsiLogConsoleTest.cs | 14 +++---- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/Microsoft.Extensions.Logging.Console/Internal/AnsiLogConsole.cs b/src/Microsoft.Extensions.Logging.Console/Internal/AnsiLogConsole.cs index dfc04b2d..1a827296 100644 --- a/src/Microsoft.Extensions.Logging.Console/Internal/AnsiLogConsole.cs +++ b/src/Microsoft.Extensions.Logging.Console/Internal/AnsiLogConsole.cs @@ -37,12 +37,12 @@ public void Write(string message, ConsoleColor? background, ConsoleColor? foregr if (foreground.HasValue) { - _outputBuilder.Append("\x1B[39m"); // reset to default foreground color + _outputBuilder.Append("\x1B[39m\x1B[22m"); // reset to default foreground color } if (background.HasValue) { - _outputBuilder.Append("\x1B[0m"); // reset to the background color + _outputBuilder.Append("\x1B[49m"); // reset to the background color } } @@ -79,21 +79,21 @@ private static string GetForegroundColorEscapeCode(ConsoleColor color) case ConsoleColor.Gray: return "\x1B[37m"; case ConsoleColor.Red: - return "\x1B[91m"; + return "\x1B[1m\x1B[31m"; case ConsoleColor.Green: - return "\x1B[92m"; + return "\x1B[1m\x1B[32m"; case ConsoleColor.Yellow: - return "\x1B[93m"; + return "\x1B[1m\x1B[33m"; case ConsoleColor.Blue: - return "\x1B[94m"; + return "\x1B[1m\x1B[34m"; case ConsoleColor.Magenta: - return "\x1B[95m"; + return "\x1B[1m\x1B[35m"; case ConsoleColor.Cyan: - return "\x1B[96m"; + return "\x1B[1m\x1B[36m"; case ConsoleColor.White: - return "\x1B[97m"; + return "\x1B[1m\x1B[37m"; default: - return "\x1B[39m"; // default foreground color + return "\x1B[39m\x1B[22m"; // default foreground color } } @@ -102,23 +102,23 @@ private static string GetBackgroundColorEscapeCode(ConsoleColor color) switch (color) { case ConsoleColor.Black: - return "\x1B[100m"; + return "\x1B[40m"; case ConsoleColor.Red: - return "\x1B[101m"; + return "\x1B[41m"; case ConsoleColor.Green: - return "\x1B[102m"; + return "\x1B[42m"; case ConsoleColor.Yellow: - return "\x1B[103m"; + return "\x1B[43m"; case ConsoleColor.Blue: - return "\x1B[104m"; + return "\x1B[44m"; case ConsoleColor.Magenta: - return "\x1B[105m"; + return "\x1B[45m"; case ConsoleColor.Cyan: - return "\x1B[106m"; + return "\x1B[46m"; case ConsoleColor.White: - return "\x1B[107m"; + return "\x1B[47m"; default: - return "\x1B[0m"; // Use default background color + return "\x1B[49m"; // Use default background color } } } diff --git a/test/Microsoft.Extensions.Logging.Test/AnsiLogConsoleTest.cs b/test/Microsoft.Extensions.Logging.Test/AnsiLogConsoleTest.cs index 1c852241..ae355918 100644 --- a/test/Microsoft.Extensions.Logging.Test/AnsiLogConsoleTest.cs +++ b/test/Microsoft.Extensions.Logging.Test/AnsiLogConsoleTest.cs @@ -87,7 +87,7 @@ public void WritesMessage_WithForegroundEscapeCode_AndNoBackgroundColorSpecified var message = "Request received"; var expectedMessage = GetForegroundColorEscapeCode(ConsoleColor.DarkGreen) + message - + "\x1B[39m"; //resets foreground color + + "\x1B[39m\x1B[22m"; //resets foreground color // Act console.WriteLine(message, background: null, foreground: ConsoleColor.DarkGreen); @@ -106,7 +106,7 @@ public void WritesMessage_WithBackgroundEscapeCode_AndNoForegroundColorSpecified var message = "Request received"; var expectedMessage = GetBackgroundColorEscapeCode(ConsoleColor.Red) + message - + "\x1B[0m"; //resets background color + + "\x1B[49m"; //resets background color // Act console.WriteLine(message, background: ConsoleColor.Red, foreground: null); @@ -126,8 +126,8 @@ public void WriteMessage_InOrder_WhenBothForegroundOrBackgroundColorsSpecified() var expectedMessage = GetBackgroundColorEscapeCode(ConsoleColor.Red) + GetForegroundColorEscapeCode(ConsoleColor.DarkGreen) + "Request received" - + "\x1B[39m" //resets foreground color - + "\x1B[0m" //resets background color + + "\x1B[39m\x1B[22m" //resets foreground color + + "\x1B[49m" //resets background color + Environment.NewLine; // Act @@ -166,10 +166,8 @@ private static string GetForegroundColorEscapeCode(ConsoleColor color) return "\x1B[33m"; case ConsoleColor.Gray: return "\x1B[37m"; - case ConsoleColor.White: - return "\x1B[97m"; default: - return "\x1B[37m"; + return "\x1B[39m"; } } @@ -178,7 +176,7 @@ private static string GetBackgroundColorEscapeCode(ConsoleColor color) switch (color) { case ConsoleColor.Red: - return "\x1B[101m"; + return "\x1B[41m"; default: return "\x1B[49m"; }