コード例 #1
0
 public static void WriteColoredMessage(this TextWriter textWriter, string message, ConsoleColor?background, ConsoleColor?foreground)
 {
     // Order: backgroundcolor, foregroundcolor, Message, reset foregroundcolor, reset backgroundcolor
     if (background.HasValue)
     {
         textWriter.Write(AnsiParser.GetBackgroundColorEscapeCode(background.Value));
     }
     if (foreground.HasValue)
     {
         textWriter.Write(AnsiParser.GetForegroundColorEscapeCode(foreground.Value));
     }
     textWriter.Write(message);
     if (foreground.HasValue)
     {
         textWriter.Write(AnsiParser.DefaultForegroundColor); // reset to default foreground color
     }
     if (background.HasValue)
     {
         textWriter.Write(AnsiParser.DefaultBackgroundColor); // reset to the background color
     }
 }
コード例 #2
0
 public AnsiParsingLogConsole(bool stdErr = false)
 {
     _textWriter = stdErr ? System.Console.Error : System.Console.Out;
     _parser     = new AnsiParser(WriteToConsole);
 }