1 //===- WithColor.h ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_SUPPORT_WITHCOLOR_H
11 #define LLVM_SUPPORT_WITHCOLOR_H
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/CommandLine.h"
18 extern cl::OptionCategory ColorCategory;
22 // Symbolic names for various syntax elements.
23 enum class HighlightColor {
35 /// An RAII object that temporarily switches an output stream to a specific
39 /// Determine whether colors should be displayed.
40 bool colorsEnabled(raw_ostream &OS);
43 /// To be used like this: WithColor(OS, HighlightColor::String) << "text";
44 WithColor(raw_ostream &OS, HighlightColor S);
47 raw_ostream &get() { return OS; }
48 operator raw_ostream &() { return OS; }
50 /// Convenience method for printing "error: " to stderr.
51 static raw_ostream &error();
52 /// Convenience method for printing "warning: " to stderr.
53 static raw_ostream &warning();
54 /// Convenience method for printing "note: " to stderr.
55 static raw_ostream ¬e();
57 /// Convenience method for printing "error: " to the given stream.
58 static raw_ostream &error(raw_ostream &OS, StringRef Prefix = "");
59 /// Convenience method for printing "warning: " to the given stream.
60 static raw_ostream &warning(raw_ostream &OS, StringRef Prefix = "");
61 /// Convenience method for printing "note: " to the given stream.
62 static raw_ostream ¬e(raw_ostream &OS, StringRef Prefix = "");
65 } // end namespace llvm
67 #endif // LLVM_LIB_DEBUGINFO_WITHCOLOR_H