2008-01-08 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / report.cs
index 8bf9b1f7d3168f5991b405430b457ca70b63568d..478f0bea9e352382cbb4b1f6ac53f2975a9e990b 100644 (file)
@@ -118,6 +118,7 @@ namespace Mono.CSharp {
                        warning_ignore_table = null;
                        warning_regions_table = null;
                        reporting_disabled = false;
+                       error_stack = warning_stack = null;
                }
 
                public static void DisableReporting ()
@@ -465,6 +466,18 @@ namespace Mono.CSharp {
                sealed class ErrorMessage : AbstractMessage
                {
                        static string prefix, postfix;
+
+                       [System.Runtime.InteropServices.DllImport ("libc", EntryPoint="isatty")]
+                       extern static int _isatty (int fd);
+                       
+                       static bool isatty (int fd)
+                       {
+                               try {
+                                       return _isatty (fd) == 1;
+                               } catch {
+                                       return false;
+                               }
+                       }
                        
                        static ErrorMessage ()
                        {
@@ -484,6 +497,12 @@ namespace Mono.CSharp {
                                        xterm_colors = true;
                                        break;
                                }
+                               if (!xterm_colors)
+                                       return;
+
+                               if (!(isatty (1) && isatty (2)))
+                                       return;
+                               
                                string config = Environment.GetEnvironmentVariable ("MCS_COLORS");
                                if (config == null){
                                        config = "errors=red";
@@ -498,9 +517,6 @@ namespace Mono.CSharp {
 
                                config = config.Substring (7);
                                
-                               if (!xterm_colors)
-                                       return;
-
                                int p = config.IndexOf (",");
                                if (p == -1)
                                        prefix = GetForeground (config);