Adrian Prantl | 0c36a75 | 2015-01-06 16:50:25 +0000 | [diff] [blame^] | 1 | //===-- 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" |
| 12 | using namespace llvm; |
| 13 | using namespace dwarf; |
| 14 | using namespace syntax; |
| 15 | |
| 16 | static cl::opt<cl::boolOrDefault> |
| 17 | UseColor("color", |
| 18 | cl::desc("use colored syntax highlighting (default=autodetect)"), |
| 19 | cl::init(cl::BOU_UNSET)); |
| 20 | |
| 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) { |
| 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 | |
| 34 | WithColor::~WithColor() { |
| 35 | if (UseColor == cl::BOU_UNSET ? OS.has_colors() : UseColor == cl::BOU_TRUE) |
| 36 | OS.resetColor(); |
| 37 | } |