private static void SetOutputColour(OutputColour style) { if (NoColours) { return; } if (style == PreviousColour) { return; } PreviousColour = style; if (Utilities.MultiArchPInvoke.RunningPlatform == Utilities.Platform.Windows && !Utilities.MultiArchPInvoke.IsBashOnWindows) { switch (style) { case OutputColour.SystemDefault: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = DefaultColour; break; case OutputColour.Black: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Black; break; case OutputColour.DarkBlue: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkBlue; break; case OutputColour.DarkCyan: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkCyan; break; case OutputColour.DarkGray: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkGray; break; case OutputColour.DarkGreen: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkGreen; break; case OutputColour.DarkMagenta: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkMagenta; break; case OutputColour.DarkRed: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkRed; break; case OutputColour.DarkYellow: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkYellow; break; case OutputColour.Blue: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Blue; break; case OutputColour.Cyan: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Cyan; break; case OutputColour.Gray: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Gray; break; case OutputColour.Green: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Green; break; case OutputColour.Magenta: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Magenta; break; case OutputColour.Red: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Red; break; case OutputColour.White: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.White; break; case OutputColour.Yellow: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Yellow; break; case OutputColour.ErrorHeader: System.Console.BackgroundColor = ConsoleColor.Red; System.Console.ForegroundColor = ConsoleColor.White; break; case OutputColour.WarningHeader: System.Console.BackgroundColor = ConsoleColor.Yellow; System.Console.ForegroundColor = ConsoleColor.Black; break; case OutputColour.Invert: System.Console.BackgroundColor = ConsoleColor.White; System.Console.ForegroundColor = ConsoleColor.Black; break; default: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = DefaultColour; break; } } else { System.Console.Write("\x1b[0m"); switch (style) { default: case OutputColour.SystemDefault: System.Console.Write("\x1b[0m"); break; case OutputColour.Black: System.Console.Write("\x1b[30m"); break; case OutputColour.DarkBlue: System.Console.Write("\x1b[34m"); break; case OutputColour.DarkCyan: System.Console.Write("\x1b[36m"); break; case OutputColour.DarkGray: System.Console.Write("\x1b[90m"); break; case OutputColour.DarkGreen: System.Console.Write("\x1b[32m"); break; case OutputColour.DarkMagenta: System.Console.Write("\x1b[35m"); break; case OutputColour.DarkRed: System.Console.Write("\x1b[31m"); break; case OutputColour.DarkYellow: System.Console.Write("\x1b[33m"); break; case OutputColour.Blue: System.Console.Write("\x1b[94m"); break; case OutputColour.Cyan: System.Console.Write("\x1b[96m"); break; case OutputColour.Gray: System.Console.Write("\x1b[37m"); break; case OutputColour.Green: System.Console.Write("\x1b[92m"); break; case OutputColour.Magenta: System.Console.Write("\x1b[95m"); break; case OutputColour.Red: System.Console.Write("\x1b[91m"); break; case OutputColour.Yellow: System.Console.Write("\x1b[93m"); break; case OutputColour.White: System.Console.Write("\x1b[97m"); break; case OutputColour.ErrorHeader: System.Console.Write("\x1b[101;97m"); break; case OutputColour.WarningHeader: System.Console.Write("\x1b[30;103m"); break; case OutputColour.Invert: System.Console.Write("\x1b[7m"); break; } } }
private static void SetOutputColour(OutputColour style) { if (NoColours) return; if (style == PreviousColour) return; PreviousColour = style; if (Utilities.MultiArchPInvoke.RunningPlatform == Utilities.Platform.Windows) { switch (style) { case OutputColour.SystemDefault: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = DefaultColour; break; case OutputColour.Blue: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Blue; break; case OutputColour.Cyan: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Cyan; break; case OutputColour.DarkBlue: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkBlue; break; case OutputColour.DarkCyan: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkCyan; break; case OutputColour.DarkGray: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkGray; break; case OutputColour.DarkGreen: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkGreen; break; case OutputColour.DarkMagenta: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkMagenta; break; case OutputColour.DarkRed: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkRed; break; case OutputColour.DarkYellow: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.DarkYellow; break; case OutputColour.Gray: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Gray; break; case OutputColour.Green: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Green; break; case OutputColour.Magenta: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Magenta; break; case OutputColour.Red: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Red; break; case OutputColour.White: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.White; break; case OutputColour.Yellow: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = ConsoleColor.Yellow; break; case OutputColour.ErrorHeader: System.Console.BackgroundColor = ConsoleColor.Red; System.Console.ForegroundColor = ConsoleColor.White; break; case OutputColour.WarningHeader: System.Console.BackgroundColor = ConsoleColor.Yellow; System.Console.ForegroundColor = ConsoleColor.Black; break; case OutputColour.Invert: System.Console.BackgroundColor = ConsoleColor.White; System.Console.ForegroundColor = ConsoleColor.Black; break; default: System.Console.BackgroundColor = DefaultBGColour; System.Console.ForegroundColor = DefaultColour; break; } } else { System.Console.Write("\x1b[0m"); switch (style) { case OutputColour.Normal: break; case OutputColour.Success: System.Console.Write("\x1b[92m"); break; case OutputColour.Blue: System.Console.Write("\x1b[96m"); break; case OutputColour.Emphasis: System.Console.Write("\x1b[1m"); break; case OutputColour.Warning: System.Console.Write("\x1b[93m"); break; case OutputColour.Error: System.Console.Write("\x1b[91m"); break; case OutputColour.ErrorHeader: System.Console.Write("\x1b[101;97m"); break; case OutputColour.WarningHeader: System.Console.Write("\x1b[30;103m"); break; case OutputColour.Trace: System.Console.Write("\x1b[37m"); break; case OutputColour.Invert: System.Console.Write("\x1b[7m"); break; default: System.Console.Write("\x1b[0m"); break; } } }
private static void FormatOutput(string v, bool bypassLog) { List <Tuple <OutputColour, string> > outputs = new List <Tuple <OutputColour, string> >(); OutputColour currentColour = OutputColour.Normal; int pos = 0; while (pos < v.Length) { int nextLineBreak = v.IndexOf('\n', pos); int nextFindLocation = v.IndexOf('#', pos); if (nextLineBreak >= 0 && (nextFindLocation == -1 || nextLineBreak < nextFindLocation)) { outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(pos, nextLineBreak + 1 - pos))); pos = nextLineBreak + 1; } else if (nextFindLocation >= 0) { // escaping a hash sign if (nextFindLocation > 0 && v[nextFindLocation - 1] == '\\') { int len = nextFindLocation - 1 - pos; if (len > 0) { outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(pos, len))); } outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(nextFindLocation, 1))); pos = nextFindLocation + 1; continue; } int end = v.IndexOf('#', nextFindLocation + 1); if (end <= nextFindLocation + 2 && end != -1) { // valid formatting tag outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(pos, nextFindLocation - pos))); if (end == nextFindLocation + 1) { currentColour = OutputColour.Normal; pos = end + 1; } else { if (!OutputStyles.TryGetValue(v[nextFindLocation + 1], out currentColour)) { SetOutputColour(OutputColour.Warning); if (EnableDiagnostics) { System.Console.WriteLine("Unrecognized formatting tag: '{0}'!", v[nextFindLocation + 1]); } currentColour = OutputColour.Normal; if (nextFindLocation > pos) { pos = nextFindLocation; outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(pos, 1))); } else { pos = pos + 1; } } else { pos = end + 1; } } } else { outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(pos, nextFindLocation - pos))); pos = nextFindLocation + 1; } } else if (nextLineBreak == -1) { outputs.Add(new Tuple <OutputColour, string>(currentColour, v.Substring(pos, v.Length - pos))); pos = v.Length; } } bool newline = true; foreach (var x in outputs) { if (newline) { FlushOutput(true, x, bypassLog); newline = false; } else { FlushOutput(false, x, bypassLog); } if (x.Item2.EndsWith("\n")) { newline = true; } } SetOutputColour(OutputColour.Normal); }