+ this.colorSet = colorSet;
+ this.colorReset = colorReset;
+
+ events = new List<BuildStatusEventArgs> ();
+ errorsTable = new Dictionary<string, List<string>> ();
+ warningsTable = new Dictionary<string, List<string>> ();
+
+ //defaults
+ errorColor = ConsoleColor.DarkRed;
+ warningColor = ConsoleColor.DarkYellow;
+ eventColor = ConsoleColor.DarkCyan;
+ messageColor = ConsoleColor.DarkGray;
+ highMessageColor = ConsoleColor.White;
+
+ // if message color is not set via the env var,
+ // then don't use any color for it.
+ no_message_color = true;
+
+ use_colors = false;
+ if (colorSet == null || colorReset == null)
+ return;
+
+ // color support
+ string config = Environment.GetEnvironmentVariable ("XBUILD_COLORS");
+ if (config == null) {
+ use_colors = true;
+ return;
+ }
+
+ if (config == "disable")
+ return;
+
+ use_colors = true;
+ string [] pairs = config.Split (new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
+ foreach (string pair in pairs) {
+ string [] parts = pair.Split (new char[] {'='}, StringSplitOptions.RemoveEmptyEntries);
+ if (parts.Length != 2)
+ continue;
+
+ if (parts [0] == "errors")
+ TryParseConsoleColor (parts [1], ref errorColor);
+ else if (parts [0] == "warnings")
+ TryParseConsoleColor (parts [1], ref warningColor);
+ else if (parts [0] == "events")
+ TryParseConsoleColor (parts [1], ref eventColor);
+ else if (parts [0] == "messages") {
+ if (TryParseConsoleColor (parts [1], ref messageColor)) {
+ highMessageColor = GetBrightColorFor (messageColor);
+ no_message_color = false;
+ }
+ }
+ }
+ }
+
+ bool TryParseConsoleColor (string color_str, ref ConsoleColor color)
+ {
+ switch (color_str.ToLower ()) {
+ case "black": color = ConsoleColor.Black; break;
+
+ case "blue": color = ConsoleColor.DarkBlue; break;
+ case "green": color = ConsoleColor.DarkGreen; break;
+ case "cyan": color = ConsoleColor.DarkCyan; break;
+ case "red": color = ConsoleColor.DarkRed; break;
+ case "magenta": color = ConsoleColor.DarkMagenta; break;
+ case "yellow": color = ConsoleColor.DarkYellow; break;
+ case "grey": color = ConsoleColor.DarkGray; break;
+
+ case "brightgrey": color = ConsoleColor.Gray; break;
+ case "brightblue": color = ConsoleColor.Blue; break;
+ case "brightgreen": color = ConsoleColor.Green; break;
+ case "brightcyan": color = ConsoleColor.Cyan; break;
+ case "brightred": color = ConsoleColor.Red; break;
+ case "brightmagenta": color = ConsoleColor.Magenta; break;
+ case "brightyellow": color = ConsoleColor.Yellow; break;
+
+ case "white":
+ case "brightwhite": color = ConsoleColor.White; break;
+ default: return false;
+ }
+
+ return true;
+ }
+
+ ConsoleColor GetBrightColorFor (ConsoleColor color)
+ {
+ switch (color) {
+ case ConsoleColor.DarkBlue: return ConsoleColor.Blue;
+ case ConsoleColor.DarkGreen: return ConsoleColor.Green;
+ case ConsoleColor.DarkCyan: return ConsoleColor.Cyan;
+ case ConsoleColor.DarkRed: return ConsoleColor.Red;
+ case ConsoleColor.DarkMagenta: return ConsoleColor.Magenta;
+ case ConsoleColor.DarkYellow: return ConsoleColor.Yellow;
+ case ConsoleColor.DarkGray: return ConsoleColor.Gray;
+ case ConsoleColor.Gray: return ConsoleColor.White;
+
+ default: return color;
+ }