1 //===-- sanitizer_report_decorator.h ----------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Tags to decorate the sanitizer reports.
10 // Currently supported tags:
11 //   * None.
12 //   * ANSI color sequences.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef SANITIZER_REPORT_DECORATOR_H
17 #define SANITIZER_REPORT_DECORATOR_H
18 
19 #include "sanitizer_common.h"
20 
21 namespace __sanitizer {
22 class SanitizerCommonDecorator {
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()).
25  public:
SanitizerCommonDecorator()26   SanitizerCommonDecorator() : ansi_(ColorizeReports()) {}
Bold()27   const char *Bold() const { return ansi_ ? "\033[1m" : ""; }
Default()28   const char *Default() const { return ansi_ ? "\033[1m\033[0m"  : ""; }
Warning()29   const char *Warning() const { return Red(); }
Error()30   const char *Error() const { return Red(); }
MemoryByte()31   const char *MemoryByte() const { return Magenta(); }
32 
33  protected:
Black()34   const char *Black()   const { return ansi_ ? "\033[1m\033[30m" : ""; }
Red()35   const char *Red()     const { return ansi_ ? "\033[1m\033[31m" : ""; }
Green()36   const char *Green()   const { return ansi_ ? "\033[1m\033[32m" : ""; }
Yellow()37   const char *Yellow()  const { return ansi_ ? "\033[1m\033[33m" : ""; }
Blue()38   const char *Blue()    const { return ansi_ ? "\033[1m\033[34m" : ""; }
Magenta()39   const char *Magenta() const { return ansi_ ? "\033[1m\033[35m" : ""; }
Cyan()40   const char *Cyan()    const { return ansi_ ? "\033[1m\033[36m" : ""; }
White()41   const char *White()   const { return ansi_ ? "\033[1m\033[37m" : ""; }
42  private:
43   bool ansi_;
44 };
45 
46 }  // namespace __sanitizer
47 
48 #endif  // SANITIZER_REPORT_DECORATOR_H
49