1 //===-- SyntaxHighlighting.cpp ----------------------------------*- 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 #include "SyntaxHighlighting.h"
11 #include "llvm/Support/CommandLine.h"
13 using namespace dwarf;
14 using namespace syntax;
16 static cl::opt<cl::boolOrDefault>
18 cl::desc("use colored syntax highlighting (default=autodetect)"),
19 cl::init(cl::BOU_UNSET));
21 WithColor::WithColor(llvm::raw_ostream &OS, enum HighlightColor Type) : OS(OS) {
22 // Detect color from terminal type unless the user passed the --color option.
23 if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE) {
25 case Address: OS.changeColor(llvm::raw_ostream::YELLOW); break;
26 case String: OS.changeColor(llvm::raw_ostream::GREEN); break;
27 case Tag: OS.changeColor(llvm::raw_ostream::BLUE); break;
28 case Attribute: OS.changeColor(llvm::raw_ostream::CYAN); break;
29 case Enumerator: OS.changeColor(llvm::raw_ostream::MAGENTA); break;
34 WithColor::~WithColor() {
35 if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE)