blob: d4f44e446954f8f1289b24fec3f8d7007882d243 [file] [log] [blame]
Eugene Zelenko28db7e62017-03-01 01:14:23 +00001//===- SyntaxHighlighting.cpp ---------------------------------------------===//
Adrian Prantl0c36a752015-01-06 16:50:25 +00002//
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"
Eugene Zelenko28db7e62017-03-01 01:14:23 +000012#include "llvm/Support/raw_ostream.h"
13
Adrian Prantl0c36a752015-01-06 16:50:25 +000014using namespace llvm;
15using namespace dwarf;
16using namespace syntax;
17
18static cl::opt<cl::boolOrDefault>
19 UseColor("color",
20 cl::desc("use colored syntax highlighting (default=autodetect)"),
21 cl::init(cl::BOU_UNSET));
22
Eugene Zelenko28db7e62017-03-01 01:14:23 +000023WithColor::WithColor(raw_ostream &OS, enum HighlightColor Type) : OS(OS) {
Adrian Prantl0c36a752015-01-06 16:50:25 +000024 // Detect color from terminal type unless the user passed the --color option.
25 if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE) {
26 switch (Type) {
Eugene Zelenko28db7e62017-03-01 01:14:23 +000027 case Address: OS.changeColor(raw_ostream::YELLOW); break;
28 case String: OS.changeColor(raw_ostream::GREEN); break;
29 case Tag: OS.changeColor(raw_ostream::BLUE); break;
30 case Attribute: OS.changeColor(raw_ostream::CYAN); break;
31 case Enumerator: OS.changeColor(raw_ostream::MAGENTA); break;
32 case Macro: OS.changeColor(raw_ostream::RED); break;
Adrian Prantl0c36a752015-01-06 16:50:25 +000033 }
34 }
35}
36
37WithColor::~WithColor() {
38 if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE)
39 OS.resetColor();
40}