Add ANSI color support for clang.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72855 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 0e0a072..9e6afdd 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -328,6 +328,11 @@
 			     "within N columns or fewer, when possible."),
 	      llvm::cl::value_desc("N"));
 
+static llvm::cl::opt<bool>
+NoColorDiagnostic("fno-color-diagnostic",
+	      llvm::cl::desc("Don't use colors when showing diagnostics "
+                             "(automatically turned off if output is not a "
+                             "terminal)."));
 //===----------------------------------------------------------------------===//
 // C++ Visualization.
 //===----------------------------------------------------------------------===//
@@ -2150,6 +2155,10 @@
     if (MessageLength.getNumOccurrences() == 0)
       MessageLength.setValue(llvm::sys::Process::StandardErrColumns());
 
+    if (!NoColorDiagnostic) {
+      NoColorDiagnostic.setValue(!llvm::sys::Process::StandardErrHasColors());
+    }
+
     DiagClient.reset(new TextDiagnosticPrinter(llvm::errs(),
                                                !NoShowColumn,
                                                !NoCaretDiagnostics,
@@ -2157,7 +2166,8 @@
                                                PrintSourceRangeInfo,
                                                PrintDiagnosticOption,
                                                !NoDiagnosticsFixIt,
-                                               MessageLength));
+                                               MessageLength,
+                                               !NoColorDiagnostic));
   } else {
     DiagClient.reset(CreateHTMLDiagnosticClient(HTMLDiag));
   }