blob: a6b4c6549ca499ab770aaa7d05147fde0e915524 [file] [log] [blame]
Adrian Prantl0c36a752015-01-06 16:50:25 +00001//===-- SyntaxHighlighting.cpp ----------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "SyntaxHighlighting.h"
11#include "llvm/Support/CommandLine.h"
12using namespace llvm;
13using namespace dwarf;
14using namespace syntax;
15
16static cl::opt<cl::boolOrDefault>
17 UseColor("color",
18 cl::desc("use colored syntax highlighting (default=autodetect)"),
19 cl::init(cl::BOU_UNSET));
20
21WithColor::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) {
24 switch (Type) {
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;
30 }
31 }
32}
33
34WithColor::~WithColor() {
35 if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE)
36 OS.resetColor();
37}