]>
Commit | Line | Data |
---|---|---|
e9772e16 KS |
1 | //===-- sanitizer_report_decorator.h ----------------------------*- C++ -*-===// |
2 | // | |
b667dd70 ML |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. | |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |
e9772e16 KS |
6 | // |
7 | //===----------------------------------------------------------------------===// | |
8 | // | |
9 | // Tags to decorate the sanitizer reports. | |
10 | // Currently supported tags: | |
11 | // * None. | |
12 | // * ANSI color sequences. | |
13 | // | |
14 | //===----------------------------------------------------------------------===// | |
15 | ||
de5a5fa1 MP |
16 | #ifndef SANITIZER_REPORT_DECORATOR_H |
17 | #define SANITIZER_REPORT_DECORATOR_H | |
e9772e16 | 18 | |
dee5ea7a KS |
19 | #include "sanitizer_common.h" |
20 | ||
e9772e16 | 21 | namespace __sanitizer { |
866e32ad | 22 | class SanitizerCommonDecorator { |
ef1b3fda KS |
23 | // FIXME: This is not portable. It assumes the special strings are printed to |
24 | // stdout, which is not the case on Windows (see SetConsoleTextAttribute()). | |
e9772e16 | 25 | public: |
866e32ad | 26 | SanitizerCommonDecorator() : ansi_(ColorizeReports()) {} |
eac97531 | 27 | const char *Bold() const { return ansi_ ? "\033[1m" : ""; } |
866e32ad | 28 | const char *Default() const { return ansi_ ? "\033[1m\033[0m" : ""; } |
5d3805fc | 29 | const char *Warning() const { return Red(); } |
eac97531 ML |
30 | const char *Error() const { return Red(); } |
31 | const char *MemoryByte() const { return Magenta(); } | |
5d3805fc | 32 | |
866e32ad | 33 | protected: |
de5a5fa1 MP |
34 | const char *Black() const { return ansi_ ? "\033[1m\033[30m" : ""; } |
35 | const char *Red() const { return ansi_ ? "\033[1m\033[31m" : ""; } | |
36 | const char *Green() const { return ansi_ ? "\033[1m\033[32m" : ""; } | |
37 | const char *Yellow() const { return ansi_ ? "\033[1m\033[33m" : ""; } | |
38 | const char *Blue() const { return ansi_ ? "\033[1m\033[34m" : ""; } | |
39 | const char *Magenta() const { return ansi_ ? "\033[1m\033[35m" : ""; } | |
40 | const char *Cyan() const { return ansi_ ? "\033[1m\033[36m" : ""; } | |
41 | const char *White() const { return ansi_ ? "\033[1m\033[37m" : ""; } | |
e9772e16 KS |
42 | private: |
43 | bool ansi_; | |
44 | }; | |
dee5ea7a | 45 | |
e9772e16 | 46 | } // namespace __sanitizer |
de5a5fa1 MP |
47 | |
48 | #endif // SANITIZER_REPORT_DECORATOR_H |